-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mistralai[minor]: Add llms entrypoint, update chat model integration (#…
…5603) * mistralai[minor]: Add llms entrypoint * chore: lint files * cr * docs * docs nit * docs nit * update mistral-large models to mistral-large-latest * fix tools * add codestral chat model tests * chore: lint files * cr
- Loading branch information
1 parent
64bf268
commit 331e856
Showing
14 changed files
with
844 additions
and
82 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+309 KB
...ralai-npm-0.1.3-934551f985-3f8299811b.zip → ...ralai-npm-0.4.0-843348d71c-1b03fc0b55.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.