Skip to content

Commit

Permalink
Merge branch 'langchain-ai:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dl102306 authored Aug 1, 2024
2 parents b0dc620 + fa376c6 commit ee21a11
Show file tree
Hide file tree
Showing 13 changed files with 1,068 additions and 226 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/validate_new_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,23 @@ jobs:
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- name: Validate new notebooks
- name: Check for new or modified notebooks
id: check_notebooks
run: |
new_notebooks=$(echo '${{ steps.changed-files.outputs.added_files }}' | tr ' ' '\n' | grep '\.ipynb$' || true)
echo "New notebooks: $new_notebooks"
if [ -n "$new_notebooks" ]; then
for notebook in $new_notebooks; do
notebooks=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ' ' '\n' | grep '\.ipynb$' || true)
echo "Affected notebooks: $notebooks"
echo "has_affected_notebooks=$([ -n "$notebooks" ] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
- name: Build examples
if: steps.check_notebooks.outputs.has_affected_notebooks == 'true'
run: yarn turbo:command build --filter=examples
- name: Validate affected notebooks
if: steps.check_notebooks.outputs.has_affected_notebooks == 'true'
run: |
notebooks=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ' ' '\n' | grep '\.ipynb$' || true)
if [ -n "$notebooks" ]; then
for notebook in $notebooks; do
yarn notebook:validate "$notebook"
done
else
echo "No new notebooks to validate."
echo "No notebooks to validate."
fi
44 changes: 23 additions & 21 deletions docs/core_docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,6 @@ yarn-error.log*

/.quarto/
# AUTO_GENERATED_DOCS
docs/tutorials/rag.md
docs/tutorials/rag.mdx
docs/tutorials/query_analysis.md
docs/tutorials/query_analysis.mdx
docs/tutorials/qa_chat_history.md
docs/tutorials/qa_chat_history.mdx
docs/tutorials/pdf_qa.md
docs/tutorials/pdf_qa.mdx
docs/tutorials/local_rag.md
docs/tutorials/local_rag.mdx
docs/tutorials/llm_chain.md
docs/tutorials/llm_chain.mdx
docs/tutorials/graph.md
docs/tutorials/graph.mdx
docs/tutorials/extraction.md
docs/tutorials/extraction.mdx
docs/tutorials/classification.md
docs/tutorials/classification.mdx
docs/tutorials/chatbot.md
docs/tutorials/chatbot.mdx
docs/how_to/trim_messages.md
docs/how_to/trim_messages.mdx
docs/how_to/tools_prompting.md
Expand Down Expand Up @@ -208,5 +188,27 @@ docs/how_to/assign.md
docs/how_to/assign.mdx
docs/how_to/agent_executor.md
docs/how_to/agent_executor.mdx
docs/tutorials/rag.md
docs/tutorials/rag.mdx
docs/tutorials/query_analysis.md
docs/tutorials/query_analysis.mdx
docs/tutorials/qa_chat_history.md
docs/tutorials/qa_chat_history.mdx
docs/tutorials/pdf_qa.md
docs/tutorials/pdf_qa.mdx
docs/tutorials/local_rag.md
docs/tutorials/local_rag.mdx
docs/tutorials/llm_chain.md
docs/tutorials/llm_chain.mdx
docs/tutorials/graph.md
docs/tutorials/graph.mdx
docs/tutorials/extraction.md
docs/tutorials/extraction.mdx
docs/tutorials/classification.md
docs/tutorials/classification.mdx
docs/tutorials/chatbot.md
docs/tutorials/chatbot.mdx
docs/integrations/llms/mistral.md
docs/integrations/llms/mistral.mdx
docs/integrations/llms/mistral.mdx
docs/integrations/chat/mistral.md
docs/integrations/chat/mistral.mdx
2 changes: 1 addition & 1 deletion docs/core_docs/docs/how_to/callbacks_custom_events.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
":::caution Compatibility\n",
"Dispatching custom callback events requires `@langchain/core>=0.2.16`. See [this guide](/docs/how_to/installation/#installing-integration-packages) for some considerations to take when upgrading `@langchain/core`.\n",
"\n",
"The default entrypoint below triggers an import and initialization of [`async_hooks`](https://nodejs.org/api/async_hooks.html) to enable automatic `RunnableConfig` passing, which is not supported in all environments. If you see import issues, you must import from `@langchain/callbacks/dispatch/web` and propagate the `RunnableConfig` object manually (see example below).\n",
"The default entrypoint below triggers an import and initialization of [`async_hooks`](https://nodejs.org/api/async_hooks.html) to enable automatic `RunnableConfig` passing, which is not supported in all environments. If you see import issues, you must import from `@langchain/core/callbacks/dispatch/web` and propagate the `RunnableConfig` object manually (see example below).\n",
":::\n",
"```"
]
Expand Down
280 changes: 280 additions & 0 deletions docs/core_docs/docs/integrations/chat/fireworks.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
{
"cells": [
{
"cell_type": "raw",
"id": "afaf8039",
"metadata": {},
"source": [
"---\n",
"sidebar_label: ChatFireworks\n",
"---"
]
},
{
"cell_type": "markdown",
"id": "e49f1e0d",
"metadata": {},
"source": [
"# ChatFireworks\n",
"\n",
"This will help you getting started with `ChatFireworks` [chat models](/docs/concepts/#chat-models). For detailed documentation of all `ChatFireworks` features and configurations head to the [API reference](https://api.js.langchain.com/classes/langchain_community_chat_models_fireworks.ChatFireworks.html).\n",
"\n",
"## Overview\n",
"### Integration details\n",
"\n",
"| Class | Package | Local | Serializable | [PY support](https:/python.langchain.com/v0.2/docs/integrations/chat/fireworks) | Package downloads | Package latest |\n",
"| :--- | :--- | :---: | :---: | :---: | :---: | :---: |\n",
"| [ChatFireworks](https://api.js.langchain.com/classes/langchain_community_chat_models_fireworks.ChatFireworks.html) | [@langchain/community](https://api.js.langchain.com/modules/langchain_community_chat_models_fireworks.html) | ❌ | ✅ | ✅ | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/community?style=flat-square&label=%20) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?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/) | [Token usage](/docs/how_to/chat_token_usage_tracking/) | [Logprobs](/docs/how_to/logprobs/) |\n",
"| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |\n",
"| ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | \n",
"\n",
"## Setup\n",
"\n",
"To access `ChatFireworks` models you'll need to create a Fireworks account, get an API key, and install the `@langchain/community` integration package.\n",
"\n",
"### Credentials\n",
"\n",
"Head to [the Fireworks website](https://fireworks.ai/login) to sign up to Fireworks and generate an API key. Once you've done this set the `FIREWORKS_API_KEY` environment variable:\n",
"\n",
"```bash\n",
"export FIREWORKS_API_KEY=\"your-api-key\"\n",
"```\n",
"\n",
"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",
"```bash\n",
"# export LANGCHAIN_TRACING_V2=\"true\"\n",
"# export LANGCHAIN_API_KEY=\"your-api-key\"\n",
"```\n",
"\n",
"### Installation\n",
"\n",
"The LangChain `ChatFireworks` integration lives in the `@langchain/community` package:\n",
"\n",
"```{=mdx}\n",
"\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\n",
"</Npm2Yarn>\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:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "cb09c344-1836-4e0c-acf8-11d13ac1dbae",
"metadata": {},
"outputs": [],
"source": [
"import { ChatFireworks } from \"@langchain/community/chat_models/fireworks\" \n",
"\n",
"const llm = new ChatFireworks({\n",
" model: \"accounts/fireworks/models/llama-v3p1-70b-instruct\",\n",
" temperature: 0,\n",
" maxTokens: undefined,\n",
" timeout: undefined,\n",
" maxRetries: 2,\n",
" // other params...\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "2b4f3e15",
"metadata": {},
"source": [
"## Invocation"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "62e0dbc3",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"AIMessage {\n",
" \"id\": \"chatcmpl-9rBYHbb6QYRrKyr2tMhO9pH4AYXR4\",\n",
" \"content\": \"J'adore la programmation.\",\n",
" \"additional_kwargs\": {},\n",
" \"response_metadata\": {\n",
" \"tokenUsage\": {\n",
" \"completionTokens\": 8,\n",
" \"promptTokens\": 31,\n",
" \"totalTokens\": 39\n",
" },\n",
" \"finish_reason\": \"stop\"\n",
" },\n",
" \"tool_calls\": [],\n",
" \"invalid_tool_calls\": [],\n",
" \"usage_metadata\": {\n",
" \"input_tokens\": 31,\n",
" \"output_tokens\": 8,\n",
" \"total_tokens\": 39\n",
" }\n",
"}\n"
]
}
],
"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": 3,
"id": "d86145b3-bfef-46e8-b227-4dda5c9c2705",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"J'adore la programmation.\n"
]
}
],
"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:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e197d1d7-a070-4c96-9f8a-a0e86d046e0b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"AIMessage {\n",
" \"id\": \"chatcmpl-9rBYM3KSIhHOuTXpBvA5oFyk8RSaN\",\n",
" \"content\": \"Ich liebe das Programmieren.\",\n",
" \"additional_kwargs\": {},\n",
" \"response_metadata\": {\n",
" \"tokenUsage\": {\n",
" \"completionTokens\": 6,\n",
" \"promptTokens\": 26,\n",
" \"totalTokens\": 32\n",
" },\n",
" \"finish_reason\": \"stop\"\n",
" },\n",
" \"tool_calls\": [],\n",
" \"invalid_tool_calls\": [],\n",
" \"usage_metadata\": {\n",
" \"input_tokens\": 26,\n",
" \"output_tokens\": 6,\n",
" \"total_tokens\": 32\n",
" }\n",
"}\n"
]
}
],
"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": [
"Behind the scenes, Fireworks AI uses the OpenAI SDK and OpenAI compatible API, with some caveats:\n",
"\n",
"- Certain properties are not supported by the Fireworks API, see [here](https://readme.fireworks.ai/docs/openai-compatibility#api-compatibility).\n",
"- Generation using multiple prompts is not supported."
]
},
{
"cell_type": "markdown",
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3",
"metadata": {},
"source": [
"## API reference\n",
"\n",
"For detailed documentation of all ChatFireworks features and configurations head to the API reference: https://api.js.langchain.com/classes/langchain_community_chat_models_fireworks.ChatFireworks.html"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "TypeScript",
"language": "typescript",
"name": "tslab"
},
"language_info": {
"codemirror_mode": {
"mode": "typescript",
"name": "javascript",
"typescript": true
},
"file_extension": ".ts",
"mimetype": "text/typescript",
"name": "typescript",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit ee21a11

Please sign in to comment.