!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

You are viewing the **preview** v0.2 docs. View the **stable** v0.1 docs [here](/v0.1/docs/get_started/introduction/). Leave feedback on the v0.2 docs [here](https://github.com/langchain-ai/langchainjs/discussions/5386).

[

![🦜️🔗 Langchain](/v0.2/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.2/img/brand/wordmark-dark.png)

](/v0.2/)[Integrations](/v0.2/docs/integrations/platforms/)[API Reference](https://v02.api.js.langchain.com)

[More](#)

*   [People](/v0.2/docs/people/)
*   [Community](/v0.2/docs/community)
*   [Tutorials](/v0.2/docs/additional_resources/tutorials)
*   [Contributing](/v0.2/docs/contributing)

[v0.2](#)

*   [v0.2](/v0.2/docs/introduction)
*   [v0.1](https://js.langchain.com/v0.1/docs/get_started/introduction)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Providers](/v0.2/docs/integrations/platforms/)
    
    *   [Providers](/v0.2/docs/integrations/platforms/)
    *   [Anthropic](/v0.2/docs/integrations/platforms/anthropic)
    *   [AWS](/v0.2/docs/integrations/platforms/aws)
    *   [Google](/v0.2/docs/integrations/platforms/google)
    *   [Microsoft](/v0.2/docs/integrations/platforms/microsoft)
    *   [OpenAI](/v0.2/docs/integrations/platforms/openai)
*   [Components](/v0.2/docs/integrations/components)
    
    *   [Chat models](/v0.2/docs/integrations/chat/)
        
        *   [Chat models](/v0.2/docs/integrations/chat/)
        *   [Alibaba Tongyi](/v0.2/docs/integrations/chat/alibaba_tongyi)
        *   [Anthropic](/v0.2/docs/integrations/chat/anthropic)
        *   [Anthropic Tools](/v0.2/docs/integrations/chat/anthropic_tools)
        *   [Azure OpenAI](/v0.2/docs/integrations/chat/azure)
        *   [Baidu Wenxin](/v0.2/docs/integrations/chat/baidu_wenxin)
        *   [Bedrock](/v0.2/docs/integrations/chat/bedrock)
        *   [Cloudflare Workers AI](/v0.2/docs/integrations/chat/cloudflare_workersai)
        *   [Cohere](/v0.2/docs/integrations/chat/cohere)
        *   [Fake LLM](/v0.2/docs/integrations/chat/fake)
        *   [Fireworks](/v0.2/docs/integrations/chat/fireworks)
        *   [Friendli](/v0.2/docs/integrations/chat/friendli)
        *   [Google GenAI](/v0.2/docs/integrations/chat/google_generativeai)
        *   [(Legacy) Google PaLM/VertexAI](/v0.2/docs/integrations/chat/google_palm)
        *   [Google Vertex AI](/v0.2/docs/integrations/chat/google_vertex_ai)
        *   [Groq](/v0.2/docs/integrations/chat/groq)
        *   [Llama CPP](/v0.2/docs/integrations/chat/llama_cpp)
        *   [Minimax](/v0.2/docs/integrations/chat/minimax)
        *   [Mistral AI](/v0.2/docs/integrations/chat/mistral)
        *   [NIBittensorChatModel](/v0.2/docs/integrations/chat/ni_bittensor)
        *   [Ollama](/v0.2/docs/integrations/chat/ollama)
        *   [Ollama Functions](/v0.2/docs/integrations/chat/ollama_functions)
        *   [OpenAI](/v0.2/docs/integrations/chat/openai)
        *   [PremAI](/v0.2/docs/integrations/chat/premai)
        *   [PromptLayer OpenAI](/v0.2/docs/integrations/chat/prompt_layer_openai)
        *   [TogetherAI](/v0.2/docs/integrations/chat/togetherai)
        *   [WebLLM](/v0.2/docs/integrations/chat/web_llm)
        *   [YandexGPT](/v0.2/docs/integrations/chat/yandex)
        *   [ZhipuAI](/v0.2/docs/integrations/chat/zhipuai)
    *   [LLMs](/v0.2/docs/integrations/llms/)
        
    *   [Embedding models](/v0.2/docs/integrations/text_embedding)
        
    *   [Document loaders](/v0.2/docs/integrations/document_loaders)
        
    *   [Document transformers](/v0.2/docs/integrations/document_transformers)
        
    *   [Vector stores](/v0.2/docs/integrations/vectorstores)
        
    *   [Retrievers](/v0.2/docs/integrations/retrievers)
        
    *   [Tools](/v0.2/docs/integrations/tools)
        
    *   [Toolkits](/v0.2/docs/integrations/toolkits)
        
    *   [Stores](/v0.2/docs/integrations/stores/)
        

*   [](/v0.2/)
*   [Components](/v0.2/docs/integrations/components)
*   [Chat models](/v0.2/docs/integrations/chat/)
*   Minimax

On this page

Minimax
=======

[Minimax](https://api.minimax.chat) is a Chinese startup that provides natural language processing models for companies and individuals.

This example demonstrates using LangChain.js to interact with Minimax.

Setup[​](#setup "Direct link to Setup")
---------------------------------------

To use Minimax models, you'll need a [Minimax account](https://api.minimax.chat), an [API key](https://api.minimax.chat/user-center/basic-information/interface-key), and a [Group ID](https://api.minimax.chat/user-center/basic-information)

tip

See [this section for general instructions on installing integration packages](/v0.2/docs/how_to/installation#installing-integration-packages).

*   npm
*   Yarn
*   pnpm

    npm install @langchain/community

    yarn add @langchain/community

    pnpm add @langchain/community

tip

We're unifying model params across all packages. We now suggest using `model` instead of `modelName`, and `apiKey` for API keys.

Basic usage[​](#basic-usage "Direct link to Basic usage")
---------------------------------------------------------

    import { ChatMinimax } from "@langchain/community/chat_models/minimax";import { HumanMessage } from "@langchain/core/messages";// Use abab5.5const abab5_5 = new ChatMinimax({  model: "abab5.5-chat",  botSetting: [    {      bot_name: "MM Assistant",      content: "MM Assistant is an AI Assistant developed by minimax.",    },  ],});const messages = [  new HumanMessage({    content: "Hello",  }),];const res = await abab5_5.invoke(messages);console.log(res);/*AIChatMessage {  text: 'Hello! How may I assist you today?',  name: undefined,  additional_kwargs: {}  }}*/// use abab5const abab5 = new ChatMinimax({  proVersion: false,  model: "abab5-chat",  minimaxGroupId: process.env.MINIMAX_GROUP_ID, // In Node.js defaults to process.env.MINIMAX_GROUP_ID  minimaxApiKey: process.env.MINIMAX_API_KEY, // In Node.js defaults to process.env.MINIMAX_API_KEY});const result = await abab5.invoke([  new HumanMessage({    content: "Hello",    name: "XiaoMing",  }),]);console.log(result);/*AIMessage {  lc_serializable: true,  lc_kwargs: {    content: 'Hello! Can I help you with anything?',    additional_kwargs: { function_call: undefined }  },  lc_namespace: [ 'langchain', 'schema' ],  content: 'Hello! Can I help you with anything?',  name: undefined,  additional_kwargs: { function_call: undefined }} */

#### API Reference:

*   [ChatMinimax](https://v02.api.js.langchain.com/classes/langchain_community_chat_models_minimax.ChatMinimax.html) from `@langchain/community/chat_models/minimax`
*   [HumanMessage](https://v02.api.js.langchain.com/classes/langchain_core_messages.HumanMessage.html) from `@langchain/core/messages`

Chain model calls[​](#chain-model-calls "Direct link to Chain model calls")
---------------------------------------------------------------------------

    import { LLMChain } from "langchain/chains";import { ChatMinimax } from "@langchain/community/chat_models/minimax";import {  ChatPromptTemplate,  HumanMessagePromptTemplate,  SystemMessagePromptTemplate,} from "@langchain/core/prompts";// We can also construct an LLMChain from a ChatPromptTemplate and a chat model.const chat = new ChatMinimax({ temperature: 0.01 });const chatPrompt = ChatPromptTemplate.fromMessages([  SystemMessagePromptTemplate.fromTemplate(    "You are a helpful assistant that translates {input_language} to {output_language}."  ),  HumanMessagePromptTemplate.fromTemplate("{text}"),]);const chainB = new LLMChain({  prompt: chatPrompt,  llm: chat,});const resB = await chainB.invoke({  input_language: "English",  output_language: "Chinese",  text: "I love programming.",});console.log({ resB });

#### API Reference:

*   [LLMChain](https://v02.api.js.langchain.com/classes/langchain_chains.LLMChain.html) from `langchain/chains`
*   [ChatMinimax](https://v02.api.js.langchain.com/classes/langchain_community_chat_models_minimax.ChatMinimax.html) from `@langchain/community/chat_models/minimax`
*   [ChatPromptTemplate](https://v02.api.js.langchain.com/classes/langchain_core_prompts.ChatPromptTemplate.html) from `@langchain/core/prompts`
*   [HumanMessagePromptTemplate](https://v02.api.js.langchain.com/classes/langchain_core_prompts.HumanMessagePromptTemplate.html) from `@langchain/core/prompts`
*   [SystemMessagePromptTemplate](https://v02.api.js.langchain.com/classes/langchain_core_prompts.SystemMessagePromptTemplate.html) from `@langchain/core/prompts`

With function calls[​](#with-function-calls "Direct link to With function calls")
---------------------------------------------------------------------------------

    import { ChatMinimax } from "@langchain/community/chat_models/minimax";import { HumanMessage } from "@langchain/core/messages";const functionSchema = {  name: "get_weather",  description: " Get weather information.",  parameters: {    type: "object",    properties: {      location: {        type: "string",        description: " The location to get the weather",      },    },    required: ["location"],  },};// Bind function arguments to the model.// All subsequent invoke calls will use the bound parameters.// "functions.parameters" must be formatted as JSON Schemaconst model = new ChatMinimax({  botSetting: [    {      bot_name: "MM Assistant",      content: "MM Assistant is an AI Assistant developed by minimax.",    },  ],}).bind({  functions: [functionSchema],});const result = await model.invoke([  new HumanMessage({    content: " What is the weather like in NewYork tomorrow?",    name: "I",  }),]);console.log(result);/*AIMessage {  lc_serializable: true,  lc_kwargs: { content: '', additional_kwargs: { function_call: [Object] } },  lc_namespace: [ 'langchain', 'schema' ],  content: '',  name: undefined,  additional_kwargs: {    function_call: { name: 'get_weather', arguments: '{"location": "NewYork"}' }  }}*/// Alternatively, you can pass function call arguments as an additional argument as a one-off:const minimax = new ChatMinimax({  model: "abab5.5-chat",  botSetting: [    {      bot_name: "MM Assistant",      content: "MM Assistant is an AI Assistant developed by minimax.",    },  ],});const result2 = await minimax.invoke(  [new HumanMessage("What is the weather like in NewYork tomorrow?")],  {    functions: [functionSchema],  });console.log(result2);/*AIMessage {  lc_serializable: true,  lc_kwargs: { content: '', additional_kwargs: { function_call: [Object] } },  lc_namespace: [ 'langchain', 'schema' ],  content: '',  name: undefined,  additional_kwargs: {    function_call: { name: 'get_weather', arguments: '{"location": "NewYork"}' }  }} */

#### API Reference:

*   [ChatMinimax](https://v02.api.js.langchain.com/classes/langchain_community_chat_models_minimax.ChatMinimax.html) from `@langchain/community/chat_models/minimax`
*   [HumanMessage](https://v02.api.js.langchain.com/classes/langchain_core_messages.HumanMessage.html) from `@langchain/core/messages`

Functions with Zod[​](#functions-with-zod "Direct link to Functions with Zod")
------------------------------------------------------------------------------

    import { z } from "zod";import { zodToJsonSchema } from "zod-to-json-schema";import { ChatMinimax } from "@langchain/community/chat_models/minimax";import { HumanMessage } from "@langchain/core/messages";const extractionFunctionZodSchema = z.object({  location: z.string().describe(" The location to get the weather"),});// Bind function arguments to the model.// "functions.parameters" must be formatted as JSON Schema.// We translate the above Zod schema into JSON schema using the "zodToJsonSchema" package.const model = new ChatMinimax({  model: "abab5.5-chat",  botSetting: [    {      bot_name: "MM Assistant",      content: "MM Assistant is an AI Assistant developed by minimax.",    },  ],}).bind({  functions: [    {      name: "get_weather",      description: " Get weather information.",      parameters: zodToJsonSchema(extractionFunctionZodSchema),    },  ],});const result = await model.invoke([  new HumanMessage({    content: " What is the weather like in Shanghai tomorrow?",    name: "XiaoMing",  }),]);console.log(result);/*AIMessage {  lc_serializable: true,  lc_kwargs: { content: '', additional_kwargs: { function_call: [Object] } },  lc_namespace: [ 'langchain', 'schema' ],  content: '',  name: undefined,  additional_kwargs: {    function_call: { name: 'get_weather', arguments: '{"location": "Shanghai"}' }  }}*/

#### API Reference:

*   [ChatMinimax](https://v02.api.js.langchain.com/classes/langchain_community_chat_models_minimax.ChatMinimax.html) from `@langchain/community/chat_models/minimax`
*   [HumanMessage](https://v02.api.js.langchain.com/classes/langchain_core_messages.HumanMessage.html) from `@langchain/core/messages`

With glyph[​](#with-glyph "Direct link to With glyph")
------------------------------------------------------

This feature can help users force the model to return content in the requested format.

    import { ChatMinimax } from "@langchain/community/chat_models/minimax";import {  ChatPromptTemplate,  HumanMessagePromptTemplate,} from "@langchain/core/prompts";import { HumanMessage } from "@langchain/core/messages";const model = new ChatMinimax({  model: "abab5.5-chat",  botSetting: [    {      bot_name: "MM Assistant",      content: "MM Assistant is an AI Assistant developed by minimax.",    },  ],}).bind({  replyConstraints: {    sender_type: "BOT",    sender_name: "MM Assistant",    glyph: {      type: "raw",      raw_glyph: "The translated text：{{gen 'content'}}",    },  },});const messagesTemplate = ChatPromptTemplate.fromMessages([  HumanMessagePromptTemplate.fromTemplate(    " Please help me translate the following sentence in English： {text}"  ),]);const messages = await messagesTemplate.formatMessages({ text: "我是谁" });const result = await model.invoke(messages);console.log(result);/*AIMessage {  lc_serializable: true,  lc_kwargs: {    content: 'The translated text： Who am I\x02',    additional_kwargs: { function_call: undefined }  },  lc_namespace: [ 'langchain', 'schema' ],  content: 'The translated text： Who am I\x02',  name: undefined,  additional_kwargs: { function_call: undefined }}*/// use json_valueconst modelMinimax = new ChatMinimax({  model: "abab5.5-chat",  botSetting: [    {      bot_name: "MM Assistant",      content: "MM Assistant is an AI Assistant developed by minimax.",    },  ],}).bind({  replyConstraints: {    sender_type: "BOT",    sender_name: "MM Assistant",    glyph: {      type: "json_value",      json_properties: {        name: {          type: "string",        },        age: {          type: "number",        },        is_student: {          type: "boolean",        },        is_boy: {          type: "boolean",        },        courses: {          type: "object",          properties: {            name: {              type: "string",            },            score: {              type: "number",            },          },        },      },    },  },});const result2 = await modelMinimax.invoke([  new HumanMessage({    content:      " My name is Yue Wushuang, 18 years old this year, just finished the test with 99.99 points.",    name: "XiaoMing",  }),]);console.log(result2);/*AIMessage {  lc_serializable: true,  lc_kwargs: {    content: '{\n' +      '  "name": "Yue Wushuang",\n' +      '  "is_student": true,\n' +      '  "is_boy": false,\n' +      '  "courses":   {\n' +      '    "name": "Mathematics",\n' +      '    "score": 99.99\n' +      '   },\n' +      '  "age": 18\n' +      ' }',    additional_kwargs: { function_call: undefined }  }} */

#### API Reference:

*   [ChatMinimax](https://v02.api.js.langchain.com/classes/langchain_community_chat_models_minimax.ChatMinimax.html) from `@langchain/community/chat_models/minimax`
*   [ChatPromptTemplate](https://v02.api.js.langchain.com/classes/langchain_core_prompts.ChatPromptTemplate.html) from `@langchain/core/prompts`
*   [HumanMessagePromptTemplate](https://v02.api.js.langchain.com/classes/langchain_core_prompts.HumanMessagePromptTemplate.html) from `@langchain/core/prompts`
*   [HumanMessage](https://v02.api.js.langchain.com/classes/langchain_core_messages.HumanMessage.html) from `@langchain/core/messages`

With sample messages[​](#with-sample-messages "Direct link to With sample messages")
------------------------------------------------------------------------------------

This feature can help the model better understand the return information the user wants to get, including but not limited to the content, format, and response mode of the information.

    import { ChatMinimax } from "@langchain/community/chat_models/minimax";import { AIMessage, HumanMessage } from "@langchain/core/messages";const model = new ChatMinimax({  model: "abab5.5-chat",  botSetting: [    {      bot_name: "MM Assistant",      content: "MM Assistant is an AI Assistant developed by minimax.",    },  ],}).bind({  sampleMessages: [    new HumanMessage({      content: " Turn A5 into red and modify the content to minimax.",    }),    new AIMessage({      content: "select A5 color red change minimax",    }),  ],});const result = await model.invoke([  new HumanMessage({    content:      ' Please reply to my content according to the following requirements: According to the following interface list, give the order and parameters of calling the interface for the content I gave. You just need to give the order and parameters of calling the interface, and do not give any other output. The following is the available interface list: select: select specific table position, input parameter use letters and numbers to determine, for example "B13"; color: dye the selected table position, input parameters use the English name of the color, for example "red"; change: modify the selected table position, input parameters use strings.',  }),  new HumanMessage({    content: " Process B6 to gray and modify the content to question.",  }),]);console.log(result);

#### API Reference:

*   [ChatMinimax](https://v02.api.js.langchain.com/classes/langchain_community_chat_models_minimax.ChatMinimax.html) from `@langchain/community/chat_models/minimax`
*   [AIMessage](https://v02.api.js.langchain.com/classes/langchain_core_messages.AIMessage.html) from `@langchain/core/messages`
*   [HumanMessage](https://v02.api.js.langchain.com/classes/langchain_core_messages.HumanMessage.html) from `@langchain/core/messages`

With plugins[​](#with-plugins "Direct link to With plugins")
------------------------------------------------------------

This feature supports calling tools like a search engine to get additional data that can assist the model.

    import { ChatMinimax } from "@langchain/community/chat_models/minimax";import { HumanMessage } from "@langchain/core/messages";const model = new ChatMinimax({  model: "abab5.5-chat",  botSetting: [    {      bot_name: "MM Assistant",      content: "MM Assistant is an AI Assistant developed by minimax.",    },  ],}).bind({  plugins: ["plugin_web_search"],});const result = await model.invoke([  new HumanMessage({    content: " What is the weather like in NewYork tomorrow?",  }),]);console.log(result);/*AIMessage {  lc_serializable: true,  lc_kwargs: {    content: 'The weather in Shanghai tomorrow is expected to be hot. Please note that this is just a forecast and the actual weather conditions may vary.',    additional_kwargs: { function_call: undefined }  },  lc_namespace: [ 'langchain', 'schema' ],  content: 'The weather in Shanghai tomorrow is expected to be hot. Please note that this is just a forecast and the actual weather conditions may vary.',  name: undefined,  additional_kwargs: { function_call: undefined }}*/

#### API Reference:

*   [ChatMinimax](https://v02.api.js.langchain.com/classes/langchain_community_chat_models_minimax.ChatMinimax.html) from `@langchain/community/chat_models/minimax`
*   [HumanMessage](https://v02.api.js.langchain.com/classes/langchain_core_messages.HumanMessage.html) from `@langchain/core/messages`

* * *

#### Was this page helpful?

  

#### You can leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

Llama CPP

](/v0.2/docs/integrations/chat/llama_cpp)[

Next

Mistral AI

](/v0.2/docs/integrations/chat/mistral)

*   [Setup](#setup)
*   [Basic usage](#basic-usage)
*   [Chain model calls](#chain-model-calls)
*   [With function calls](#with-function-calls)
*   [Functions with Zod](#functions-with-zod)
*   [With glyph](#with-glyph)
*   [With sample messages](#with-sample-messages)
*   [With plugins](#with-plugins)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.