{ "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 }