Skip to content

Commit

Permalink
Merge branch 'main' into fix/ibm_implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipZmijewski committed Nov 27, 2024
2 parents 6aa808e + 1a98ecd commit 69f9824
Show file tree
Hide file tree
Showing 101 changed files with 6,097 additions and 866 deletions.
88 changes: 47 additions & 41 deletions docs/core_docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,28 @@ docs/how_to/agent_executor.md
docs/how_to/agent_executor.mdx
docs/concepts/t.md
docs/concepts/t.mdx
docs/troubleshooting/errors/INVALID_TOOL_RESULTS.md
docs/troubleshooting/errors/INVALID_TOOL_RESULTS.mdx
docs/versions/migrating_memory/conversation_summary_memory.md
docs/versions/migrating_memory/conversation_summary_memory.mdx
docs/versions/migrating_memory/conversation_buffer_window_memory.md
docs/versions/migrating_memory/conversation_buffer_window_memory.mdx
docs/versions/migrating_memory/chat_history.md
docs/versions/migrating_memory/chat_history.mdx
docs/troubleshooting/errors/INVALID_TOOL_RESULTS.md
docs/troubleshooting/errors/INVALID_TOOL_RESULTS.mdx
docs/integrations/tools/tavily_search.md
docs/integrations/tools/tavily_search.mdx
docs/integrations/tools/serpapi.md
docs/integrations/tools/serpapi.mdx
docs/integrations/tools/exa_search.md
docs/integrations/tools/exa_search.mdx
docs/integrations/tools/duckduckgo_search.md
docs/integrations/tools/duckduckgo_search.mdx
docs/integrations/toolkits/vectorstore.md
docs/integrations/toolkits/vectorstore.mdx
docs/integrations/toolkits/sql.md
docs/integrations/toolkits/sql.mdx
docs/integrations/toolkits/openapi.md
docs/integrations/toolkits/openapi.mdx
docs/integrations/vectorstores/weaviate.md
docs/integrations/vectorstores/weaviate.mdx
docs/integrations/vectorstores/upstash.md
Expand All @@ -252,22 +266,24 @@ docs/integrations/vectorstores/elasticsearch.md
docs/integrations/vectorstores/elasticsearch.mdx
docs/integrations/vectorstores/chroma.md
docs/integrations/vectorstores/chroma.mdx
docs/integrations/tools/tavily_search.md
docs/integrations/tools/tavily_search.mdx
docs/integrations/tools/serpapi.md
docs/integrations/tools/serpapi.mdx
docs/integrations/tools/exa_search.md
docs/integrations/tools/exa_search.mdx
docs/integrations/tools/duckduckgo_search.md
docs/integrations/tools/duckduckgo_search.mdx
docs/integrations/toolkits/vectorstore.md
docs/integrations/toolkits/vectorstore.mdx
docs/integrations/toolkits/sql.md
docs/integrations/toolkits/sql.mdx
docs/integrations/toolkits/openapi.md
docs/integrations/toolkits/openapi.mdx
docs/integrations/stores/in_memory.md
docs/integrations/stores/in_memory.mdx
docs/integrations/stores/file_system.md
docs/integrations/stores/file_system.mdx
docs/integrations/retrievers/tavily.md
docs/integrations/retrievers/tavily.mdx
docs/integrations/retrievers/kendra-retriever.md
docs/integrations/retrievers/kendra-retriever.mdx
docs/integrations/retrievers/exa.md
docs/integrations/retrievers/exa.mdx
docs/integrations/retrievers/bm25.md
docs/integrations/retrievers/bm25.mdx
docs/integrations/retrievers/bedrock-knowledge-bases.md
docs/integrations/retrievers/bedrock-knowledge-bases.mdx
docs/integrations/text_embedding/togetherai.md
docs/integrations/text_embedding/togetherai.mdx
docs/integrations/text_embedding/pinecone.md
docs/integrations/text_embedding/pinecone.mdx
docs/integrations/text_embedding/openai.md
docs/integrations/text_embedding/openai.mdx
docs/integrations/text_embedding/ollama.md
Expand All @@ -290,20 +306,6 @@ docs/integrations/text_embedding/bedrock.md
docs/integrations/text_embedding/bedrock.mdx
docs/integrations/text_embedding/azure_openai.md
docs/integrations/text_embedding/azure_openai.mdx
docs/integrations/stores/in_memory.md
docs/integrations/stores/in_memory.mdx
docs/integrations/stores/file_system.md
docs/integrations/stores/file_system.mdx
docs/integrations/retrievers/tavily.md
docs/integrations/retrievers/tavily.mdx
docs/integrations/retrievers/kendra-retriever.md
docs/integrations/retrievers/kendra-retriever.mdx
docs/integrations/retrievers/exa.md
docs/integrations/retrievers/exa.mdx
docs/integrations/retrievers/bm25.md
docs/integrations/retrievers/bm25.mdx
docs/integrations/retrievers/bedrock-knowledge-bases.md
docs/integrations/retrievers/bedrock-knowledge-bases.mdx
docs/integrations/llms/together.md
docs/integrations/llms/together.mdx
docs/integrations/llms/openai.md
Expand All @@ -328,6 +330,10 @@ docs/integrations/llms/azure.md
docs/integrations/llms/azure.mdx
docs/integrations/llms/arcjet.md
docs/integrations/llms/arcjet.mdx
docs/integrations/document_compressors/ibm.md
docs/integrations/document_compressors/ibm.mdx
docs/integrations/chat/xai.md
docs/integrations/chat/xai.mdx
docs/integrations/chat/togetherai.md
docs/integrations/chat/togetherai.mdx
docs/integrations/chat/openai.md
Expand Down Expand Up @@ -376,6 +382,16 @@ docs/integrations/retrievers/self_query/hnswlib.md
docs/integrations/retrievers/self_query/hnswlib.mdx
docs/integrations/retrievers/self_query/chroma.md
docs/integrations/retrievers/self_query/chroma.mdx
docs/integrations/document_loaders/file_loaders/unstructured.md
docs/integrations/document_loaders/file_loaders/unstructured.mdx
docs/integrations/document_loaders/file_loaders/text.md
docs/integrations/document_loaders/file_loaders/text.mdx
docs/integrations/document_loaders/file_loaders/pdf.md
docs/integrations/document_loaders/file_loaders/pdf.mdx
docs/integrations/document_loaders/file_loaders/directory.md
docs/integrations/document_loaders/file_loaders/directory.mdx
docs/integrations/document_loaders/file_loaders/csv.md
docs/integrations/document_loaders/file_loaders/csv.mdx
docs/integrations/document_loaders/web_loaders/web_puppeteer.md
docs/integrations/document_loaders/web_loaders/web_puppeteer.mdx
docs/integrations/document_loaders/web_loaders/web_cheerio.md
Expand All @@ -387,14 +403,4 @@ docs/integrations/document_loaders/web_loaders/pdf.mdx
docs/integrations/document_loaders/web_loaders/langsmith.md
docs/integrations/document_loaders/web_loaders/langsmith.mdx
docs/integrations/document_loaders/web_loaders/firecrawl.md
docs/integrations/document_loaders/web_loaders/firecrawl.mdx
docs/integrations/document_loaders/file_loaders/unstructured.md
docs/integrations/document_loaders/file_loaders/unstructured.mdx
docs/integrations/document_loaders/file_loaders/text.md
docs/integrations/document_loaders/file_loaders/text.mdx
docs/integrations/document_loaders/file_loaders/pdf.md
docs/integrations/document_loaders/file_loaders/pdf.mdx
docs/integrations/document_loaders/file_loaders/directory.md
docs/integrations/document_loaders/file_loaders/directory.mdx
docs/integrations/document_loaders/file_loaders/csv.md
docs/integrations/document_loaders/file_loaders/csv.mdx
docs/integrations/document_loaders/web_loaders/firecrawl.mdx
1 change: 1 addition & 0 deletions docs/core_docs/docs/concepts/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The conceptual guide does not cover step-by-step instructions or specific implem
- **[Memory](https://langchain-ai.github.io/langgraphjs/concepts/memory/)**: Information about a conversation that is persisted so that it can be used in future conversations.
- **[Multimodality](/docs/concepts/multimodality)**: The ability to work with data that comes in different forms, such as text, audio, images, and video.
- **[Runnable interface](/docs/concepts/runnables)**: The base abstraction that many LangChain components and the LangChain Expression Language are built on.
- **[Streaming](/docs/concepts/streaming)**: LangChain streaming APIs for surfacing results as they are generated.
- **[LangChain Expression Language (LCEL)](/docs/concepts/lcel)**: A syntax for orchestrating LangChain components. Most useful for simpler applications.
- **[Document loaders](/docs/concepts/document_loaders)**: Load a source as a list of documents.
- **[Retrieval](/docs/concepts/retrieval)**: Information retrieval systems can retrieve structured or unstructured data from a datasource in response to a query.
Expand Down
117 changes: 114 additions & 3 deletions docs/core_docs/docs/integrations/chat/mistral.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"\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",
"\n",
"## Setup\n",
"\n",
Expand Down Expand Up @@ -88,7 +88,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "cb09c344-1836-4e0c-acf8-11d13ac1dbae",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -323,6 +323,117 @@
"console.log(calcToolRes.tool_calls);"
]
},
{
"cell_type": "markdown",
"id": "85dcbecc",
"metadata": {},
"source": [
"## Hooks\n",
"\n",
"Mistral AI supports custom hooks for three events: beforeRequest, requestError, and reponse. Examples of the function signature for each hook type can be seen below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "74b8b855",
"metadata": {},
"outputs": [],
"source": [
"const beforeRequestHook = (req: Request): Request | void | Promise<Request | void> => {\n",
" // Code to run before a request is processed by Mistral\n",
"};\n",
"\n",
"const requestErrorHook = (err: unknown, req: Request): void | Promise<void> => {\n",
" // Code to run when an error occurs as Mistral is processing a request\n",
"};\n",
"\n",
"const responseHook = (res: Response, req: Request): void | Promise<void> => {\n",
" // Code to run before Mistral sends a successful response\n",
"};"
]
},
{
"cell_type": "markdown",
"id": "930df6c4",
"metadata": {},
"source": [
"To add these hooks to the chat model, either pass them as arguments and they are automatically added:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b8084f6",
"metadata": {},
"outputs": [],
"source": [
"import { ChatMistralAI } from \"@langchain/mistralai\" \n",
"\n",
"const modelWithHooks = new ChatMistralAI({\n",
" model: \"mistral-large-latest\",\n",
" temperature: 0,\n",
" maxRetries: 2,\n",
" beforeRequestHooks: [ beforeRequestHook ],\n",
" requestErrorHooks: [ requestErrorHook ],\n",
" responseHooks: [ responseHook ],\n",
" // other params...\n",
"});"
]
},
{
"cell_type": "markdown",
"id": "cc9478f3",
"metadata": {},
"source": [
"Or assign and add them manually after instantiation:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "daa70dc3",
"metadata": {},
"outputs": [],
"source": [
"import { ChatMistralAI } from \"@langchain/mistralai\" \n",
"\n",
"const model = new ChatMistralAI({\n",
" model: \"mistral-large-latest\",\n",
" temperature: 0,\n",
" maxRetries: 2,\n",
" // other params...\n",
"});\n",
"\n",
"model.beforeRequestHooks = [ ...model.beforeRequestHooks, beforeRequestHook ];\n",
"model.requestErrorHooks = [ ...model.requestErrorHooks, requestErrorHook ];\n",
"model.responseHooks = [ ...model.responseHooks, responseHook ];\n",
"\n",
"model.addAllHooksToHttpClient();"
]
},
{
"cell_type": "markdown",
"id": "389f5159",
"metadata": {},
"source": [
"The method addAllHooksToHttpClient clears all currently added hooks before assigning the entire updated hook lists to avoid hook duplication.\n",
"\n",
"Hooks can be removed one at a time, or all hooks can be cleared from the model at once."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a56b64bb",
"metadata": {},
"outputs": [],
"source": [
"model.removeHookFromHttpClient(beforeRequestHook);\n",
"\n",
"model.removeAllHooksFromHttpClient();"
]
},
{
"cell_type": "markdown",
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3",
Expand Down Expand Up @@ -354,4 +465,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Loading

0 comments on commit 69f9824

Please sign in to comment.