-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
community[major]: DeepInfra llm and chat (#5672)
* Init * fix(type errors) * feat(deepinfra embeddings) * fix(default model) * fix(deepinfra): axios is removed * ref(deepinfra): remove redundant cast * format(deepinfra) * doc(deepinfra) * doc(deepinfra) * Update deepinfra.mdx * Format * feat(deepinfra): implement llm and chat. * ref(deepinfra): lint and prettier * ref(deepinfra): remove console.log * fix(chatdeepinfra): body * fix(import map): deepinfra * fix(gitignore) * revert(.gitignore) * revert(.gitignore) * Adds docs --------- Co-authored-by: Jacob Lee <[email protected]>
- Loading branch information
1 parent
e177b2f
commit de3e618
Showing
13 changed files
with
435 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,25 @@ | ||
--- | ||
sidebar_label: Deep Infra | ||
--- | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# ChatDeepInfra | ||
|
||
LangChain supports chat models hosted by [Deep Infra](https://deepinfra.com/) through the `ChatDeepInfra` wrapper. | ||
First, you'll need to install the `@langchain/community` package: | ||
|
||
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx"; | ||
|
||
<IntegrationInstallTooltip></IntegrationInstallTooltip> | ||
|
||
```bash npm2yarn | ||
npm install @langchain/community | ||
``` | ||
|
||
You'll need to obtain an API key and set it as an environment variable named `DEEPINFRA_API_TOKEN` | ||
(or pass it into the constructor), then call the model as shown below: | ||
|
||
import Example from "@examples/models/chat/integration_deepinfra.ts"; | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> |
This file contains 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,25 @@ | ||
--- | ||
sidebar_label: Deep Infra | ||
--- | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# DeepInfra | ||
|
||
LangChain supports LLMs hosted by [Deep Infra](https://deepinfra.com/) through the `DeepInfra` wrapper. | ||
First, you'll need to install the `@langchain/community` package: | ||
|
||
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx"; | ||
|
||
<IntegrationInstallTooltip></IntegrationInstallTooltip> | ||
|
||
```bash npm2yarn | ||
npm install @langchain/community | ||
``` | ||
|
||
You'll need to obtain an API key and set it as an environment variable named `DEEPINFRA_API_TOKEN` | ||
(or pass it into the constructor), then call the model as shown below: | ||
|
||
import Example from "@examples/models/llm/deepinfra.ts"; | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> |
This file contains 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,17 @@ | ||
import { ChatDeepInfra } from "@langchain/community/chat_models/deepinfra"; | ||
import { HumanMessage } from "@langchain/core/messages"; | ||
|
||
const apiKey = process.env.DEEPINFRA_API_TOKEN; | ||
|
||
const model = "meta-llama/Meta-Llama-3-70B-Instruct"; | ||
|
||
const chat = new ChatDeepInfra({ | ||
model, | ||
apiKey, | ||
}); | ||
|
||
const messages = [new HumanMessage("Hello")]; | ||
|
||
const res = await chat.invoke(messages); | ||
|
||
console.log(res); |
This file contains 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,18 @@ | ||
import { DeepInfraLLM } from "@langchain/community/llms/deepinfra"; | ||
|
||
const apiKey = process.env.DEEPINFRA_API_TOKEN; | ||
const model = "meta-llama/Meta-Llama-3-70B-Instruct"; | ||
|
||
const llm = new DeepInfraLLM({ | ||
temperature: 0.7, | ||
maxTokens: 20, | ||
model, | ||
apiKey, | ||
maxRetries: 5, | ||
}); | ||
|
||
const res = await llm.invoke( | ||
"What is the next step in the process of making a good game?" | ||
); | ||
|
||
console.log({ res }); |
This file contains 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 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 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.