diff --git a/docs/core_docs/docs/integrations/chat/fireworks.ipynb b/docs/core_docs/docs/integrations/chat/fireworks.ipynb index e5276cd34c6b..9c2219315fca 100644 --- a/docs/core_docs/docs/integrations/chat/fireworks.ipynb +++ b/docs/core_docs/docs/integrations/chat/fireworks.ipynb @@ -3,10 +3,14 @@ { "cell_type": "raw", "id": "afaf8039", - "metadata": {}, + "metadata": { + "vscode": { + "languageId": "raw" + } + }, "source": [ "---\n", - "sidebar_label: ChatFireworks\n", + "sidebar_label: Fireworks\n", "---" ] }, @@ -24,7 +28,7 @@ "\n", "| Class | Package | Local | Serializable | [PY support](https:/python.langchain.com/v0.2/docs/integrations/chat/fireworks) | Package downloads | Package latest |\n", "| :--- | :--- | :---: | :---: | :---: | :---: | :---: |\n", - "| [ChatFireworks](https://api.js.langchain.com/classes/langchain_community_chat_models_fireworks.ChatFireworks.html) | [@langchain/community](https://api.js.langchain.com/modules/langchain_community_chat_models_fireworks.html) | ❌ | ✅ | ✅ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/community?style=flat-square&label=%20) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20) |\n", + "| [ChatFireworks](https://api.js.langchain.com/classes/langchain_community_chat_models_fireworks.ChatFireworks.html) | [@langchain/community](https://api.js.langchain.com/modules/langchain_community_chat_models_fireworks.html) | ❌ | ✅ | ✅ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/community?style=flat-square&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n", "\n", "### Model features\n", "| [Tool calling](/docs/how_to/tool_calling) | [Structured output](/docs/how_to/structured_output/) | JSON mode | [Image input](/docs/how_to/multimodal_inputs/) | Audio input | Video input | [Token-level streaming](/docs/how_to/chat_streaming/) | [Token usage](/docs/how_to/chat_token_usage_tracking/) | [Logprobs](/docs/how_to/logprobs/) |\n", diff --git a/docs/core_docs/docs/integrations/chat/mistral.ipynb b/docs/core_docs/docs/integrations/chat/mistral.ipynb index f308e0c1d768..047ec3c4e1ad 100644 --- a/docs/core_docs/docs/integrations/chat/mistral.ipynb +++ b/docs/core_docs/docs/integrations/chat/mistral.ipynb @@ -3,10 +3,14 @@ { "cell_type": "raw", "id": "afaf8039", - "metadata": {}, + "metadata": { + "vscode": { + "languageId": "raw" + } + }, "source": [ "---\n", - "sidebar_label: ChatMistralAI\n", + "sidebar_label: MistralAI\n", "---" ] }, @@ -24,7 +28,7 @@ "\n", "| Class | Package | Local | Serializable | [PY support](https:/python.langchain.com/v0.2/docs/integrations/chat/mistralai) | Package downloads | Package latest |\n", "| :--- | :--- | :---: | :---: | :---: | :---: | :---: |\n", - "| [ChatMistralAI](https://api.js.langchain.com/classes/langchain_mistralai.ChatMistralAI.html) | [@langchain/mistralai](https://api.js.langchain.com/modules/langchain_mistralai.html) | ❌ | ❌ | ✅ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/mistralai?style=flat-square&label=%20) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/mistralai?style=flat-square&label=%20) |\n", + "| [ChatMistralAI](https://api.js.langchain.com/classes/langchain_mistralai.ChatMistralAI.html) | [@langchain/mistralai](https://api.js.langchain.com/modules/langchain_mistralai.html) | ❌ | ❌ | ✅ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/mistralai?style=flat-square&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/mistralai?style=flat-square&label=%20&) |\n", "\n", "### Model features\n", "| [Tool calling](/docs/how_to/tool_calling) | [Structured output](/docs/how_to/structured_output/) | JSON mode | [Image input](/docs/how_to/multimodal_inputs/) | Audio input | Video input | [Token-level streaming](/docs/how_to/chat_streaming/) | [Token usage](/docs/how_to/chat_token_usage_tracking/) | [Logprobs](/docs/how_to/logprobs/) |\n", @@ -250,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "id": "98d9034c", "metadata": {}, "outputs": [ @@ -263,7 +267,7 @@ " name: 'calculator',\n", " args: { operation: 'add', number1: 2, number2: 2 },\n", " type: 'tool_call',\n", - " id: '2HFfjvCvo'\n", + " id: 'Tn8X3UCSP'\n", " }\n", "]\n" ] @@ -275,7 +279,7 @@ "import { z } from \"zod\";\n", "import { tool } from \"@langchain/core/tools\";\n", "\n", - "const calculatorSchema2 = z.object({\n", + "const calculatorSchema = z.object({\n", " operation: z\n", " .enum([\"add\", \"subtract\", \"multiply\", \"divide\"])\n", " .describe(\"The type of operation to execute.\"),\n", @@ -283,24 +287,23 @@ " number2: z.number().describe(\"The second number to operate on.\"),\n", "});\n", "\n", - "const calculatorTool2 = tool((input) => {\n", + "const calculatorTool = tool((input) => {\n", " return JSON.stringify(input);\n", "}, {\n", " name: \"calculator\",\n", " description: \"A simple calculator tool\",\n", - " schema: calculatorSchema2,\n", + " schema: calculatorSchema,\n", "});\n", "\n", - "const llm2 = new ChatMistralAI({\n", + "// Bind the tool to the model\n", + "const modelWithTool = new ChatMistralAI({\n", " model: \"mistral-large-latest\",\n", + "}).bind({\n", + " tools: [calculatorTool],\n", "});\n", "\n", - "// Bind the tool to the model\n", - "const modelWithTool2 = llm2.bind({\n", - " tools: [calculatorTool2],\n", - "});\n", "\n", - "const prompt2 = ChatPromptTemplate.fromMessages([\n", + "const calcToolPrompt = ChatPromptTemplate.fromMessages([\n", " [\n", " \"system\",\n", " \"You are a helpful assistant who always needs to use a calculator.\",\n", @@ -309,12 +312,12 @@ "]);\n", "\n", "// Chain your prompt, model, and output parser together\n", - "const chain2 = prompt2.pipe(modelWithTool2);\n", + "const chainWithCalcTool = calcToolPrompt.pipe(modelWithTool);\n", "\n", - "const response2 = await chain2.invoke({\n", + "const calcToolRes = await chainWithCalcTool.invoke({\n", " input: \"What is 2 + 2?\",\n", "});\n", - "console.log(response2.tool_calls);" + "console.log(calcToolRes.tool_calls);" ] }, { @@ -337,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "id": "a8638d82", "metadata": {}, "outputs": [ @@ -354,7 +357,7 @@ "import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n", "import { z } from \"zod\";\n", "\n", - "const calculatorSchema3 = z\n", + "const calculatorSchemaForWSO = z\n", " .object({\n", " operation: z\n", " .enum([\"add\", \"subtract\", \"multiply\", \"divide\"])\n", @@ -364,14 +367,16 @@ " })\n", " .describe(\"A simple calculator tool\");\n", "\n", - "const llm3 = new ChatMistralAI({\n", + "const llmForWSO = new ChatMistralAI({\n", " model: \"mistral-large-latest\",\n", - "});\n", + "})\n", "\n", "// Pass the schema and tool name to the withStructuredOutput method\n", - "const modelWithTool3 = llm3.withStructuredOutput(calculatorSchema3);\n", + "const modelWithStructuredOutput = llmForWSO.withStructuredOutput(calculatorSchemaForWSO, {\n", + " name: \"calculator\",\n", + "});\n", "\n", - "const prompt3 = ChatPromptTemplate.fromMessages([\n", + "const promptForWSO = ChatPromptTemplate.fromMessages([\n", " [\n", " \"system\",\n", " \"You are a helpful assistant who always needs to use a calculator.\",\n", @@ -380,12 +385,12 @@ "]);\n", "\n", "// Chain your prompt and model together\n", - "const chain3 = prompt3.pipe(modelWithTool3);\n", + "const chainWSO = promptForWSO.pipe(modelWithStructuredOutput);\n", "\n", - "const response3 = await chain3.invoke({\n", + "const responseWSO = await chainWSO.invoke({\n", " input: \"What is 2 + 2?\",\n", "});\n", - "console.log(response3);" + "console.log(responseWSO);" ] }, { @@ -398,7 +403,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "id": "9786b41a", "metadata": {}, "outputs": [ @@ -416,14 +421,14 @@ " name: 'calculator',\n", " args: { operation: 'add', number1: 2, number2: 2 },\n", " type: 'tool_call',\n", - " id: 'qVxKofNLR'\n", + " id: 'w48T6Nc3d'\n", " }\n", " ],\n", " invalid_tool_calls: [],\n", " additional_kwargs: {\n", " tool_calls: [\n", " {\n", - " id: 'qVxKofNLR',\n", + " id: 'w48T6Nc3d',\n", " function: {\n", " name: 'calculator',\n", " arguments: '{\"operation\": \"add\", \"number1\": 2, \"number2\": 2}'\n", @@ -441,7 +446,7 @@ " additional_kwargs: {\n", " tool_calls: [\n", " {\n", - " id: 'qVxKofNLR',\n", + " id: 'w48T6Nc3d',\n", " function: {\n", " name: 'calculator',\n", " arguments: '{\"operation\": \"add\", \"number1\": 2, \"number2\": 2}'\n", @@ -460,7 +465,7 @@ " name: 'calculator',\n", " args: { operation: 'add', number1: 2, number2: 2 },\n", " type: 'tool_call',\n", - " id: 'qVxKofNLR'\n", + " id: 'w48T6Nc3d'\n", " }\n", " ],\n", " invalid_tool_calls: [],\n", @@ -472,16 +477,16 @@ } ], "source": [ - "const includeRawModel3 = llm3.withStructuredOutput(calculatorSchema3, {\n", + "const includeRawModel = llmForWSO.withStructuredOutput(calculatorSchemaForWSO, {\n", " name: \"calculator\",\n", " includeRaw: true,\n", "});\n", - "const includeRawChain3 = prompt3.pipe(includeRawModel3);\n", + "const includeRawChain = promptForWSO.pipe(includeRawModel);\n", "\n", - "const includeRawResponse3 = await includeRawChain3.invoke({\n", + "const includeRawResponse = await includeRawChain.invoke({\n", " input: \"What is 2 + 2?\",\n", "});\n", - "console.dir(includeRawResponse3, { depth: null });" + "console.dir(includeRawResponse, { depth: null });" ] }, { @@ -494,7 +499,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "id": "9f1dc9bd", "metadata": {}, "outputs": [ @@ -510,7 +515,7 @@ "import { ChatMistralAI } from \"@langchain/mistralai\";\n", "import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n", "\n", - "const calculatorJsonSchema4 = {\n", + "const calculatorJsonSchema = {\n", " type: \"object\",\n", " properties: {\n", " operation: {\n", @@ -528,14 +533,14 @@ " description: \"A simple calculator tool\",\n", "};\n", "\n", - "const llm4 = new ChatMistralAI({\n", + "const llmForJsonSchema = new ChatMistralAI({\n", " model: \"mistral-large-latest\",\n", "});\n", "\n", "// Pass the schema and tool name to the withStructuredOutput method\n", - "const modelWithTool4 = llm4.withStructuredOutput(calculatorJsonSchema4);\n", + "const modelWithJsonSchemaTool = llmForJsonSchema.withStructuredOutput(calculatorJsonSchema);\n", "\n", - "const prompt4 = ChatPromptTemplate.fromMessages([\n", + "const promptForJsonSchema = ChatPromptTemplate.fromMessages([\n", " [\n", " \"system\",\n", " \"You are a helpful assistant who always needs to use a calculator.\",\n", @@ -544,12 +549,12 @@ "]);\n", "\n", "// Chain your prompt and model together\n", - "const chain4 = prompt4.pipe(modelWithTool4);\n", + "const chainWithJsonSchema = promptForJsonSchema.pipe(modelWithJsonSchemaTool);\n", "\n", - "const response4 = await chain4.invoke({\n", + "const responseFromJsonSchema = await chainWithJsonSchema.invoke({\n", " input: \"What is 2 + 2?\",\n", "});\n", - "console.log(response4);\n" + "console.log(responseFromJsonSchema);\n" ] }, { @@ -565,7 +570,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "id": "76bd0061", "metadata": {}, "outputs": [ @@ -573,7 +578,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "The weather in Paris is 28 °C.\n" + "It's 28 °C in Paris.\n" ] } ], @@ -585,13 +590,13 @@ "\n", "import { ChatPromptTemplate } from \"@langchain/core/prompts\";\n", "\n", - "const llm5 = new ChatMistralAI({\n", + "const llmForAgent = new ChatMistralAI({\n", " temperature: 0,\n", " model: \"mistral-large-latest\",\n", "});\n", "\n", "// Prompt template must have \"input\" and \"agent_scratchpad input variables\"\n", - "const prompt5 = ChatPromptTemplate.fromMessages([\n", + "const agentPrompt = ChatPromptTemplate.fromMessages([\n", " [\"system\", \"You are a helpful assistant\"],\n", " [\"placeholder\", \"{chat_history}\"],\n", " [\"human\", \"{input}\"],\n", @@ -599,7 +604,7 @@ "]);\n", "\n", "// Mocked tool\n", - "const currentWeatherTool5 = tool(async () => \"28 °C\", {\n", + "const currentWeatherToolForAgent = tool(async () => \"28 °C\", {\n", " name: \"get_current_weather\",\n", " description: \"Get the current weather in a given location\",\n", " schema: z.object({\n", @@ -608,20 +613,20 @@ "});\n", "\n", "const agent = createToolCallingAgent({\n", - " llm: llm5,\n", - " tools: [currentWeatherTool5],\n", - " prompt: prompt5,\n", + " llm: llmForAgent,\n", + " tools: [currentWeatherToolForAgent],\n", + " prompt: agentPrompt,\n", "});\n", "\n", "const agentExecutor = new AgentExecutor({\n", " agent,\n", - " tools: [currentWeatherTool5],\n", + " tools: [currentWeatherToolForAgent],\n", "});\n", "\n", - "const input = \"What's the weather like in Paris?\";\n", - "const { output } = await agentExecutor.invoke({ input });\n", + "const agentInput = \"What's the weather like in Paris?\";\n", + "const agentRes = await agentExecutor.invoke({ input: agentInput });\n", "\n", - "console.log(output);\n" + "console.log(agentRes.output);\n" ] }, {