-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli[minor]: Add base chat model integration template (#6276)
- Loading branch information
1 parent
7ab3367
commit 1218bf8
Showing
1 changed file
with
267 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "raw", | ||
"id": "afaf8039", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"sidebar_label: __ModuleName__\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e49f1e0d", | ||
"metadata": {}, | ||
"source": [ | ||
"# Chat__ModuleName__\n", | ||
"\n", | ||
"- TODO: Make sure API reference link is correct.\n", | ||
"\n", | ||
"This will help you getting started with __ModuleName__ [chat models](/docs/concepts/#chat-models). For detailed documentation of all Chat__ModuleName__ features and configurations head to the [API reference](https://api.js.langchain.com/classes/langchain___package_name__.__ModuleName__.html).\n", | ||
"\n", | ||
"- TODO: Add any other relevant links, like information about models, prices, context windows, etc. See https://js.langchain.com/v0.2/docs/integrations/chat/openai/ for an example.\n", | ||
"\n", | ||
"## Overview\n", | ||
"### Integration details\n", | ||
"\n", | ||
"- TODO: Fill in table features.\n", | ||
"- TODO: Remove PY support link if not relevant, otherwise ensure link is correct.\n", | ||
"- TODO: Make sure API reference links are correct.\n", | ||
"\n", | ||
"| Class | Package | Local | Serializable | [PY support](https:/py.langchain.com/v0.2/docs/integrations/chat/__package_name_short_snake__) | Package downloads | Package latest |\n", | ||
"| :--- | :--- | :---: | :---: | :---: | :---: | :---: |\n", | ||
"| [Chat__ModuleName__](https://api.js.langchain.com/classes/langchain___PackageName__.__ModuleName__.html) | [__package_name__](https://api.js.langchain.com/modules/__package_snake_name__.html) | ✅/❌ | beta/❌ | ✅/❌ | ![NPM - Downloads](https://img.shields.io/npm/dm/__package_name__?style=flat-square&label=%20) | ![NPM - Version](https://img.shields.io/npm/v/__package_name__?style=flat-square&label=%20) |\n", | ||
"\n", | ||
"### Model features\n", | ||
"| [Tool calling](/docs/how_to/tool_calling) | [Structured output](/docs/how_to/structured_output/) | JSON mode | [Image input](/docs/how_to/multimodal_inputs/) | Audio input | Video input | [Token-level streaming](/docs/how_to/chat_streaming/) | Native async | [Token usage](/docs/how_to/chat_token_usage_tracking/) | [Logprobs](/docs/how_to/logprobs/) |\n", | ||
"| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |\n", | ||
"| ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | \n", | ||
"\n", | ||
"## Setup\n", | ||
"\n", | ||
"- TODO: Update with relevant info.\n", | ||
"\n", | ||
"To access __ModuleName__ models you'll need to create a/an __ModuleName__ account, get an API key, and install the `__package_name__` integration package.\n", | ||
"\n", | ||
"### Credentials\n", | ||
"\n", | ||
"- TODO: Update with relevant info.\n", | ||
"\n", | ||
"Head to (TODO: link) to sign up to __ModuleName__ and generate an API key. Once you've done this set the __MODULE_NAME___API_KEY environment variable:\n", | ||
"\n", | ||
"```{=mdx}\n", | ||
"\n", | ||
"```bash\n", | ||
"export __MODULE_NAME___API_KEY=\"your-api-key\"\n", | ||
"```\n", | ||
"\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "72ee0c4b-9764-423a-9dbf-95129e185210", | ||
"metadata": {}, | ||
"source": [ | ||
"If you want to get automated tracing of your model calls you can also set your [LangSmith](https://docs.smith.langchain.com/) API key by uncommenting below:\n", | ||
"\n", | ||
"```{=mdx}\n", | ||
"\n", | ||
"```bash\n", | ||
"# export LANGCHAIN_TRACING_V2=\"true\"\n", | ||
"# export LANGCHAIN_API_KEY=\"your-api-key\"\n", | ||
"```\n", | ||
"\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0730d6a1-c893-4840-9817-5e5251676d5d", | ||
"metadata": {}, | ||
"source": [ | ||
"### Installation\n", | ||
"\n", | ||
"The LangChain __ModuleName__ integration lives in the `__package_name__` package:\n", | ||
"\n", | ||
"```{=mdx}\n", | ||
"\n", | ||
"```bash npm2yarn\n", | ||
"npm i __package_name__\n", | ||
"```\n", | ||
"\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a38cde65-254d-4219-a441-068766c0d4b5", | ||
"metadata": {}, | ||
"source": [ | ||
"## Instantiation\n", | ||
"\n", | ||
"Now we can instantiate our model object and generate chat completions:\n", | ||
"\n", | ||
"- TODO: Update model instantiation with relevant params." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cb09c344-1836-4e0c-acf8-11d13ac1dbae", | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "typescript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import { Chat__ModuleName__ } from \"__module_name__\" \n", | ||
"\n", | ||
"const llm = new Chat__ModuleName__({\n", | ||
" model: \"model-name\",\n", | ||
" temperature: 0,\n", | ||
" max_tokens: undefined,\n", | ||
" timeout: undefined,\n", | ||
" maxRetries: 2,\n", | ||
" // other params...\n", | ||
"})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "2b4f3e15", | ||
"metadata": {}, | ||
"source": [ | ||
"## Invocation\n", | ||
"\n", | ||
"- TODO: Run cells so output can be seen." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "62e0dbc3", | ||
"metadata": { | ||
"tags": [], | ||
"vscode": { | ||
"languageId": "typescript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"const messages = [\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", | ||
"const aiMsg = await llm.invoke(messages)\n", | ||
"aiMsg" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d86145b3-bfef-46e8-b227-4dda5c9c2705", | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "typescript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"console.log(aiMsg.content)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "18e2bfc0-7e78-4528-a73f-499ac150dca8", | ||
"metadata": {}, | ||
"source": [ | ||
"## Chaining\n", | ||
"\n", | ||
"We can [chain](/docs/how_to/sequence/) our model with a prompt template like so:\n", | ||
"\n", | ||
"- TODO: Run cells so output can be seen." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e197d1d7-a070-4c96-9f8a-a0e86d046e0b", | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "typescript" | ||
} | ||
}, | ||
"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", | ||
"id": "d1ee55bc-ffc8-4cfa-801c-993953a08cfd", | ||
"metadata": {}, | ||
"source": [ | ||
"## TODO: Any functionality specific to this model provider\n", | ||
"\n", | ||
"E.g. creating/using finetuned models via this provider. Delete if not relevant." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3", | ||
"metadata": {}, | ||
"source": [ | ||
"## API reference\n", | ||
"\n", | ||
"For detailed documentation of all Chat__ModuleName__ features and configurations head to the API reference: https://api.js.langchain.com/classes/langchain___package_name__.__ModuleName__.html" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |