-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
mistralai[minor]: Add llms entrypoint, update chat model integration #5603
Changes from all commits
116e01d
6d5a259
6a17555
4a91836
61c8d36
810a0f8
1397691
6278b57
9dc95f0
21fdc59
680456e
a19c918
4e7f47f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# MistralAI\n", | ||
"\n", | ||
"```{=mdx}\n", | ||
":::tip\n", | ||
"Want to run Mistral's models locally? Check out our [Ollama integration](/docs/integrations/chat/ollama).\n", | ||
":::\n", | ||
"```\n", | ||
"\n", | ||
"Here's how you can initialize an `MistralAI` LLM instance:\n", | ||
"\n", | ||
"```{=mdx}\n", | ||
"import IntegrationInstallTooltip from \"@mdx_components/integration_install_tooltip.mdx\";\n", | ||
"import Npm2Yarn from \"@theme/Npm2Yarn\";\n", | ||
"\n", | ||
"<IntegrationInstallTooltip></IntegrationInstallTooltip>\n", | ||
"\n", | ||
"<Npm2Yarn>\n", | ||
" @langchain/mistralai\n", | ||
"</Npm2Yarn>\n", | ||
"```\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"console.log('hello world');\n", | ||
"```\n", | ||
"This will output 'hello world' to the console.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import { MistralAI } from \"@langchain/mistralai\";\n", | ||
"\n", | ||
"const model = new MistralAI({\n", | ||
" model: \"codestral-latest\", // Defaults to \"codestral-latest\" if no model provided.\n", | ||
" temperature: 0,\n", | ||
" apiKey: \"YOUR-API-KEY\", // In Node.js defaults to process.env.MISTRAL_API_KEY\n", | ||
"});\n", | ||
"const res = await model.invoke(\n", | ||
" \"You can print 'hello world' to the console in javascript like this:\\n```javascript\"\n", | ||
");\n", | ||
"console.log(res);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Since the Mistral LLM is a completions model, they also allow you to insert a `suffix` to the prompt. Suffixes can be passed via the call options when invoking a model like so:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"console.log('hello world');\n", | ||
"```\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"const res = await model.invoke(\n", | ||
" \"You can print 'hello world' to the console in javascript like this:\\n```javascript\", {\n", | ||
" suffix: \"```\"\n", | ||
" }\n", | ||
");\n", | ||
"console.log(res);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"As seen in the first example, the model generated the requested `console.log('hello world')` code snippet, but also included extra unwanted text. By adding a suffix, we can constrain the model to only complete the prompt up to the suffix (in this case, three backticks). This allows us to easily parse the completion and extract only the desired response without the suffix using a custom output parser." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"console.log('hello world');\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import { MistralAI } from \"@langchain/mistralai\";\n", | ||
"\n", | ||
"const model = new MistralAI({\n", | ||
" model: \"codestral-latest\",\n", | ||
" temperature: 0,\n", | ||
" apiKey: \"YOUR-API-KEY\",\n", | ||
"});\n", | ||
"\n", | ||
"const suffix = \"```\";\n", | ||
"\n", | ||
"const customOutputParser = (input: string) => {\n", | ||
" if (input.includes(suffix)) {\n", | ||
" return input.split(suffix)[0];\n", | ||
" }\n", | ||
" throw new Error(\"Input does not contain suffix.\")\n", | ||
"};\n", | ||
"\n", | ||
"const res = await model.invoke(\n", | ||
" \"You can print 'hello world' to the console in javascript like this:\\n```javascript\", {\n", | ||
" suffix,\n", | ||
" }\n", | ||
");\n", | ||
"\n", | ||
"console.log(customOutputParser(res));" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "TypeScript", | ||
"language": "typescript", | ||
"name": "tslab" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"mode": "typescript", | ||
"name": "javascript", | ||
"typescript": true | ||
}, | ||
"file_extension": ".ts", | ||
"mimetype": "text/typescript", | ||
"name": "typescript", | ||
"version": "3.7.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ const calculatorSchema = z | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey there! I've noticed that the recent change in the |
||
const model = new ChatMistralAI({ | ||
apiKey: process.env.MISTRAL_API_KEY, | ||
model: "mistral-large", | ||
model: "mistral-large-latest", | ||
}); | ||
|
||
// Pass the schema and tool name to the withStructuredOutput method | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ const calculatorJsonSchema = { | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey there! I've reviewed the code and noticed that the recent change in the |
||
const model = new ChatMistralAI({ | ||
apiKey: process.env.MISTRAL_API_KEY, | ||
model: "mistral-large", | ||
model: "mistral-large-latest", | ||
}); | ||
|
||
// Pass the schema and tool name to the withStructuredOutput method | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there! I've reviewed the code and noticed a change in the
model
initialization, updating themodel
property from "mistral-large" to "mistral-large-latest". I've flagged this for your review as it also accesses an environment variable usingprocess.env.MISTRAL_API_KEY
. Keep up the great work!