-
Notifications
You must be signed in to change notification settings - Fork 2.5k
community[minor]: Add support for Tencent Hunyuan Chat Model and Embeddings #5476
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
69779ad
community: Add support for Tencent Hunyuan chat model and embeddings
TeCHiScy 0fb6332
community[minor]: Add support for Tencent Hunyuan Chat Model and Embe…
TeCHiScy 6b25cf6
community[minor]: Add support for Tencent Hunyuan Chat Model and Embe…
TeCHiScy 40a5c6f
community[minor]: Add support for Tencent Hunyuan Chat Model and Embe…
TeCHiScy abfe33f
community[minor]: Add support for Tencent Hunyuan Chat Model and Embe…
TeCHiScy a78f430
community[minor]: Add support for Tencent Hunyuan Chat Model and Embe…
TeCHiScy c336f22
community[minor]: Add support for Tencent Hunyuan Chat Model and Embe…
TeCHiScy aa1a5fe
Merge branch 'main' of https://github.com/hwchase17/langchainjs into …
jacoblee93 fed173a
Update build, lint, format
jacoblee93 8c8bf31
Type export
jacoblee93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or 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 hidden or 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,41 @@ | ||
--- | ||
sidebar_label: Tencent Hunyuan | ||
--- | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# ChatTencentHunyuan | ||
|
||
LangChain.js supports the Tencent Hunyuan family of models. | ||
|
||
https://cloud.tencent.com/document/product/1729/104753 | ||
|
||
## Setup | ||
|
||
1. Sign up for a Tencent Cloud account [here](https://cloud.tencent.com/register). | ||
2. Create SecretID & SecretKey [here](https://console.cloud.tencent.com/cam/capi). | ||
3. Set SecretID and SecretKey as environment variables named `TENCENT_SECRET_ID` and `TENCENT_SECRET_KEY`, respectively. | ||
|
||
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx"; | ||
|
||
<IntegrationInstallTooltip></IntegrationInstallTooltip> | ||
|
||
```bash npm2yarn | ||
npm install @langchain/community | ||
``` | ||
|
||
If you are using LangChain.js in a browser environment, you'll also need to install the following dependencies: | ||
|
||
```bash npm2yarn | ||
npm install crypto-js | ||
``` | ||
|
||
And then make sure that you import from the `web` as shown below. | ||
|
||
## Usage | ||
|
||
Here's an example: | ||
|
||
import TencentHunyuan from "@examples/models/chat/integration_tencent_hunyuan.ts"; | ||
|
||
<CodeBlock language="typescript">{TencentHunyuan}</CodeBlock> |
38 changes: 38 additions & 0 deletions
38
docs/core_docs/docs/integrations/text_embedding/tencent_hunyuan.mdx
This file contains hidden or 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,38 @@ | ||
--- | ||
sidebar_label: Tencent Hunyuan | ||
--- | ||
|
||
# TencentHunyuan | ||
|
||
The `TencentHunyuanEmbeddings` class uses the Tencent Hunyuan API to generate embeddings for a given text. | ||
|
||
## Setup | ||
|
||
1. Sign up for a Tencent Cloud account [here](https://cloud.tencent.com/register). | ||
2. Create SecretID & SecretKey [here](https://console.cloud.tencent.com/cam/capi). | ||
3. Set SecretID and SecretKey as environment variables named `TENCENT_SECRET_ID` and `TENCENT_SECRET_KEY`, respectively. | ||
|
||
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx"; | ||
|
||
<IntegrationInstallTooltip></IntegrationInstallTooltip> | ||
|
||
```bash npm2yarn | ||
npm install @langchain/community | ||
``` | ||
|
||
If you are using LangChain.js in a browser environment, you'll also need to install the following dependencies: | ||
|
||
```bash npm2yarn | ||
npm install crypto-js | ||
``` | ||
|
||
And then make sure that you import from the `web` as shown below. | ||
|
||
## Usage | ||
|
||
Here's an example: | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
import TencentHunyuan from "@examples/models/embeddings/tencent_hunyuan.ts"; | ||
|
||
<CodeBlock language="typescript">{TencentHunyuan}</CodeBlock> |
111 changes: 111 additions & 0 deletions
111
examples/src/models/chat/integration_tencent_hunyuan.ts
This file contains hidden or 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,111 @@ | ||
// in nodejs environment | ||
import { ChatTencentHunyuan } from "@langchain/community/chat_models/tencent_hunyuan"; | ||
|
||
// in browser environment | ||
// import { ChatTencentHunyuan } from "@langchain/community/chat_models/tencent_hunyuan/web"; | ||
|
||
import { HumanMessage } from "@langchain/core/messages"; | ||
import type { LLMResult } from "@langchain/core/outputs"; | ||
|
||
const messages = [new HumanMessage("Hello")]; | ||
|
||
// Default model is hunyuan-pro | ||
const hunyuanPro = new ChatTencentHunyuan({ | ||
streaming: false, | ||
temperature: 1, | ||
}); | ||
|
||
let res = await hunyuanPro.invoke(messages); | ||
console.log(res); | ||
/* | ||
AIMessage { | ||
content: 'Hello! How can I help you today?Is there anything I can do for you?', | ||
name: undefined, | ||
additional_kwargs: {}, | ||
response_metadata: { | ||
tokenUsage: { totalTokens: 20, promptTokens: 1, completionTokens: 19 } | ||
}, | ||
tool_calls: [], | ||
invalid_tool_calls: [] | ||
} | ||
*/ | ||
|
||
// Use hunyuan-lite | ||
const hunyuanLite = new ChatTencentHunyuan({ | ||
model: "hunyuan-lite", | ||
streaming: false, | ||
}); | ||
|
||
res = await hunyuanLite.invoke(messages); | ||
console.log(res); | ||
/* | ||
AIMessage { | ||
content: '你好!很高兴为你提供服务~有什么我可以帮助你的吗?', | ||
name: undefined, | ||
additional_kwargs: {}, | ||
response_metadata: { | ||
tokenUsage: { totalTokens: 14, promptTokens: 1, completionTokens: 13 } | ||
}, | ||
tool_calls: [], | ||
invalid_tool_calls: [] | ||
} | ||
*/ | ||
|
||
// Use hunyuan-lite with streaming | ||
const hunyuanLiteStream = new ChatTencentHunyuan({ | ||
model: "hunyuan-lite", | ||
streaming: true, | ||
temperature: 1, | ||
}); | ||
|
||
hunyuanLiteStream.invoke(messages, { | ||
callbacks: [ | ||
{ | ||
handleLLMEnd(output: LLMResult) { | ||
console.log(output); | ||
/* | ||
{ | ||
generations: [ | ||
[ | ||
[Object], [Object], | ||
[Object], [Object], | ||
[Object], [Object], | ||
[Object], [Object], | ||
[Object] | ||
] | ||
], | ||
llmOutput: { | ||
tokenUsage: { totalTokens: 9, promptTokens: 1, completionTokens: 8 } | ||
} | ||
} | ||
*/ | ||
}, | ||
handleLLMNewToken(token: string) { | ||
console.log(`token: ${token}`); | ||
/* | ||
token: 你好 | ||
token: ! | ||
token: 很高兴 | ||
token: 能 | ||
token: 为您 | ||
token: 解答 | ||
token: 问题 | ||
token: 和建议 | ||
token: 方案 | ||
token: . | ||
token: 如果您 | ||
token: 有其他 | ||
token: 需要帮助 | ||
token: 的地方 | ||
token: , | ||
token: | ||
token: 随时 | ||
token: 告诉我 | ||
token: 哦 | ||
token: ~ | ||
token: | ||
*/ | ||
}, | ||
}, | ||
], | ||
}); |
This file contains hidden or 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,13 @@ | ||
// in nodejs environment | ||
import { TencentHunyuanEmbeddings } from "@langchain/community/embeddings/tencent_hunyuan"; | ||
|
||
// in browser environment | ||
// import { TencentHunyuanEmbeddings } from "@langchain/community/embeddings/tencent_hunyuan/web"; | ||
|
||
/* Embed queries */ | ||
const embeddings = new TencentHunyuanEmbeddings(); | ||
const res = await embeddings.embedQuery("你好,世界!"); | ||
console.log(res); | ||
/* Embed documents */ | ||
const documentRes = await embeddings.embedDocuments(["你好,世界!", "再见"]); | ||
console.log({ documentRes }); |
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there! 👋 Just wanted to flag that the recent changes in the embeddings directory might impact the project's dependencies. It would be great if the maintainers could review this for any potential changes to peer/dev/hard dependencies. Thanks!