Skip to content

Commit d456148

Browse files
community[minor]: Add Moonshot chat models integration (#5239)
* Add Moonshot chat models * fix: MOONSHOT_API_KEY needs to be capitalized * feat: remove moonshotApiKey * fix: remove encodeApiKey * docs: complete parameter comment * Format * Lint --------- Co-authored-by: jacoblee93 <[email protected]>
1 parent 0f2be54 commit d456148

File tree

9 files changed

+682
-1
lines changed

9 files changed

+682
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
sidebar_label: Moonshot
3+
---
4+
5+
import CodeBlock from "@theme/CodeBlock";
6+
7+
# ChatMoonshot
8+
9+
LangChain.js supports the Moonshot AI family of models.
10+
11+
https://platform.moonshot.cn/docs/intro
12+
13+
## Setup
14+
15+
You'll need to sign up for an Moonshot API key and set it as an environment variable named `MOONSHOT_API_KEY`
16+
17+
https://platform.moonshot.cn/console
18+
19+
You'll also need to install the following dependencies:
20+
21+
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";
22+
23+
<IntegrationInstallTooltip></IntegrationInstallTooltip>
24+
25+
```bash npm2yarn
26+
npm install @langchain/community
27+
```
28+
29+
## Usage
30+
31+
Here's an example:
32+
33+
import Moonshot from "@examples/models/chat/integration_moonshot.ts";
34+
35+
<CodeBlock language="typescript">{Moonshot}</CodeBlock>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ChatMoonshot } from "@langchain/community/chat_models/moonshot";
2+
import { HumanMessage } from "@langchain/core/messages";
3+
4+
// Default model is moonshot-v1-8k
5+
const moonshotV18K = new ChatMoonshot({
6+
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.MOONSHOT_API_KEY
7+
});
8+
9+
// Use moonshot-v1-128k
10+
const moonshotV1128k = new ChatMoonshot({
11+
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.MOONSHOT_API_KEY
12+
model: "moonshot-v1-128k", // Available models: moonshot-v1-8k, moonshot-v1-32k, moonshot-v1-128k
13+
temperature: 0.3,
14+
});
15+
16+
const messages = [new HumanMessage("Hello")];
17+
18+
const res = await moonshotV18K.invoke(messages);
19+
/*
20+
AIMessage {
21+
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.",
22+
}
23+
*/
24+
25+
const res2 = await moonshotV1128k.invoke(messages);
26+
/*
27+
AIMessage {
28+
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.",
29+
}
30+
*/

libs/langchain-community/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ chat_models/minimax.cjs
530530
chat_models/minimax.js
531531
chat_models/minimax.d.ts
532532
chat_models/minimax.d.cts
533+
chat_models/moonshot.cjs
534+
chat_models/moonshot.js
535+
chat_models/moonshot.d.ts
536+
chat_models/moonshot.d.cts
533537
chat_models/ollama.cjs
534538
chat_models/ollama.js
535539
chat_models/ollama.d.ts

libs/langchain-community/langchain.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export const config = {
168168
"chat_models/iflytek_xinghuo/web": "chat_models/iflytek_xinghuo/web",
169169
"chat_models/llama_cpp": "chat_models/llama_cpp",
170170
"chat_models/minimax": "chat_models/minimax",
171+
"chat_models/moonshot": "chat_models/moonshot",
171172
"chat_models/ollama": "chat_models/ollama",
172173
"chat_models/portkey": "chat_models/portkey",
173174
"chat_models/premai": "chat_models/premai",

libs/langchain-community/package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,15 @@
18851885
"import": "./chat_models/minimax.js",
18861886
"require": "./chat_models/minimax.cjs"
18871887
},
1888+
"./chat_models/moonshot": {
1889+
"types": {
1890+
"import": "./chat_models/moonshot.d.ts",
1891+
"require": "./chat_models/moonshot.d.cts",
1892+
"default": "./chat_models/moonshot.d.ts"
1893+
},
1894+
"import": "./chat_models/moonshot.js",
1895+
"require": "./chat_models/moonshot.cjs"
1896+
},
18881897
"./chat_models/ollama": {
18891898
"types": {
18901899
"import": "./chat_models/ollama.d.ts",
@@ -3420,6 +3429,10 @@
34203429
"chat_models/minimax.js",
34213430
"chat_models/minimax.d.ts",
34223431
"chat_models/minimax.d.cts",
3432+
"chat_models/moonshot.cjs",
3433+
"chat_models/moonshot.js",
3434+
"chat_models/moonshot.d.ts",
3435+
"chat_models/moonshot.d.cts",
34233436
"chat_models/ollama.cjs",
34243437
"chat_models/ollama.js",
34253438
"chat_models/ollama.d.ts",
@@ -3865,4 +3878,4 @@
38653878
"chains/graph_qa/cypher.d.ts",
38663879
"chains/graph_qa/cypher.d.cts"
38673880
]
3868-
}
3881+
}

0 commit comments

Comments
 (0)