Compare commits

..

51 Commits

Author SHA1 Message Date
Erick Friis
fae774a6c3 fmt 2024-01-11 13:16:47 -08:00
Erick Friis
a3c3ad487f Merge branch 'master' into erick/deepinfra-chat 2024-01-11 13:16:20 -08:00
Harrison Chase
80d41a8da3 add old serializable mapping (#15906) 2024-01-11 13:03:12 -08:00
Erick Friis
623f87c888 community[patch]: pinecone bug (#15905) 2024-01-11 11:44:07 -08:00
Eugene Yurtsev
44101b6b0e Docs[patch]: Update OpenAI tools agent description (#15896)
Update OpenAI tools agent description.
2024-01-11 14:39:11 -05:00
Eugene Yurtsev
46b7a8d913 Docs[patch]: Update agent quick start for agents (#15892)
Minor change:

1) Update tool invocation to use .invoke
2) Show hub prompt
2024-01-11 14:38:48 -05:00
Jacob Lee
c11dbefedc docs[patch]: Fix bad headers in output parser docs (#15778)
Currently looks like this:

<img width="282" alt="Screenshot 2024-01-09 at 1 08 53 PM"
src="https://github.com/langchain-ai/langchain/assets/6952323/58f3d368-6588-418e-8502-30d13757cb99">

CC @efriis @baskaryan
2024-01-11 10:24:15 -08:00
Christophe Bornet
c56060bb7d Add document loader section to Astra provider doc page (#15882)
See preview:
https://langchain-git-fork-cbornet-provider-astra-doc-loader-langchain.vercel.app/docs/integrations/providers/astradb#ocument-loader
2024-01-11 07:52:29 -08:00
xvjixiang
611f18c944 Docs: Fix a typo in elasticsearch vectorstore notebook (#15807)
<!-- Thank you for contributing to LangChain!

Please title your PR "<package>: <description>", where <package> is
whichever of langchain, community, core, experimental, etc. is being
modified.

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes if applicable,
  - **Dependencies:** any dependencies required for this change,
- **Twitter handle:** we announce bigger features on Twitter. If your PR
gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before
submitting. Run `make format`, `make lint` and `make test` from the root
of the package you've modified to check this locally.

See contribution guidelines for more information on how to write/run
tests, lint, etc: https://python.langchain.com/docs/contributing/

If you're adding a new integration, please include:
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.

If no one reviews your PR within a few days, please @-mention one of
@baskaryan, @eyurtsev, @hwchase17.
 -->
2024-01-10 20:30:44 -08:00
axiangcoding
d5aa277b94 community: add collection_properties parameter to Milvus (#15788)
- **Description:** add collection_properties parameter to Milvus. See
[pymilvus set_properties()
description](https://milvus.io/api-reference/pymilvus/v2.3.x/Collection/set_properties().md)
  - **Issue:** None
  - **Dependencies:** None
  - **Twitter handle:** None
2024-01-10 20:29:01 -08:00
mogith-pn
9e1ed17bfb Community : Modified doc strings and example notebook for Clarifai (#15816)
Community : Modified doc strings and example notebook for Clarifai

Description:
1. Modified doc strings inside clarifai vectorstore class and
embeddings.
2. Modified notebook examples.

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
2024-01-10 19:33:10 -08:00
Harrison Chase
97411e998f [docs] add beautiful soup dependency (#15860) 2024-01-10 19:32:55 -08:00
Daniel
6d299a55c0 docs: Update cohere.mdx, Text embedding had incorrect code snippet (#15840)
text embedding code snippet was incorrect.
2024-01-10 19:25:29 -08:00
Sagar B Manjunath
e6240fecab templates: Add NVIDIA Canonical RAG example chain (#15758)
- **Description:** Adds a RAG template that uses NVIDIA AI playground
and embedding models, along with Milvus vector store

- **Dependencies:** This template depends on the AI playground service
in NVIDIA NGC. API keys with a significant trial compute are available
(10k queries at the time of writing). This template also depends on the
Milvus Vector store which is publicly available.

Note: [A quick link to get a
key](https://catalog.ngc.nvidia.com/orgs/nvidia/teams/ai-foundation/models/codellama-13b/api)
when you have an NGC account. Generate Key button at the top right of
the code window.

---------

Co-authored-by: Sagar B Manjunath <sbogadimanju@nvidia.com>
Co-authored-by: Erick Friis <erick@langchain.dev>
2024-01-10 18:39:16 -08:00
Erick Friis
38523d7c57 together[minor]: add llm (#15853) 2024-01-10 17:55:34 -08:00
William FH
2895ca87cf Update Evals Notebook (#15851) 2024-01-10 16:33:34 -08:00
Erick Friis
ee708739c3 community[patch]: pinecone v3 support (#15849)
Info in slack

---------

Co-authored-by: Roie Schwaber-Cohen <roie.cohen@gmail.com>
2024-01-10 14:54:50 -08:00
Bagatur
18411c379c docs: fix links (#15848) 2024-01-10 17:39:06 -05:00
Lance Martin
9c871f427b TogetherAI RAG (#15846) 2024-01-10 14:28:05 -08:00
Eugene Yurtsev
a06db53c37 Add unit tests to test openai tools agent (#15843)
This PR adds unit testing to test openai tools agent.
2024-01-10 17:06:30 -05:00
Harrison Chase
21a1538949 add raga reranker (#15838) 2024-01-10 11:07:19 -08:00
Eugene Yurtsev
45f49ca439 infra: fix issue preview (#15836)
Fixing the placeholder for the code example. GitHub collapses newlines
when
trying to use the text area, which is super confusing.
2024-01-10 13:27:07 -05:00
Eugene Yurtsev
c425e6f740 More updates to issue template (#15833)
More update to issue template
2024-01-10 13:16:02 -05:00
Eugene Yurtsev
65980c22b8 Infra: Fix syntax error in BUG REPORT template (#15831)
Fix syntax error in issue template
2024-01-10 12:39:08 -05:00
Eugene Yurtsev
e182d630f7 ISSUE_TEMPLATE: Update issue template (#15757)
Drop some fields, re-order, start directing folks towards QA.

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2024-01-10 12:35:41 -05:00
Bagatur
6432494f9d infra: explicitly specify py path (#15826) 2024-01-10 11:59:43 -05:00
Bagatur
79124fd71d experimental[patch]: Release 0.0.49 (#15823) 2024-01-10 11:23:19 -05:00
Harrison Chase
20abe24819 experimental[minor]: Add semantic chunker (#15799) 2024-01-10 11:18:30 -05:00
Harrison Chase
a1d7f2b3e1 add dspy notebook (#15798) 2024-01-10 08:01:08 -08:00
Eugene Yurtsev
feb41c5e28 langchain[patch]: Improve stream_log with AgentExecutor and Runnable Agent (#15792)
This PR fixes an issue where AgentExecutor with RunnableAgent does not allow users to see individual llm tokens if streaming=True is not set explicitly on the underlying chat model.

The majority of this PR is testing code:

1. Create a test chat model that makes it easier to test streaming and
supports AIMessages that include function invocation information.
2. Tests for the chat model
3. Tests for RunnableAgent (previously untested)
4. Tests for openai agent (previously untested)
2024-01-10 10:53:01 -05:00
Erick Friis
85a4594ed7 community[patch]: more deprecations (#15782) 2024-01-09 20:36:16 -08:00
Erick Friis
33dccf0f66 core[patch]: release 0.1.9 (#15794) 2024-01-09 19:27:19 -08:00
Bagatur
942071bf57 docs: collapse structured use case (#15791) 2024-01-09 21:47:09 -05:00
Erick Friis
0c95f3a981 mistralai[patch]: warn on stop token, fix on_llm_new_token (#15787)
Fixes #15269

Addresses with warning. MistralAI API doesn't support stop token yet.

---------

Co-authored-by: Niels Garve <info@nielsgarve.com>
2024-01-09 16:27:20 -08:00
Erick Friis
323941a90a mistralai[patch]: persist async client (#15786) 2024-01-09 16:21:39 -08:00
Erick Friis
8c42cc4482 fmt 2024-01-09 15:51:35 -08:00
Erick Friis
088633d296 cr 2024-01-09 15:50:12 -08:00
Erick Friis
7057089756 Merge branch 'master' into deepinfra-chat 2024-01-09 15:39:18 -08:00
Tomaz Bratanic
3e0cd11f51 templates: Add neo4j semantic layer template (#15652)
Co-authored-by: Tomaz Bratanic <tomazbratanic@Tomazs-MacBook-Pro.local>
Co-authored-by: Erick Friis <erick@langchain.dev>
2024-01-09 15:33:44 -08:00
NuODaniel
70b6315b23 community[patch]: fix qianfan chat stream calling caused exception (#13800)
- **Description:** 
`QianfanChatEndpoint` extends `BaseChatModel` as a super class, which
has a default stream implement might concat the MessageChunk with
`__add__`. When call stream(), a ValueError for duplicated key will be
raise.
  - **Issues:** 
     * #13546  
     * #13548
     * merge two single test file related to qianfan.
  - **Dependencies:** no
  - **Tag maintainer:**

---------

Co-authored-by: root <liujun45@baidu.com>
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
2024-01-09 15:29:25 -08:00
Erick Friis
656e87beb9 core[patch]: add alternative_import to deprecated (#15781) 2024-01-09 14:45:28 -08:00
Erick Friis
04a5a37e92 robocorp[patch]: fix readme, release 0.0.1.post1 (#15777) 2024-01-09 12:53:57 -08:00
Erick Friis
ae67ba4dbb templates: robocorp action server template (#15776)
---------

Co-authored-by: Rihards Gravis <rihards@gravis.lv>
Co-authored-by: Mikko Korpela <mikko@robocorp.com>
2024-01-09 12:41:20 -08:00
Erick Friis
91ec9da534 openai[patch]: unit test load (#15624) 2024-01-09 11:54:11 -08:00
Erick Friis
7be72e1103 openai[patch], docs: readme (#15773) 2024-01-09 11:52:24 -08:00
Bagatur
ee5bd986de community[patch]: update oai deprecation message (#15681)
addresses #15674
2024-01-09 14:36:58 -05:00
Erick Friis
7562f70c95 robocorp[minor]: Add robocorp action server toolkit (#15766)
Co-authored-by: Rihards Gravis <rihards@gravis.lv>
Co-authored-by: Mikko Korpela <mikko@robocorp.com>
2024-01-09 11:29:19 -08:00
Erick Friis
7bc100fd43 docs: integration package pip installs (#15762)
More than 300 files - will fail check_diff. Will merge after Vercel
deploy succeeds

Still occurrences that need changing - will update more later
2024-01-09 11:13:10 -08:00
Bagatur
1b0db82dbe docs: fix recognition (#15769) 2024-01-09 13:57:28 -05:00
Iskren Chernev
5c6d143056 update test model 2024-01-03 17:42:23 +02:00
Iskren Chernev
17bba02492 deepinfra support for chat_models 2024-01-03 16:59:30 +02:00
518 changed files with 15982 additions and 1117 deletions

View File

@@ -5,60 +5,84 @@ body:
- type: markdown
attributes:
value: >
Thank you for taking the time to file a bug report. Before creating a new
issue, please make sure to take a few moments to check the issue tracker
for existing issues about the bug.
Thank you for taking the time to file a bug report.
Relevant links to check before filing a bug report to see if your issue has already been reported, fixed or
if there's another way to solve your problem:
[LangChain documentation with the integrated search](https://python.langchain.com/docs/get_started/introduction),
[API Reference](https://api.python.langchain.com/en/stable/),
[GitHub search](https://github.com/langchain-ai/langchain),
[LangChain Github Discussions](https://github.com/langchain-ai/langchain/discussions),
[LangChain Github Issues](https://github.com/langchain-ai/langchain/issues?q=is%3Aissue)
- type: checkboxes
id: checks
attributes:
label: Checked other resources
description: Please confirm and check all the following options.
options:
- label: I added a very descriptive title to this issue.
required: true
- label: I searched the LangChain documentation with the integrated search.
required: true
- label: I used the GitHub search to find a similar question and didn't find it.
required: true
- type: textarea
id: reproduction
validations:
required: true
attributes:
label: Example Code
description: |
Please add a self-contained, [minimal, reproducible, example](https://stackoverflow.com/help/minimal-reproducible-example) with your use case.
If a maintainer can copy it, run it, and see it right away, there's a much higher chance that you'll be able to get help.
If you're including an error message, please include the full stack trace not just the last error.
**Important!** Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
Avoid screenshots when possible, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.
placeholder: |
The following code:
```python
from langchain_core.runnables import RunnableLambda
def bad_code(inputs) -> int:
raise NotImplementedError('For demo purpose')
chain = RunnableLambda(bad_code)
chain.invoke('Hello!')
```
Include both the error and the full stack trace if reporting an exception!
- type: textarea
id: description
attributes:
label: Description
description: |
What is the problem, question, or error?
Write a short description telling what you are doing, what you expect to happen, and what is currently happening.
placeholder: |
* I'm trying to use the `langchain` library to do X.
* I expect to see Y.
* Instead, it does Z.
validations:
required: true
- type: textarea
id: system-info
attributes:
label: System Info
description: Please share your system info with us.
placeholder: LangChain version, platform, python version, ...
placeholder: |
"pip freeze | grep langchain"
platform
python version
validations:
required: true
- type: textarea
id: who-can-help
attributes:
label: Who can help?
description: |
Your issue will be replied to more quickly if you can figure out the right person to tag with @
If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
The core maintainers strive to read all issues, but tagging them will help them prioritize.
Please tag fewer than 3 people.
@hwchase17 - project lead
Tracing / Callbacks
- @agola11
Async
- @agola11
DataLoader Abstractions
- @eyurtsev
LLM/Chat Wrappers
- @hwchase17
- @agola11
Tools / Toolkits
- ...
placeholder: "@Username ..."
- type: checkboxes
id: information-scripts-examples
attributes:
label: Information
description: "The problem arises when using:"
options:
- label: "The official example notebooks/scripts"
- label: "My own modified scripts"
- type: checkboxes
id: related-components
attributes:
@@ -77,30 +101,3 @@ body:
- label: "Chains"
- label: "Callbacks/Tracing"
- label: "Async"
- type: textarea
id: reproduction
validations:
required: true
attributes:
label: Reproduction
description: |
Please provide a [code sample](https://stackoverflow.com/help/minimal-reproducible-example) that reproduces the problem you ran into. It can be a Colab link or just a code snippet.
If you have code snippets, error messages, stack traces please provide them here as well.
Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
Avoid screenshots when possible, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.
placeholder: |
Steps to reproduce the behavior:
1.
2.
3.
- type: textarea
id: expected-behavior
validations:
required: true
attributes:
label: Expected behavior
description: "A clear and concise description of what you would expect to happen."

View File

@@ -1,18 +0,0 @@
name: Other Issue
description: Raise an issue that wouldn't be covered by the other templates.
title: "Issue: <Please write a comprehensive title after the 'Issue: ' prefix>"
labels: [04 - Other]
body:
- type: textarea
attributes:
label: "Issue you'd like to raise."
description: >
Please describe the issue you'd like to raise as clearly as possible.
Make sure to include any relevant links or references.
- type: textarea
attributes:
label: "Suggestion:"
description: >
Please outline a suggestion to improve the issue here.

View File

@@ -28,6 +28,7 @@ runs:
steps:
- uses: actions/setup-python@v5
name: Setup python ${{ inputs.python-version }}
id: setup-python
with:
python-version: ${{ inputs.python-version }}
@@ -74,7 +75,8 @@ runs:
env:
POETRY_VERSION: ${{ inputs.poetry-version }}
PYTHON_VERSION: ${{ inputs.python-version }}
run: pipx install "poetry==$POETRY_VERSION" --python "python$PYTHON_VERSION" --verbose
# Install poetry using the python version installed by setup-python step.
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose
- name: Restore pip and poetry cached dependencies
uses: actions/cache@v3

156
cookbook/together_ai.ipynb Normal file
View File

@@ -0,0 +1,156 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0fc0309d-4d49-4bb5-bec0-bd92c6fddb28",
"metadata": {},
"source": [
"## Together AI + RAG\n",
" \n",
"[Together AI](https://python.langchain.com/docs/integrations/llms/together) has a broad set of OSS LLMs via inference API.\n",
"\n",
"See [here](https://api.together.xyz/playground). We use `\"mistralai/Mixtral-8x7B-Instruct-v0.1` for RAG on the Mixtral paper.\n",
"\n",
"Download the paper:\n",
"https://arxiv.org/pdf/2401.04088.pdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d12fb75a-f707-48d5-82a5-efe2d041813c",
"metadata": {},
"outputs": [],
"source": [
"! pip install --quiet pypdf chromadb tiktoken openai langchain-together"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9ab49327-0532-4480-804c-d066c302a322",
"metadata": {},
"outputs": [],
"source": [
"# Load\n",
"from langchain_community.document_loaders import PyPDFLoader\n",
"\n",
"loader = PyPDFLoader(\"~/Desktop/mixtral.pdf\")\n",
"data = loader.load()\n",
"\n",
"# Split\n",
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
"\n",
"text_splitter = RecursiveCharacterTextSplitter(chunk_size=2000, chunk_overlap=0)\n",
"all_splits = text_splitter.split_documents(data)\n",
"\n",
"# Add to vectorDB\n",
"from langchain_community.embeddings import OpenAIEmbeddings\n",
"from langchain_community.vectorstores import Chroma\n",
"\n",
"\"\"\"\n",
"from langchain_together.embeddings import TogetherEmbeddings\n",
"embeddings = TogetherEmbeddings(model=\"togethercomputer/m2-bert-80M-8k-retrieval\")\n",
"\"\"\"\n",
"vectorstore = Chroma.from_documents(\n",
" documents=all_splits,\n",
" collection_name=\"rag-chroma\",\n",
" embedding=OpenAIEmbeddings(),\n",
")\n",
"\n",
"retriever = vectorstore.as_retriever()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4efaddd9-3dbb-455c-ba54-0ad7f2d2ce0f",
"metadata": {},
"outputs": [],
"source": [
"from langchain_core.output_parsers import StrOutputParser\n",
"from langchain_core.prompts import ChatPromptTemplate\n",
"from langchain_core.pydantic_v1 import BaseModel\n",
"from langchain_core.runnables import RunnableParallel, RunnablePassthrough\n",
"\n",
"# RAG prompt\n",
"template = \"\"\"Answer the question based only on the following context:\n",
"{context}\n",
"\n",
"Question: {question}\n",
"\"\"\"\n",
"prompt = ChatPromptTemplate.from_template(template)\n",
"\n",
"# LLM\n",
"from langchain_community.llms import Together\n",
"\n",
"llm = Together(\n",
" model=\"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n",
" temperature=0.0,\n",
" max_tokens=2000,\n",
" top_k=1,\n",
")\n",
"\n",
"# RAG chain\n",
"chain = (\n",
" RunnableParallel({\"context\": retriever, \"question\": RunnablePassthrough()})\n",
" | prompt\n",
" | llm\n",
" | StrOutputParser()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "88b1ee51-1b0f-4ebf-bb32-e50e843f0eeb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'\\nAnswer: The architectural details of Mixtral are as follows:\\n- Dimension (dim): 4096\\n- Number of layers (n\\\\_layers): 32\\n- Dimension of each head (head\\\\_dim): 128\\n- Hidden dimension (hidden\\\\_dim): 14336\\n- Number of heads (n\\\\_heads): 32\\n- Number of kv heads (n\\\\_kv\\\\_heads): 8\\n- Context length (context\\\\_len): 32768\\n- Vocabulary size (vocab\\\\_size): 32000\\n- Number of experts (num\\\\_experts): 8\\n- Number of top k experts (top\\\\_k\\\\_experts): 2\\n\\nMixtral is based on a transformer architecture and uses the same modifications as described in [18], with the notable exceptions that Mixtral supports a fully dense context length of 32k tokens, and the feedforward block picks from a set of 8 distinct groups of parameters. At every layer, for every token, a router network chooses two of these groups (the “experts”) to process the token and combine their output additively. This technique increases the number of parameters of a model while controlling cost and latency, as the model only uses a fraction of the total set of parameters per token. Mixtral is pretrained with multilingual data using a context size of 32k tokens. It either matches or exceeds the performance of Llama 2 70B and GPT-3.5, over several benchmarks. In particular, Mixtral vastly outperforms Llama 2 70B on mathematics, code generation, and multilingual benchmarks.'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chain.invoke(\"What are the Architectural details of Mixtral?\")"
]
},
{
"cell_type": "markdown",
"id": "755cf871-26b7-4e30-8b91-9ffd698470f4",
"metadata": {},
"source": [
"Trace: \n",
"\n",
"https://smith.langchain.com/public/935fd642-06a6-4b42-98e3-6074f93115cd/r"
]
}
],
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -40,3 +40,8 @@ smooth for future contributors.
In a similar vein, we do enforce certain linting, formatting, and documentation standards in the codebase.
If you are finding these difficult (or even just annoying) to work with, feel free to contact a maintainer for help -
we do not want these to get in the way of getting good code into the codebase.
# 🌟 Recognition
If your contribution has made its way into a release, we will want to give you credit on Twitter (only if you want though)!
If you have a Twitter account you would like us to mention, please let us know in the PR or through another means.

View File

@@ -10,6 +10,16 @@
"Example of how to use LCEL to write Python code."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0653c7c7",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain-core langchain-experimental langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,
@@ -17,10 +27,10 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.prompts import (\n",
"from langchain_core.output_parsers import StrOutputParser\n",
"from langchain_core.prompts import (\n",
" ChatPromptTemplate,\n",
")\n",
"from langchain_core.output_parsers import StrOutputParser\n",
"from langchain_experimental.utilities import PythonREPL\n",
"from langchain_openai import ChatOpenAI"
]

View File

@@ -12,6 +12,16 @@
"One especially useful technique is to use embeddings to route a query to the most relevant prompt. Here's a very simple example."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b793a0aa",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain-core langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,
@@ -19,9 +29,9 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.prompts import PromptTemplate\n",
"from langchain.utils.math import cosine_similarity\n",
"from langchain_core.output_parsers import StrOutputParser\n",
"from langchain_core.prompts import PromptTemplate\n",
"from langchain_core.runnables import RunnableLambda, RunnablePassthrough\n",
"from langchain_openai import ChatOpenAI, OpenAIEmbeddings\n",
"\n",

View File

@@ -10,6 +10,16 @@
"This shows how to add memory to an arbitrary chain. Right now, you can use the memory classes but need to hook it up manually"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18753dee",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -10,6 +10,16 @@
"This shows how to add in moderation (or other safeguards) around your LLM application."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6acf3505",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 20,

View File

@@ -19,6 +19,14 @@
"Runnables can easily be used to string together multiple Chains"
]
},
{
"cell_type": "raw",
"id": "0f316b5c",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 4,

View File

@@ -35,6 +35,14 @@
"Note, you can mix and match PromptTemplate/ChatPromptTemplates and LLMs/ChatModels as you like here."
]
},
{
"cell_type": "raw",
"id": "ef79a54b",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -12,6 +12,16 @@
"With LCEL, it's easy to add custom functionality for managing the size of prompts within your chain or agent. Let's look at simple agent example that can search Wikipedia for information."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1846587d",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai wikipedia"
]
},
{
"cell_type": "code",
"execution_count": 1,
@@ -19,8 +29,6 @@
"metadata": {},
"outputs": [],
"source": [
"# !pip install langchain wikipedia\n",
"\n",
"from operator import itemgetter\n",
"\n",
"from langchain.agents import AgentExecutor, load_tools\n",

View File

@@ -26,7 +26,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install langchain openai faiss-cpu tiktoken"
"%pip install --upgrade --quiet langchain langchain-openai faiss-cpu tiktoken"
]
},
{

View File

@@ -19,6 +19,14 @@
"We can replicate our SQLDatabaseChain with Runnables."
]
},
{
"cell_type": "raw",
"id": "b3121aa8",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -17,7 +17,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install duckduckgo-search"
"%pip install --upgrade --quiet langchain langchain-openai duckduckgo-search"
]
},
{

View File

@@ -30,6 +30,14 @@
"The most basic and common use case is chaining a prompt template and a model together. To see how this works, let's create a chain that takes a topic and generates a joke:"
]
},
{
"cell_type": "raw",
"id": "278b0027",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain-core langchain-community langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,
@@ -486,7 +494,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.1"
"version": "3.11.4"
}
},
"nbformat": 4,

View File

@@ -12,6 +12,16 @@
"Suppose we have a simple prompt + model sequence:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c5dad8b5",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -34,6 +34,16 @@
"With LLMs we can configure things like temperature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40ed76a2",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 35,

View File

@@ -16,6 +16,16 @@
"Let's take a look at this in action!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23b2b564",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 16,

View File

@@ -24,6 +24,16 @@
"IMPORTANT: By default, a lot of the LLM wrappers catch errors and retry. You will most likely want to turn those off when working with fallbacks. Otherwise the first wrapper will keep on retrying and not failing."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ebb61b1f",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -24,6 +24,14 @@
"Note that all inputs to these functions need to be a SINGLE argument. If you have a function that accepts multiple arguments, you should write a wrapper that accepts a single input and unpacks it into multiple argument."
]
},
{
"cell_type": "raw",
"id": "9a5fe916",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -24,6 +24,15 @@
"## Sync version"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -15,11 +15,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8bc5d235",
"id": "d816e954",
"metadata": {},
"outputs": [],
"source": [
"!pip install langchain openai faiss-cpu tiktoken"
"%pip install --upgrade --quiet langchain langchain-openai faiss-cpu tiktoken"
]
},
{
@@ -29,8 +29,6 @@
"metadata": {},
"outputs": [],
"source": [
"from operator import itemgetter\n",
"\n",
"from langchain.prompts import ChatPromptTemplate\n",
"from langchain.vectorstores import FAISS\n",
"from langchain_core.output_parsers import StrOutputParser\n",

View File

@@ -1,7 +1,7 @@
{
"cells": [
{
"cell_type": "markdown",
"cell_type": "raw",
"id": "e2596041-9b76-4e74-836f-e6235086bbf0",
"metadata": {},
"source": [
@@ -26,6 +26,16 @@
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2627ffd7",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 3,

View File

@@ -41,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install -U langchain redis anthropic"
"%pip install --upgrade --quiet langchain redis anthropic"
]
},
{

View File

@@ -28,6 +28,16 @@
"See the example below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e169b952",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 11,

View File

@@ -50,6 +50,14 @@
"Let's take a look at these methods. To do so, we'll create a super simple PromptTemplate + ChatModel chain."
]
},
{
"cell_type": "raw",
"id": "57768739",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain-core langchain-community langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -35,6 +35,14 @@
"To better understand the value of LCEL, it's helpful to see it in action and think about how we might recreate similar functionality without it. In this walkthrough we'll do just that with our [basic example](/docs/expression_language/get_started#basic_example) from the get started section. We'll take our simple prompt + model chain, which under the hood already defines a lot of functionality, and see what it would take to recreate all of it."
]
},
{
"cell_type": "raw",
"id": "b99b47ec",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain-core langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": null,

View File

@@ -73,7 +73,7 @@ For this getting started guide, we will provide two options: using OpenAI (a pop
First we'll need to import the LangChain x OpenAI integration package.
```shell
pip install langchain_openai
pip install langchain-openai
```
Accessing the API requires an API key, which you can get by creating an account and heading [here](https://platform.openai.com/account/api-keys). Once we have a key we'll want to set it as an environment variable by running:
@@ -182,7 +182,14 @@ You can then use a retriever to fetch only the most relevant pieces and pass tho
In this process, we will look up relevant documents from a *Retriever* and then pass them into the prompt.
A Retriever can be backed by anything - a SQL table, the internet, etc - but in this instance we will populate a vector store and use that as a retriever. For more information on vectorstores, see [this documentation](/docs/modules/data_connection/vectorstores).
First, we need to load the data that we want to index:
First, we need to load the data that we want to index. In order to do this, we will use the WebBaseLoader. This requires installing [BeautifulSoup](https://beautiful-soup-4.readthedocs.io/en/latest/):
```
```shell
pip install beautifulsoup4
```
After that, we can import and use WebBaseLoader.
```python

View File

@@ -104,7 +104,7 @@
},
"outputs": [],
"source": [
"# %pip install anthropic\n",
"%pip install --upgrade --quiet anthropic\n",
"# %env ANTHROPIC_API_KEY=YOUR_API_KEY"
]
},

View File

@@ -23,6 +23,15 @@
"In this example, you will use gpt-4 to select which output is preferred."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -318,7 +318,7 @@
},
"outputs": [],
"source": [
"# %pip install ChatAnthropic\n",
"%pip install --upgrade --quiet anthropic\n",
"# %env ANTHROPIC_API_KEY=<API_KEY>"
]
},
@@ -464,4 +464,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

View File

@@ -23,7 +23,7 @@
},
"outputs": [],
"source": [
"# %pip install evaluate > /dev/null"
"%pip install --upgrade --quiet evaluate > /dev/null"
]
},
{

View File

@@ -18,6 +18,15 @@
"Below is an example demonstrating the usage of `LabeledScoreStringEvalChain` using the default prompt:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 10,

View File

@@ -29,7 +29,7 @@
},
"outputs": [],
"source": [
"# %pip install rapidfuzz"
"%pip install --upgrade --quiet rapidfuzz"
]
},
{

View File

@@ -14,6 +14,16 @@
"In this example, you will make a simple trajectory evaluator that uses an LLM to determine if any actions were unnecessary."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c96b340",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,
@@ -140,4 +150,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

View File

@@ -17,6 +17,16 @@
"For more information, check out the reference docs for the [TrajectoryEvalChain](https://api.python.langchain.com/en/latest/evaluation/langchain.evaluation.agents.trajectory_eval_chain.TrajectoryEvalChain.html#langchain.evaluation.agents.trajectory_eval_chain.TrajectoryEvalChain) for more info."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4d22262",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,
@@ -177,7 +187,7 @@
},
"outputs": [],
"source": [
"# %pip install anthropic\n",
"%pip install --upgrade --quiet anthropic\n",
"# ANTHROPIC_API_KEY=<YOUR ANTHROPIC API KEY>"
]
},
@@ -300,4 +310,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

View File

@@ -26,6 +26,16 @@
"IMPORTANT: By default, a lot of the LLM wrappers catch errors and retry. You will most likely want to turn those off when working with fallbacks. Otherwise the first wrapper will keep on retrying and not failing."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3a449a2e",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -201,7 +201,7 @@
"\n",
"* E.g., for Llama-7b: `ollama pull llama2` will download the most basic version of the model (e.g., smallest # parameters and 4 bit quantization)\n",
"* We can also specify a particular version from the [model list](https://github.com/jmorganca/ollama?tab=readme-ov-file#model-library), e.g., `ollama pull llama2:13b`\n",
"* See the full set of parameters on the [API reference page](https://api.python.langchain.com/en/latest/llms/langchain.llms.ollama.Ollama.html)"
"* See the full set of parameters on the [API reference page](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.ollama.Ollama.html)"
]
},
{
@@ -241,7 +241,7 @@
"\n",
"As noted above, see the [API reference](https://api.python.langchain.com/en/latest/llms/langchain.llms.llamacpp.LlamaCpp.html?highlight=llamacpp#langchain.llms.llamacpp.LlamaCpp) for the full set of parameters. \n",
"\n",
"From the [llama.cpp docs](https://python.langchain.com/docs/integrations/llms/llamacpp), a few are worth commenting on:\n",
"From the [llama.cpp API reference docs](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.llamacpp.LlamaCpp.htm), a few are worth commenting on:\n",
"\n",
"`n_gpu_layers`: number of layers to be loaded into GPU memory\n",
"\n",
@@ -277,7 +277,7 @@
"source": [
"%env CMAKE_ARGS=\"-DLLAMA_METAL=on\"\n",
"%env FORCE_CMAKE=1\n",
"%pip install -U llama-cpp-python --no-cache-dirclear"
"%pip install --upgrade --quiet llama-cpp-python --no-cache-dirclear"
]
},
{
@@ -378,9 +378,9 @@
"source": [
"### GPT4All\n",
"\n",
"We can use model weights downloaded from [GPT4All](https://python.langchain.com/docs/integrations/llms/gpt4all) model explorer.\n",
"We can use model weights downloaded from [GPT4All](/docs/integrations/llms/gpt4all) model explorer.\n",
"\n",
"Similar to what is shown above, we can run inference and use [the API reference](https://api.python.langchain.com/en/latest/llms/langchain.llms.gpt4all.GPT4All.html?highlight=gpt4all#langchain.llms.gpt4all.GPT4All) to set parameters of interest."
"Similar to what is shown above, we can run inference and use [the API reference](https://api.python.langchain.com/en/latest/llms/langchain_community.llms.gpt4all.GPT4All.html) to set parameters of interest."
]
},
{
@@ -390,7 +390,7 @@
"metadata": {},
"outputs": [],
"source": [
"pip install gpt4all\n"
"%pip install gpt4all"
]
},
{
@@ -582,9 +582,9 @@
"source": [
"## Use cases\n",
"\n",
"Given an `llm` created from one of the models above, you can use it for [many use cases](docs/use_cases).\n",
"Given an `llm` created from one of the models above, you can use it for [many use cases](/docs/use_cases/).\n",
"\n",
"For example, here is a guide to [RAG](docs/use_cases/question_answering/local_retrieval_qa) with local LLMs.\n",
"For example, here is a guide to [RAG](/docs/use_cases/question_answering/local_retrieval_qa) with local LLMs.\n",
"\n",
"In general, use cases for local LLMs can be driven by at least two factors:\n",
"\n",
@@ -611,7 +611,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.9.1"
}
},
"nbformat": 4,

View File

@@ -12,6 +12,16 @@
"LangChain provides the concept of a ModelLaboratory to test out and try different models."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12ebae56",
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@@ -28,15 +28,23 @@
"Below you will find the use case on how to leverage anonymization in LangChain."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade --quiet langchain langchain-openai langchain-experimental presidio-analyzer presidio-anonymizer spacy Faker"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Install necessary packages\n",
"# ! pip install langchain langchain-experimental openai presidio-analyzer presidio-anonymizer spacy Faker\n",
"# ! python -m spacy download en_core_web_lg"
"# Download model\n",
"!python -m spacy download en_core_web_lg"
]
},
{

View File

@@ -41,15 +41,21 @@
"\n"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain langchain-openai langchain-experimental presidio-analyzer presidio-anonymizer spacy Faker"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Install necessary packages\n",
"# ! pip install langchain langchain-experimental openai presidio-analyzer presidio-anonymizer spacy Faker\n",
"# ! python -m spacy download en_core_web_lg"
"# Download model\n",
"!python -m spacy download en_core_web_lg"
]
},
{
@@ -239,7 +245,7 @@
"outputs": [],
"source": [
"# Install necessary packages\n",
"# ! pip install fasttext langdetect"
"%pip install --upgrade --quiet fasttext langdetect"
]
},
{

View File

@@ -31,15 +31,21 @@
"### Iterative process of upgrading the anonymizer"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"%pip install --upgrade --quiet langchain langchain-experimental langchain-openai presidio-analyzer presidio-anonymizer spacy Faker faiss-cpu tiktoken"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Install necessary packages\n",
"# !pip install langchain langchain-experimental openai presidio-analyzer presidio-anonymizer spacy Faker faiss-cpu tiktoken\n",
"# ! python -m spacy download en_core_web_lg"
"# Download model\n",
"! python -m spacy download en_core_web_lg"
]
},
{

View File

@@ -56,7 +56,7 @@
"outputs": [],
"source": [
"# Install necessary packages\n",
"# ! pip install langchain langchain-experimental openai presidio-analyzer presidio-anonymizer spacy Faker\n",
"%pip install --upgrade --quiet langchain langchain-experimental langchain-openai presidio-analyzer presidio-anonymizer spacy Faker\n",
"# ! python -m spacy download en_core_web_lg"
]
},

View File

@@ -24,7 +24,7 @@
},
"outputs": [],
"source": [
"%pip install boto3 nltk"
"%pip install --upgrade --quiet boto3 nltk"
]
},
{
@@ -37,7 +37,7 @@
},
"outputs": [],
"source": [
"%pip install -U langchain_experimental"
"%pip install --upgrade --quiet langchain_experimental"
]
},
{
@@ -50,7 +50,7 @@
},
"outputs": [],
"source": [
"%pip install -U langchain pydantic"
"%pip install --upgrade --quiet langchain pydantic"
]
},
{
@@ -527,7 +527,7 @@
},
"outputs": [],
"source": [
"%pip install huggingface_hub"
"%pip install --upgrade --quiet huggingface_hub"
]
},
{

View File

@@ -31,7 +31,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install \"optimum[onnxruntime]\""
"%pip install --upgrade --quiet \"optimum[onnxruntime]\" langchain transformers langchain-experimental langchain-openai"
]
},
{

View File

@@ -43,8 +43,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install argilla --upgrade\n",
"!pip install openai"
"%pip install --upgrade --quiet langchain langchain-openai argilla"
]
},
{

View File

@@ -42,7 +42,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install deepeval --upgrade"
"%pip install --upgrade --quiet langchain langchain-openai deepeval"
]
},
{

View File

@@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install context-python --upgrade"
"%pip install --upgrade --quiet langchain langchain-openai context-python"
]
},
{

View File

@@ -34,9 +34,9 @@
"outputs": [],
"source": [
"# Install necessary dependencies.\n",
"!pip install -q infinopy\n",
"!pip install -q matplotlib\n",
"!pip install -q tiktoken"
"%pip install --upgrade --quiet infinopy\n",
"%pip install --upgrade --quiet matplotlib\n",
"%pip install --upgrade --quiet tiktoken"
]
},
{

View File

@@ -56,7 +56,7 @@
},
"outputs": [],
"source": [
"!pip install -U label-studio label-studio-sdk openai"
"%pip install --upgrade --quiet langchain label-studio label-studio-sdk langchain-openai"
]
},
{

View File

@@ -32,7 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install promptlayer --upgrade"
"%pip install --upgrade --quiet promptlayer --upgrade"
]
},
{

View File

@@ -38,9 +38,9 @@
},
"outputs": [],
"source": [
"!pip install sagemaker\n",
"!pip install openai\n",
"!pip install google-search-results"
"%pip install --upgrade --quiet sagemaker\n",
"%pip install --upgrade --quiet langchain-openai\n",
"%pip install --upgrade --quiet google-search-results"
]
},
{

View File

@@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install trubrics"
"%pip install --upgrade --quiet trubrics"
]
},
{

View File

@@ -129,7 +129,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install langchain-anthropic"
"%pip install --upgrade --quiet langchain-anthropic"
]
},
{

View File

@@ -33,7 +33,7 @@
},
"outputs": [],
"source": [
"# !pip install openai"
"%pip install --upgrade --quiet langchain-openai"
]
},
{

View File

@@ -55,17 +55,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[INFO] [09-15 20:00:29] logging.py:55 [t:139698882193216]: requesting llm api endpoint: /chat/eb-instant\n"
]
}
],
"outputs": [],
"source": [
"\"\"\"For basic init and call\"\"\"\n",
"import os\n",
@@ -126,9 +118,7 @@
"from langchain.schema import HumanMessage\n",
"from langchain_community.chat_models import QianfanChatEndpoint\n",
"\n",
"chatLLM = QianfanChatEndpoint(\n",
" streaming=True,\n",
")\n",
"chatLLM = QianfanChatEndpoint()\n",
"res = chatLLM.stream([HumanMessage(content=\"hi\")], streaming=True)\n",
"for r in res:\n",
" print(\"chat resp:\", r)\n",
@@ -260,11 +250,11 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.11.5"
},
"vscode": {
"interpreter": {
"hash": "6fa70026b407ae751a5c9e6bd7f7d482379da8ad616f98512780b705c84ee157"
"hash": "58f7cb64c3a06383b7f18d2a11305edccbad427293a2b4afa7abe8bfc810d4bb"
}
}
},

View File

@@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install boto3"
"%pip install --upgrade --quiet boto3"
]
},
{

View File

@@ -0,0 +1,170 @@
{
"cells": [
{
"cell_type": "raw",
"id": "9d3b07d9",
"metadata": {},
"source": [
"---\n",
"sidebar_label: DeepInfra\n",
"---"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "bf733a38-db84-4363-89e2-de6735c37230",
"metadata": {},
"source": [
"# ChatDeepInfra\n",
"\n",
"[DeepInfra](https://deepinfra.com/?utm_source=langchain) is a serverless inference as a service that provides access to a [variety of LLMs](https://deepinfra.com/models?utm_source=langchain) and [embeddings models](https://deepinfra.com/models?type=embeddings&utm_source=langchain). This notebook goes over how to use LangChain with DeepInfra for chat models."
]
},
{
"cell_type": "markdown",
"id": "8e237415-b81e-4573-87f2-2b9ad51631bc",
"metadata": {},
"source": [
"## Set the Environment API Key\n",
"Make sure to get your API key from DeepInfra. You have to [Login](https://deepinfra.com/login?from=%2Fdash) and get a new token.\n",
"\n",
"You are given a 1 hour free of serverless GPU compute to test different models. (see [here](https://github.com/deepinfra/deepctl#deepctl))\n",
"You can print your token with `deepctl auth token`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "02466faf-679b-4b53-91b1-d2a06802e983",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# get a new token: https://deepinfra.com/login?from=%2Fdash\n",
"\n",
"import os\n",
"\n",
"if not os.environ.get(\"DEEPINFRA_API_TOKEN\"):\n",
" from getpass import getpass\n",
"\n",
" DEEPINFRA_API_TOKEN = getpass()\n",
" os.environ[\"DEEPINFRA_API_TOKEN\"] = DEEPINFRA_API_TOKEN\n",
" # or pass deepinfra_api_token parameter to the ChatDeepInfra constructor"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d4a7c55d-b235-4ca4-a579-c90cc9570da9",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content=' Sure! Here is the translation of \"I love programming\" into French:\\n\\nJe adore le programming.\\n\\nIn this sentence, \"adore\" is the verb used to express the idea of loving something. Other options could be \"aime\" or \"aimons\", but \"adore\" is the most commonly used verb for this purpose in French.')"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain_community.chat_models import ChatDeepInfra\n",
"from langchain_core.messages import HumanMessage\n",
"\n",
"chat = ChatDeepInfra(model=\"meta-llama/Llama-2-7b-chat-hf\")\n",
"\n",
"messages = [\n",
" HumanMessage(\n",
" content=\"Translate this sentence from English to French. I love programming.\"\n",
" )\n",
"]\n",
"chat.invoke(messages)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "c361ab1e-8c0c-4206-9e3c-9d1424a12b9c",
"metadata": {},
"source": [
"## `ChatDeepInfra` also supports async and streaming functionality:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c5fac0e9-05a4-4fc1-a3b3-e5bbb24b971b",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content=' Sure! Here is the translation of \"I love programming\" into French:\\n\\nJe adore le programming.\\n\\nI hope this helps! Let me know if you have any other questions.')"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"await chat.ainvoke(messages)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "025be980-e50d-4a68-93dc-c9c7b500ce34",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Sure! Here's the translation of \"I love programming\" from English to French:\n",
"\n",
"Je suis passionné(e) de programmation.\n",
"\n",
"Note that the sentence is translated as \"I am passionate about programming\" in French, as the verb \"aimer\" (to love) is not commonly used in this context. Instead, \"passionné(e)\" (passionate) is used to convey the idea of having a strong interest or enjoyment in something.\n"
]
}
],
"source": [
"for chunk in chat.stream(messages):\n",
" print(chunk.content, end=\"\")\n",
"print()"
]
}
],
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -34,7 +34,7 @@
},
"outputs": [],
"source": [
"# !pip install openai"
"%pip install --upgrade --quiet langchain-openai"
]
},
{

View File

@@ -19,7 +19,7 @@
},
"outputs": [],
"source": [
"# !pip install gigachat"
"%pip install --upgrade --quiet gigachat"
]
},
{

View File

@@ -28,7 +28,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install -U --quiet langchain-google-genai pillow"
"%pip install --upgrade --quiet langchain-google-genai pillow"
]
},
{

View File

@@ -21,7 +21,7 @@
"\n",
"By default, Google Cloud [does not use](https://cloud.google.com/vertex-ai/docs/generative-ai/data-governance#foundation_model_development) customer data to train its foundation models as part of Google Cloud`s AI/ML Privacy Commitment. More details about how Google processes data can also be found in [Google's Customer Data Processing Addendum (CDPA)](https://cloud.google.com/terms/data-processing-addendum).\n",
"\n",
"To use `Google Cloud Vertex AI` PaLM you must have the `google-cloud-aiplatform` Python package installed and either:\n",
"To use `Google Cloud Vertex AI` PaLM you must have the `langchain-google-vertexai` Python package installed and either:\n",
"- Have credentials configured for your environment (gcloud, workload identity, etc...)\n",
"- Store the path to a service account JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable\n",
"\n",
@@ -35,13 +35,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"!pip install -U langchain-google-vertexai"
"%pip install --upgrade --quiet langchain-google-vertexai"
]
},
{
@@ -50,8 +61,8 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain_google_vertexai import ChatVertexAI\n",
"from langchain_core.prompts import ChatPromptTemplate"
"from langchain_core.prompts import ChatPromptTemplate\n",
"from langchain_google_vertexai import ChatVertexAI"
]
},
{

View File

@@ -58,7 +58,7 @@
}
],
"source": [
"%pip install GPTRouter"
"%pip install --upgrade --quiet GPTRouter"
]
},
{

View File

@@ -33,7 +33,7 @@
}
],
"source": [
"%pip install -q text-generation transformers google-search-results numexpr langchainhub sentencepiece jinja2"
"%pip install --upgrade --quiet text-generation transformers google-search-results numexpr langchainhub sentencepiece jinja2"
]
},
{

View File

@@ -25,7 +25,7 @@
"id": "f5b652cf",
"metadata": {},
"source": [
"!pip install -U llamaapi"
"%pip install --upgrade --quiet llamaapi"
]
},
{

View File

@@ -44,7 +44,7 @@
}
],
"source": [
"%pip install -U --quiet langchain-nvidia-ai-endpoints"
"%pip install --upgrade --quiet langchain-nvidia-ai-endpoints"
]
},
{
@@ -795,7 +795,7 @@
}
],
"source": [
"%pip install -U --quiet langchain"
"%pip install --upgrade --quiet langchain"
]
},
{

View File

@@ -264,7 +264,7 @@
},
"outputs": [],
"source": [
"%pip install pillow"
"%pip install --upgrade --quiet pillow"
]
},
{

View File

@@ -36,7 +36,7 @@
"outputs": [],
"source": [
"# Install the package\n",
"!pip install dashscope"
"%pip install --upgrade --quiet dashscope"
]
},
{

View File

@@ -32,7 +32,7 @@
"outputs": [],
"source": [
"# Install the package\n",
"!pip install volcengine"
"%pip install --upgrade --quiet volcengine"
]
},
{

View File

@@ -29,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install yandexcloud"
"%pip install --upgrade --quiet yandexcloud"
]
},
{

View File

@@ -32,7 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"# !pip install zhipuai"
"%pip install --upgrade --quiet zhipuai"
]
},
{

View File

@@ -369,7 +369,7 @@
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U openai --quiet"
"%pip install --upgrade --quiet langchain-openai"
]
},
{

View File

@@ -25,7 +25,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client"
"%pip install --upgrade --quiet google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client"
]
},
{

View File

@@ -213,7 +213,7 @@
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U openai --quiet"
"%pip install --upgrade --quiet langchain-openai"
]
},
{

View File

@@ -30,7 +30,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install -U langchain openai"
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{

View File

@@ -30,7 +30,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install -U langchain openai"
"%pip install --upgrade --quiet langchain langchain-openai"
]
},
{

View File

@@ -41,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install airbyte-cdk"
"%pip install --upgrade --quiet airbyte-cdk"
]
},
{
@@ -61,7 +61,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install \"source_github@git+https://github.com/airbytehq/airbyte.git@master#subdirectory=airbyte-integrations/connectors/source-github\""
"%pip install --upgrade --quiet \"source_github@git+https://github.com/airbytehq/airbyte.git@master#subdirectory=airbyte-integrations/connectors/source-github\""
]
},
{

View File

@@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install airbyte-source-gong"
"%pip install --upgrade --quiet airbyte-source-gong"
]
},
{

View File

@@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install airbyte-source-hubspot"
"%pip install --upgrade --quiet airbyte-source-hubspot"
]
},
{

View File

@@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install airbyte-source-salesforce"
"%pip install --upgrade --quiet airbyte-source-salesforce"
]
},
{

View File

@@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install airbyte-source-shopify"
"%pip install --upgrade --quiet airbyte-source-shopify"
]
},
{

View File

@@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install airbyte-source-stripe"
"%pip install --upgrade --quiet airbyte-source-stripe"
]
},
{

View File

@@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install airbyte-source-typeform"
"%pip install --upgrade --quiet airbyte-source-typeform"
]
},
{

View File

@@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install airbyte-source-zendesk-support"
"%pip install --upgrade --quiet airbyte-source-zendesk-support"
]
},
{

View File

@@ -15,7 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"! pip install pyairtable"
"%pip install --upgrade --quiet pyairtable"
]
},
{

View File

@@ -37,7 +37,7 @@
}
],
"source": [
"!pip install pyodps"
"%pip install --upgrade --quiet pyodps"
]
},
{

View File

@@ -25,7 +25,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install boto3 openai tiktoken python-dotenv"
"%pip install --upgrade --quiet boto3 langchain-openai tiktoken python-dotenv"
]
},
{
@@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install \"amazon-textract-caller>=0.2.0\""
"%pip install --upgrade --quiet \"amazon-textract-caller>=0.2.0\""
]
},
{

View File

@@ -24,7 +24,7 @@
},
"outputs": [],
"source": [
"#!pip install apify-client"
"%pip install --upgrade --quiet apify-client"
]
},
{

View File

@@ -37,7 +37,7 @@
},
"outputs": [],
"source": [
"#!pip install arxiv"
"%pip install --upgrade --quiet arxiv"
]
},
{
@@ -59,7 +59,7 @@
},
"outputs": [],
"source": [
"#!pip install pymupdf"
"%pip install --upgrade --quiet pymupdf"
]
},
{

View File

@@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install assemblyai"
"%pip install --upgrade --quiet assemblyai"
]
},
{

View File

@@ -23,7 +23,7 @@
"metadata": {},
"outputs": [],
"source": [
"! pip install -q playwright beautifulsoup4\n",
"%pip install --upgrade --quiet playwright beautifulsoup4\n",
"! playwright install"
]
},

View File

@@ -23,7 +23,7 @@
},
"outputs": [],
"source": [
"#!pip install boto3"
"%pip install --upgrade --quiet boto3"
]
},
{

View File

@@ -31,7 +31,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install boto3"
"%pip install --upgrade --quiet boto3"
]
},
{

View File

@@ -25,7 +25,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install azureml-fsspec, azure-ai-generative"
"%pip install --upgrade --quiet azureml-fsspec, azure-ai-generative"
]
},
{

View File

@@ -27,7 +27,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install azure-storage-blob"
"%pip install --upgrade --quiet azure-storage-blob"
]
},
{

View File

@@ -21,7 +21,7 @@
},
"outputs": [],
"source": [
"#!pip install azure-storage-blob"
"%pip install --upgrade --quiet azure-storage-blob"
]
},
{

View File

@@ -39,7 +39,7 @@
}
],
"source": [
"%pip install langchain langchain-community azure-ai-documentintelligence -q"
"%pip install --upgrade --quiet langchain langchain-community azure-ai-documentintelligence -q"
]
},
{

View File

@@ -32,7 +32,7 @@
},
"outputs": [],
"source": [
"#!pip install bibtexparser pymupdf"
"%pip install --upgrade --quiet bibtexparser pymupdf"
]
},
{

View File

@@ -23,7 +23,7 @@
},
"outputs": [],
"source": [
"#!pip install bilibili-api-python"
"%pip install --upgrade --quiet bilibili-api-python"
]
},
{

Some files were not shown because too many files have changed in this diff Show More