{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "ename": "KeyError", "evalue": "'API_KEY'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[4], line 5\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmistralai\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodels\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mchat_completion\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ChatMessage\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m\n\u001b[0;32m----> 5\u001b[0m api_key \u001b[38;5;241m=\u001b[39m \u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menviron\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mAPI_KEY\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;66;03m# model = \"mistral-tiny\"\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \n\u001b[1;32m 8\u001b[0m \u001b[38;5;66;03m# client = MistralClient(api_key=api_key)\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 19\u001b[0m \n\u001b[1;32m 20\u001b[0m \u001b[38;5;66;03m# print(chat_response.choices[0].message.content)\u001b[39;00m\n", "File \u001b[0;32m:679\u001b[0m, in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n", "\u001b[0;31mKeyError\u001b[0m: 'API_KEY'" ] } ], "source": [ "from mistralai.client import MistralClient\n", "from mistralai.models.chat_completion import ChatMessage\n", "import os\n", "\n", "api_key = os.environ['API_KEY']\n", "# model = \"mistral-tiny\"\n", "\n", "# client = MistralClient(api_key=api_key)\n", "\n", "# messages = [\n", "# ChatMessage(role=\"user\", content=\"What is the best French cheese?\")\n", "# ]\n", "\n", "# # No streaming\n", "# chat_response = client.chat(\n", "# model=model,\n", "# messages=messages,\n", "# )\n", "\n", "# print(chat_response.choices[0].message.content)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.5" } }, "nbformat": 4, "nbformat_minor": 2 }