-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
feat(community): Add new LLM provider Novita AI #7231
Changes from 3 commits
3ea6406
79dc0d2
30c9dee
5f7d753
87dfdad
f6d6a79
ffcf66e
deb915a
a03fcd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "raw", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"sidebar_label: Novita\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# ChatNovita\n", | ||
"\n", | ||
"[Novita AI](https://novita.ai/model-api/product/llm-api?utm_source=github_langchain&utm_medium=github_readme&utm_campaign=link): The most cost-effective, stable, and scalable inference platform — delivering production-ready performance at a lower cost.\n", | ||
"\n", | ||
"This guide will help you getting started with `ChatNovitaAI` [chat models](/docs/concepts/chat_models). For detailed documentation of all `ChatNovitaAI` features and configurations head to the [API reference](https://novita.ai/docs/model-api/reference/llm/llm.html?utm_source=github_langchain&utm_medium=github_readme&utm_campaign=link)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Overview\n", | ||
"\n", | ||
"### Model features\n", | ||
"| [Tool calling](../../how_to/tool_calling.ipynb) | [Structured output](../../how_to/structured_output.ipynb) | JSON mode | [Image input](../../how_to/multimodal_inputs.ipynb) | Audio input | Video input | [Token-level streaming](../../how_to/chat_streaming.ipynb) | Native async | [Token usage](../../how_to/chat_token_usage_tracking.ipynb) | [Logprobs](../../how_to/logprobs.ipynb) |\n", | ||
"| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |\n", | ||
"| ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ |" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Setup\n", | ||
"\n", | ||
"To access Novita AI models you'll need to create a Novita account and get an API key.\n", | ||
"\n", | ||
"### Credentials\n", | ||
"\n", | ||
"Head to [this page](https://novita.ai/settings#key-management?utm_source=github_langchain&utm_medium=github_readme&utm_campaign=link) to sign up to Novita AI and generate an API key. Once you've done this set the NOVITA_API_KEY environment variable:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "shellscript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"export NOVITA_API_KEY=\"your-api-key\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Installation\n", | ||
"\n", | ||
"The LangChain Novita integration lives in the `@langchain-community` package:\n", | ||
"\n", | ||
"```{=mdx}\n", | ||
"import IntegrationInstallTooltip from \"@mdx_components/integration_install_tooltip.mdx\";\n", | ||
"import Npm2Yarn from \"@theme/Npm2Yarn\";\n", | ||
"\n", | ||
"<IntegrationInstallTooltip></IntegrationInstallTooltip>\n", | ||
"\n", | ||
"<Npm2Yarn>\n", | ||
" @langchain/community @langchain/core\n", | ||
"</Npm2Yarn>\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Instantiation\n", | ||
"\n", | ||
"Now we can instantiate our model object and generate chat completions:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "javascript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import { ChatNovitaAI } from \"../novita.js\";\n", | ||
"\n", | ||
"const llm = new ChatNovitaAI({\n", | ||
" model: \"gryphe/mythomax-l2-13b\",\n", | ||
" temperature: 0,\n", | ||
" // other params...\n", | ||
"})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Invocation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "javascript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"const aiMsg = await llm.invoke([\n", | ||
" [\n", | ||
" \"system\",\n", | ||
" \"You are a helpful assistant that translates English to French. Translate the user sentence.\",\n", | ||
" ],\n", | ||
" [\"human\", \"I love programming.\"],\n", | ||
"])\n", | ||
"aiMsg" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "javascript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"console.log(aiMsg.content)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Chaining\n", | ||
"\n", | ||
"We can [chain](../../how_to/sequence.ipynb) our model with a prompt template like so:" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "javascript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import { ChatPromptTemplate } from \"@langchain/core/prompts\"\n", | ||
"\n", | ||
"const prompt = ChatPromptTemplate.fromMessages(\n", | ||
" [\n", | ||
" [\n", | ||
" \"system\",\n", | ||
" \"You are a helpful assistant that translates {input_language} to {output_language}.\",\n", | ||
" ],\n", | ||
" [\"human\", \"{input}\"],\n", | ||
" ]\n", | ||
")\n", | ||
"\n", | ||
"const chain = prompt.pipe(llm);\n", | ||
"await chain.invoke(\n", | ||
" {\n", | ||
" input_language: \"English\",\n", | ||
" output_language: \"German\",\n", | ||
" input: \"I love programming.\",\n", | ||
" }\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## API reference\n", | ||
"\n", | ||
"For detailed documentation of Novita AI LLM APIs, head to [Novita AI API reference](https://novita.ai/docs/model-api/reference/llm/llm.html?utm_source=github_langchain&utm_medium=github_readme&utm_campaign=link)\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We prefer having this link to the LangChain API refs, but this is ok too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm truly sorry but I don't have more time to write a Novita API ref for LangChain 😭. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, no this will be autogenerated don't worry. |
||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
sidebar_label: Novita | ||
--- | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't have this and the notebook above - the notebook compiles into an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed this file |
||
# ChatNovita | ||
|
||
[Novita AI](https://novita.ai/model-api/product/llm-api?utm_source=github_langchain&utm_medium=github_readme&utm_campaign=link) is the most cost-effective, stable, and scalable inference platform — delivering production-ready performance at a lower cost. | ||
|
||
This guide will help you get started with `ChatNovitaAI` [chat models](/docs/concepts/chat_models). For detailed documentation of all `ChatNovitaAI` features and configurations head to the [API reference](https://novita.ai/docs/model-api/reference/llm/llm.html?utm_source=github_langchain&utm_medium=github_readme&utm_campaign=link). | ||
|
||
## Setup | ||
|
||
To access Novita AI models you'll need to create a Novita account and get an API key. | ||
|
||
### Credentials | ||
|
||
Head to [this page](https://novita.ai/settings#key-management?utm_source=github_langchain&utm_medium=github_readme&utm_campaign=link) to sign up to Novita AI and generate an API key. Once you've done this set the NOVITA_API_KEY environment variable: | ||
|
||
```bash | ||
export NOVITA_API_KEY="your-api-key" | ||
``` | ||
|
||
### Installation | ||
|
||
The LangChain Novita integration lives in the `@langchain-community` package: | ||
|
||
import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx"; | ||
|
||
<IntegrationInstallTooltip></IntegrationInstallTooltip> | ||
|
||
```bash npm2yarn | ||
npm install @langchain/community @langchain/core | ||
``` | ||
|
||
## Basic usage | ||
|
||
import Novita from "@examples/models/chat/integration_novita.ts"; | ||
|
||
<CodeBlock language="typescript">{Novita}</CodeBlock> | ||
|
||
## Chain model calls | ||
|
||
import NovitaChain from "@examples/models/chat/integration_novita_chain.ts"; | ||
|
||
<CodeBlock language="typescript">{NovitaChain}</CodeBlock> | ||
|
||
## API reference | ||
|
||
For detailed documentation of Novita AI LLM APIs, head to [Novita AI API reference](https://novita.ai/docs/model-api/reference/llm/llm.html?utm_source=github_langchain&utm_medium=github_readme&utm_campaign=link) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove, see above. The notebook is all you need |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ChatNovita } from "@langchain/community/chat_models/novita"; | ||
import { HumanMessage } from "@langchain/core/messages"; | ||
|
||
// Use gryphe/mythomax-l2-13b | ||
const chat = new ChatNovita({ | ||
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.NOVITA_API_KEY | ||
model: "gryphe/mythomax-l2-13b", // Check available models at https://novita.ai/llm-api | ||
temperature: 0.3, | ||
}); | ||
|
||
const messages = [new HumanMessage("Hello")]; | ||
|
||
const res = await chat.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 chat.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.", | ||
} | ||
*/ |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove, see above. The notebook is all you need |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ChatNovita } from "@langchain/community/chat_models/novita"; | ||
import { LLMChain } from "langchain/chains"; | ||
import { PromptTemplate } from "@langchain/core/prompts"; | ||
|
||
|
||
const chat = new ChatNovita({ | ||
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.NOVITA_API_KEY | ||
model: "gryphe/mythomax-l2-13b", // Check available models at https://novita.ai/llm-api | ||
temperature: 0.3, | ||
}); | ||
|
||
const prompt = PromptTemplate.fromTemplate( | ||
"What is a good name for a company that makes {product}?" | ||
); | ||
const chain = new LLMChain({ llm: chat, prompt }); | ||
|
||
const response = await chain.invoke({ product: "colorful socks" }); | ||
|
||
console.log({ response }); | ||
|
||
/* | ||
{ | ||
text: `I'm not sure what you mean by "colorful socks" but here are some ideas:\n` + | ||
'\n' + | ||
'- Sock-it to me!\n' + | ||
'- Socks Away\n' + | ||
'- Fancy Footwear' | ||
} | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ export const config = { | |
"llms/writer": "llms/writer", | ||
"llms/yandex": "llms/yandex", | ||
"llms/layerup_security": "llms/layerup_security", | ||
"llms/novita": "llms/novita", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
// vectorstores | ||
"vectorstores/analyticdb": "vectorstores/analyticdb", | ||
"vectorstores/astradb": "vectorstores/astradb", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
"author": "LangChain", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@langchain/openai": ">=0.2.0 <0.4.0", | ||
"@langchain/openai": "workspace:*", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert |
||
"binary-extensions": "^2.2.0", | ||
"expr-eval": "^2.0.2", | ||
"flat": "^5.0.2", | ||
|
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.
I believe these need to be absolute paths rather than relative
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.
Fixed