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

community[minor]: Add Moonshot chat models integration #5239

Merged
merged 8 commits into from
May 25, 2024
Merged
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
35 changes: 35 additions & 0 deletions docs/core_docs/docs/integrations/chat/moonshot.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
sidebar_label: Moonshot
---

import CodeBlock from "@theme/CodeBlock";

# ChatMoonshot

LangChain.js supports the Moonshot AI family of models.

https://platform.moonshot.cn/docs/intro

## Setup

You'll need to sign up for an Moonshot API key and set it as an environment variable named `MOONSHOT_API_KEY`

https://platform.moonshot.cn/console

You'll also need to install the following dependencies:

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/community
```

## Usage

Here's an example:

import Moonshot from "@examples/models/chat/integration_moonshot.ts";

<CodeBlock language="typescript">{Moonshot}</CodeBlock>
30 changes: 30 additions & 0 deletions examples/src/models/chat/integration_moonshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ChatMoonshot } from "@langchain/community/chat_models/moonshot";
import { HumanMessage } from "@langchain/core/messages";

// Default model is moonshot-v1-8k
const moonshotV18K = new ChatMoonshot({
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.MOONSHOT_API_KEY
});

// Use moonshot-v1-128k
const moonshotV1128k = new ChatMoonshot({
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.MOONSHOT_API_KEY
model: "moonshot-v1-128k", // Available models: moonshot-v1-8k, moonshot-v1-32k, moonshot-v1-128k
temperature: 0.3,
});

const messages = [new HumanMessage("Hello")];

const res = await moonshotV18K.invoke(messages);
/*
AIMessage {
content: "Hello! How can I help you today? Is there something you would like to talk about or ask about? I'm here to assist you with any questions you may have.",
}
*/

const res2 = await moonshotV1128k.invoke(messages);
/*
AIMessage {
text: "Hello! How can I help you today? Is there something you would like to talk about or ask about? I'm here to assist you with any questions you may have.",
}
*/
4 changes: 4 additions & 0 deletions libs/langchain-community/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ chat_models/minimax.cjs
chat_models/minimax.js
chat_models/minimax.d.ts
chat_models/minimax.d.cts
chat_models/moonshot.cjs
chat_models/moonshot.js
chat_models/moonshot.d.ts
chat_models/moonshot.d.cts
chat_models/ollama.cjs
chat_models/ollama.js
chat_models/ollama.d.ts
Expand Down
1 change: 1 addition & 0 deletions libs/langchain-community/langchain.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export const config = {
"chat_models/iflytek_xinghuo/web": "chat_models/iflytek_xinghuo/web",
"chat_models/llama_cpp": "chat_models/llama_cpp",
"chat_models/minimax": "chat_models/minimax",
"chat_models/moonshot": "chat_models/moonshot",
"chat_models/ollama": "chat_models/ollama",
"chat_models/portkey": "chat_models/portkey",
"chat_models/premai": "chat_models/premai",
Expand Down
15 changes: 14 additions & 1 deletion libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,15 @@
"import": "./chat_models/minimax.js",
"require": "./chat_models/minimax.cjs"
},
"./chat_models/moonshot": {
"types": {
"import": "./chat_models/moonshot.d.ts",
"require": "./chat_models/moonshot.d.cts",
"default": "./chat_models/moonshot.d.ts"
},
"import": "./chat_models/moonshot.js",
"require": "./chat_models/moonshot.cjs"
},
"./chat_models/ollama": {
"types": {
"import": "./chat_models/ollama.d.ts",
Expand Down Expand Up @@ -3420,6 +3429,10 @@
"chat_models/minimax.js",
"chat_models/minimax.d.ts",
"chat_models/minimax.d.cts",
"chat_models/moonshot.cjs",
"chat_models/moonshot.js",
"chat_models/moonshot.d.ts",
"chat_models/moonshot.d.cts",
"chat_models/ollama.cjs",
"chat_models/ollama.js",
"chat_models/ollama.d.ts",
Expand Down Expand Up @@ -3865,4 +3878,4 @@
"chains/graph_qa/cypher.d.ts",
"chains/graph_qa/cypher.d.cts"
]
}
}
Loading
Loading