Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Mistral Python SDK v1.0.1 #10

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cookbooks/python/openai/data/hotel_invoices/transformed_invoice_json/*
cookbooks/python/openai/data/hotel_invoices/extracted_invoice_json/*
cookbooks/python/openai/data/hotel_invoices/hotel_DB.db
cookbooks/python/openai/hallucination_results.csv
node_modules
29 changes: 13 additions & 16 deletions cookbooks/python/mistralai/evaluation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@
"metadata": {},
"outputs": [],
"source": [
"from mistralai.client import MistralClient\n",
"from mistralai.models.chat_completion import ChatMessage\n",
"from mistralai import Mistral\n",
"\n",
"\n",
"def run_mistral(user_message, model=\"mistral-small\"):\n",
" client = MistralClient(api_key=github_token, endpoint=endpoint)\n",
" messages = [ChatMessage(role=\"user\", content=user_message)]\n",
" chat_response = client.chat(\n",
" client = Mistral(api_key=github_token, server_url=endpoint)\n",
" messages = [{\"role\":\"user\", \"content\":user_message}]\n",
" chat_response = client.chat.complete(\n",
" model=model,\n",
" messages=messages,\n",
" response_format={\"type\": \"json_object\"},\n",
Expand Down Expand Up @@ -221,14 +220,13 @@
"outputs": [],
"source": [
"import os\n",
"from mistralai.client import MistralClient\n",
"from mistralai.models.chat_completion import ChatMessage\n",
"from mistralai import Mistral\n",
"\n",
"\n",
"def run_mistral(user_message, model=\"mistral-small\"):\n",
" client = MistralClient(api_key=github_token, endpoint=endpoint)\n",
" messages = [ChatMessage(role=\"user\", content=user_message)]\n",
" chat_response = client.chat(model=model, messages=messages)\n",
" client = Mistral(api_key=github_token, server_url=endpoint)\n",
" messages = [{\"role\":\"user\", \"content\":user_message}]\n",
" chat_response = client.chat.complete(model=model, messages=messages)\n",
" return chat_response.choices[0].message.content\n",
"\n",
"\n",
Expand Down Expand Up @@ -375,20 +373,19 @@
"outputs": [],
"source": [
"import os\n",
"from mistralai.client import MistralClient\n",
"from mistralai.models.chat_completion import ChatMessage\n",
"from mistralai import Mistral\n",
"\n",
"\n",
"def run_mistral(user_message, model=\"mistral-small\", is_json=False):\n",
" client = MistralClient(api_key=github_token, endpoint=endpoint)\n",
" messages = [ChatMessage(role=\"user\", content=user_message)]\n",
" client = Mistral(api_key=github_token, server_url=endpoint)\n",
" messages = [{\"role\":\"user\", \"content\":user_message}]\n",
"\n",
" if is_json:\n",
" chat_response = client.chat(\n",
" chat_response = client.chat.complete(\n",
" model=model, messages=messages, response_format={\"type\": \"json_object\"}\n",
" )\n",
" else:\n",
" chat_response = client.chat(model=model, messages=messages)\n",
" chat_response = client.chat.complete(model=model, messages=messages)\n",
"\n",
" return chat_response.choices[0].message.content"
]
Expand Down
14 changes: 6 additions & 8 deletions cookbooks/python/mistralai/function_calling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@
"metadata": {},
"outputs": [],
"source": [
"from mistralai.models.chat_completion import ChatMessage\n",
"from mistralai import Mistral\n",
"\n",
"messages = [\n",
" ChatMessage(role=\"user\", content=\"What's the status of my transaction T1001?\")\n",
" {\"role\":\"user\", \"content\":\"What's the status of my transaction T1001?\"}\n",
"]\n"
]
},
Expand All @@ -214,13 +214,11 @@
"metadata": {},
"outputs": [],
"source": [
"from mistralai.client import MistralClient\n",
"\n",
"model = \"mistral-large\"\n",
"\n",
"client = MistralClient(api_key=github_token, endpoint=endpoint)\n",
"client = Mistral(api_key=github_token, server_url=endpoint)\n",
"\n",
"response = client.chat(\n",
"response = client.chat.complete(\n",
" model=model,\n",
" messages=messages,\n",
" tools=tools,\n",
Expand Down Expand Up @@ -294,7 +292,7 @@
"metadata": {},
"outputs": [],
"source": [
"messages.append(ChatMessage(role=\"tool\", name=function_name, content=function_result, tool_call_id=tool_call.id))"
"messages.append({\"role\":\"tool\", \"name\":function_name, \"content\":function_result, \"tool_call_id\":tool_call.id})"
]
},
{
Expand Down Expand Up @@ -324,7 +322,7 @@
"metadata": {},
"outputs": [],
"source": [
"response = client.chat(\n",
"response = client.chat.complete(\n",
" model=model,\n",
" messages=messages\n",
")\n",
Expand Down
Loading