From 85b85fbbe6e0de803e25768bf2332bae8f26bd69 Mon Sep 17 00:00:00 2001 From: Antonina Bagrin Date: Mon, 4 Aug 2025 19:36:44 +0300 Subject: [PATCH] Added my contribution day_2 to community-contributions --- .../community-contributions/day2_tennis.ipynb | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 week1/community-contributions/day2_tennis.ipynb diff --git a/week1/community-contributions/day2_tennis.ipynb b/week1/community-contributions/day2_tennis.ipynb new file mode 100644 index 0000000..64a3502 --- /dev/null +++ b/week1/community-contributions/day2_tennis.ipynb @@ -0,0 +1,87 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "245fe5e2-9a3d-42f6-a39a-2a0f8750dd89", + "metadata": {}, + "outputs": [], + "source": [ + "OLLAMA_API = \"http://localhost:11434/api/chat\"\n", + "HEADERS = {\"Content-Type\": \"application/json\"}\n", + "MODEL = \"llama3.2\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4b598b5-2b8f-4004-88de-1fa03050a11f", + "metadata": {}, + "outputs": [], + "source": [ + "messages = [\n", + " {\"role\": \"user\", \"content\": \"Write a short summary of advice for a child who is just starting to get interested in tennis.\"}\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9e0ffcc6-1489-41d9-9cd3-6656101bff2e", + "metadata": {}, + "outputs": [], + "source": [ + "payload = {\n", + " \"model\": MODEL,\n", + " \"messages\": messages,\n", + " \"stream\": False\n", + " }" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "33290d04-b7f2-4f36-956b-170685faa78c", + "metadata": {}, + "outputs": [], + "source": [ + "response = requests.post(OLLAMA_API, json=payload, headers=HEADERS)\n", + "print(response.json()['message']['content'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0dfabb0-dd31-4508-8f72-34482e2bef4a", + "metadata": {}, + "outputs": [], + "source": [ + "import ollama\n", + "\n", + "response = ollama.chat(model=MODEL, messages=messages)\n", + "print(response['message']['content'])\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}