mirror of
https://github.com/hwchase17/langchain.git
synced 2026-04-20 13:28:53 +00:00
Compare commits
115 Commits
langchain-
...
langchain-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51fd70be63 | ||
|
|
7d2753fbd6 | ||
|
|
cfd11b2c34 | ||
|
|
8b7843b343 | ||
|
|
ffefaa6490 | ||
|
|
8ecef68b10 | ||
|
|
13a6847478 | ||
|
|
064b891454 | ||
|
|
d9813bdbbc | ||
|
|
7fc9e99e21 | ||
|
|
0f2b32ffa9 | ||
|
|
e32adad17a | ||
|
|
8a02fd9c01 | ||
|
|
1d98937e8d | ||
|
|
28ad244e77 | ||
|
|
c0dd293f10 | ||
|
|
54c85087e2 | ||
|
|
396c0aee4d | ||
|
|
feb351737c | ||
|
|
d87feb1b04 | ||
|
|
398718e1cb | ||
|
|
7feae62ad7 | ||
|
|
b993172702 | ||
|
|
17659ca2cd | ||
|
|
212c688ee0 | ||
|
|
979232257b | ||
|
|
4ffd27c4d0 | ||
|
|
16d41eab1e | ||
|
|
fa229d6c02 | ||
|
|
9cf7ae0a52 | ||
|
|
56580b5fff | ||
|
|
e235a572a0 | ||
|
|
bab9de581c | ||
|
|
3e48c728d5 | ||
|
|
76bce42629 | ||
|
|
bca51ca164 | ||
|
|
fa17b145bb | ||
|
|
181e4fc0e0 | ||
|
|
b3c7ed4913 | ||
|
|
042e84170b | ||
|
|
97a8e365ec | ||
|
|
1b3bd52e0e | ||
|
|
9bd4f1dfa8 | ||
|
|
2f80d67dc1 | ||
|
|
ffdc370200 | ||
|
|
5052e87d7c | ||
|
|
6e82d2184b | ||
|
|
262e19b15d | ||
|
|
854f37be87 | ||
|
|
a03141ac51 | ||
|
|
5c1ebd3086 | ||
|
|
de97d50644 | ||
|
|
1241a004cb | ||
|
|
4ba14ae9e5 | ||
|
|
dba308447d | ||
|
|
fdf6fbde18 | ||
|
|
576574c82c | ||
|
|
7bf54636ff | ||
|
|
3ec93c2817 | ||
|
|
af11fbfbf6 | ||
|
|
c812237217 | ||
|
|
c649b449d7 | ||
|
|
34fc00aff1 | ||
|
|
4b99426a4f | ||
|
|
bc3b851f08 | ||
|
|
0207dc1431 | ||
|
|
9eb9ff52c0 | ||
|
|
bc3b02651c | ||
|
|
ac922105ad | ||
|
|
0af447c90b | ||
|
|
f49da71e87 | ||
|
|
035d8cf51b | ||
|
|
1dfc8c01af | ||
|
|
fb642e1e27 | ||
|
|
7457949619 | ||
|
|
0c69c9fb3f | ||
|
|
fa8402ea09 | ||
|
|
fdeaff4149 | ||
|
|
c7154a4045 | ||
|
|
8d784db107 | ||
|
|
da113f6363 | ||
|
|
5b99bb2437 | ||
|
|
ef329f6819 | ||
|
|
f872c50b3f | ||
|
|
4833375200 | ||
|
|
78ff51ce83 | ||
|
|
150251fd49 | ||
|
|
64dfdaa924 | ||
|
|
933bc0d6ff | ||
|
|
51dae57357 | ||
|
|
66828f4ecc | ||
|
|
3145995ed9 | ||
|
|
a09e2afee4 | ||
|
|
6a8f8a56ac | ||
|
|
ab527027ac | ||
|
|
464dae8ac2 | ||
|
|
36bbdc776e | ||
|
|
f49cce739b | ||
|
|
96b99a5022 | ||
|
|
086556d466 | ||
|
|
1ff8c36aa6 | ||
|
|
6cd452d985 | ||
|
|
566e9ba164 | ||
|
|
d19e074374 | ||
|
|
7f857a02d5 | ||
|
|
38dfde6946 | ||
|
|
9cdb99bd60 | ||
|
|
8732cfc6ef | ||
|
|
08b9715845 | ||
|
|
60054db1c4 | ||
|
|
654da27255 | ||
|
|
f882824eac | ||
|
|
64b62f6ae4 | ||
|
|
0a752a74cc | ||
|
|
28e2ec7603 |
4
.github/scripts/check_diff.py
vendored
4
.github/scripts/check_diff.py
vendored
@@ -23,9 +23,6 @@ IGNORED_PARTNERS = [
|
||||
# specifically in huggingface jobs
|
||||
# https://github.com/langchain-ai/langchain/issues/25558
|
||||
"huggingface",
|
||||
# remove ai21 because of breaking changes in sdk version 2.14.0
|
||||
# that have not been fixed yet
|
||||
"ai21",
|
||||
]
|
||||
|
||||
|
||||
@@ -198,7 +195,6 @@ if __name__ == "__main__":
|
||||
dirs_to_run["test"].add("libs/partners/mistralai")
|
||||
dirs_to_run["test"].add("libs/partners/openai")
|
||||
dirs_to_run["test"].add("libs/partners/anthropic")
|
||||
dirs_to_run["test"].add("libs/partners/ai21")
|
||||
dirs_to_run["test"].add("libs/partners/fireworks")
|
||||
dirs_to_run["test"].add("libs/partners/groq")
|
||||
|
||||
|
||||
1
.github/workflows/_integration_test.yml
vendored
1
.github/workflows/_integration_test.yml
vendored
@@ -67,6 +67,7 @@ jobs:
|
||||
NVIDIA_API_KEY: ${{ secrets.NVIDIA_API_KEY }}
|
||||
GOOGLE_SEARCH_API_KEY: ${{ secrets.GOOGLE_SEARCH_API_KEY }}
|
||||
GOOGLE_CSE_ID: ${{ secrets.GOOGLE_CSE_ID }}
|
||||
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
|
||||
EXA_API_KEY: ${{ secrets.EXA_API_KEY }}
|
||||
NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }}
|
||||
WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }}
|
||||
|
||||
3
.github/workflows/_release.yml
vendored
3
.github/workflows/_release.yml
vendored
@@ -85,7 +85,7 @@ jobs:
|
||||
path: langchain
|
||||
sparse-checkout: | # this only grabs files for relevant dir
|
||||
${{ inputs.working-directory }}
|
||||
ref: master # this scopes to just master branch
|
||||
ref: ${{ github.ref }} # this scopes to just ref'd branch
|
||||
fetch-depth: 0 # this fetches entire commit history
|
||||
- name: Check Tags
|
||||
id: check-tags
|
||||
@@ -273,6 +273,7 @@ jobs:
|
||||
GOOGLE_SEARCH_API_KEY: ${{ secrets.GOOGLE_SEARCH_API_KEY }}
|
||||
GOOGLE_CSE_ID: ${{ secrets.GOOGLE_CSE_ID }}
|
||||
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
|
||||
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
|
||||
EXA_API_KEY: ${{ secrets.EXA_API_KEY }}
|
||||
NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }}
|
||||
WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }}
|
||||
|
||||
3
.github/workflows/codespell.yml
vendored
3
.github/workflows/codespell.yml
vendored
@@ -3,9 +3,8 @@ name: CI / cd . / make spell_check
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master, v0.1]
|
||||
branches: [master, v0.1, v0.2]
|
||||
pull_request:
|
||||
branches: [master, v0.1]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
3
.github/workflows/scheduled_test.yml
vendored
3
.github/workflows/scheduled_test.yml
vendored
@@ -25,7 +25,6 @@ jobs:
|
||||
- "libs/partners/fireworks"
|
||||
- "libs/partners/groq"
|
||||
- "libs/partners/mistralai"
|
||||
- "libs/partners/together"
|
||||
- "libs/partners/google-vertexai"
|
||||
- "libs/partners/google-genai"
|
||||
- "libs/partners/aws"
|
||||
@@ -91,8 +90,8 @@ jobs:
|
||||
AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME }}
|
||||
FIREWORKS_API_KEY: ${{ secrets.FIREWORKS_API_KEY }}
|
||||
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
|
||||
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
|
||||
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
|
||||
TOGETHER_API_KEY: ${{ secrets.TOGETHER_API_KEY }}
|
||||
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
|
||||
NVIDIA_API_KEY: ${{ secrets.NVIDIA_API_KEY }}
|
||||
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
|
||||
|
||||
@@ -49,7 +49,7 @@ For these applications, LangChain simplifies the entire application lifecycle:
|
||||
- **`langchain-community`**: Third party integrations.
|
||||
- Some integrations have been further split into **partner packages** that only rely on **`langchain-core`**. Examples include **`langchain_openai`** and **`langchain_anthropic`**.
|
||||
- **`langchain`**: Chains, agents, and retrieval strategies that make up an application's cognitive architecture.
|
||||
- **[`LangGraph`](https://langchain-ai.github.io/langgraph/)**: A library for building robust and stateful multi-actor applications with LLMs by modeling steps as edges and nodes in a graph. Integrates smoothly with LangChain, but can be used without it.
|
||||
- **[`LangGraph`](https://langchain-ai.github.io/langgraph/)**: A library for building robust and stateful multi-actor applications with LLMs by modeling steps as edges and nodes in a graph. Integrates smoothly with LangChain, but can be used without it. To learn more about LangGraph, check out our first LangChain Academy course, *Introduction to LangGraph*, available [here](https://academy.langchain.com/courses/intro-to-langgraph).
|
||||
|
||||
### Productionization:
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
"source": [
|
||||
"Connection is via `cassio` using `auto=True` parameter, and the notebook uses OpenAI. You should create a `.env` file accordingly.\n",
|
||||
"\n",
|
||||
"For Casssandra, set:\n",
|
||||
"For Cassandra, set:\n",
|
||||
"```bash\n",
|
||||
"CASSANDRA_CONTACT_POINTS\n",
|
||||
"CASSANDRA_USERNAME\n",
|
||||
|
||||
@@ -82,7 +82,7 @@ vercel-build: install-vercel-deps build generate-references
|
||||
mv $(OUTPUT_NEW_DOCS_DIR) docs
|
||||
rm -rf build
|
||||
mkdir static/api_reference
|
||||
git clone --depth=1 https://github.com/baskaryan/langchain-api-docs-build.git
|
||||
git clone --depth=1 -b v0.2 https://github.com/baskaryan/langchain-api-docs-build.git
|
||||
mv langchain-api-docs-build/api_reference_build/html/* static/api_reference/
|
||||
rm -rf langchain-api-docs-build
|
||||
NODE_OPTIONS="--max-old-space-size=5000" yarn run docusaurus build
|
||||
|
||||
1451
docs/data/people.yml
1451
docs/data/people.yml
File diff suppressed because it is too large
Load Diff
@@ -24,3 +24,16 @@ for more information.
|
||||
Notably, Github doesn't allow this setting to be enabled for forks in **organizations** ([issue](https://github.com/orgs/community/discussions/5634)).
|
||||
If you are working in an organization, we recommend submitting your PR from a personal
|
||||
fork in order to enable this setting.
|
||||
|
||||
### Why hasn't my PR been reviewed?
|
||||
|
||||
Please reference our [Review Process](/docs/contributing/review_process/).
|
||||
|
||||
### Why was my PR closed?
|
||||
|
||||
Please reference our [Review Process](/docs/contributing/review_process/).
|
||||
|
||||
### I think my PR was closed in a way that didn't follow the review process. What should I do?
|
||||
|
||||
Tag `@efriis` in the PR comments referencing the portion of the review
|
||||
process that you believe was not followed. We'll take a look!
|
||||
|
||||
95
docs/docs/contributing/review_process.mdx
Normal file
95
docs/docs/contributing/review_process.mdx
Normal file
@@ -0,0 +1,95 @@
|
||||
# Review Process
|
||||
|
||||
## Overview
|
||||
|
||||
This document outlines the process used by the LangChain maintainers for reviewing pull requests (PRs). The primary objective of this process is to enhance the LangChain developer experience.
|
||||
|
||||
## Review Statuses
|
||||
|
||||
We categorize PRs using three main statuses, which are marked as project item statuses in the right sidebar and can be viewed in detail [here](https://github.com/orgs/langchain-ai/projects/12/views/1).
|
||||
|
||||
- **Triage**:
|
||||
- Initial status for all newly submitted PRs.
|
||||
- Requires a maintainer to categorize it into one of the other statuses.
|
||||
|
||||
- **Needs Support**:
|
||||
- PRs that require community feedback or additional input before moving forward.
|
||||
- Automatically promoted to the backlog if it receives 5 upvotes.
|
||||
- An auto-comment is generated when this status is applied, explaining the flow and the upvote requirement.
|
||||
- If the PR remains in this status for 25 days, it will be marked as “stale” via auto-comment.
|
||||
- PRs will be auto-closed after 30 days if no further action is taken.
|
||||
|
||||
- **In Review**:
|
||||
- PRs that are actively under review by our team.
|
||||
- These are regularly reviewed and monitored.
|
||||
|
||||
**Note:** A PR may only have one status at a time.
|
||||
|
||||
**Note:** You may notice 3 additional statuses of Done, Closed, and Internal that
|
||||
are external to this lifecycle. Done and Closed PRs have been merged or closed,
|
||||
respectively. Internal is for PRs submitted by core maintainers, and these PRs are owned
|
||||
by the submitter.
|
||||
|
||||
## Review Guidelines
|
||||
|
||||
1. **PRs that touch /libs/core**:
|
||||
- PRs that directly impact core code and are likely to affect end users.
|
||||
- **Triage Guideline**: most PRs should either go straight to `In Review` or closed.
|
||||
- These PRs are given top priority and are reviewed the fastest.
|
||||
- PRs that don't have a **concise** descriptions of their motivation (either in PR summary of in a linked issue) are likely to be closed without an in-depth review. Please do not generate verbose PR descriptions with an LLM.
|
||||
- PRs that don't have unit tests are likely to be closed.
|
||||
- Feature requests should first be opened as a GitHub issue and discussed with the LangChain maintainers. Large PRs submitted without prior discussion are likely to be closed.
|
||||
|
||||
2. **PRs that touch /libs/langchain**:
|
||||
- High-impact PRs that are closely related to core PRs but slightly lower in priority.
|
||||
- **Triage Guideline**: most PRs should either go straight to `In Review` or closed.
|
||||
- These are reviewed and closed aggressively, similar to core PRs.
|
||||
- New feature requests should be discussed with the core maintainer team beforehand in an issue.
|
||||
|
||||
3. **PRs that touch /libs/partners/****:
|
||||
- PRs involving integration packages.
|
||||
- **Triage Guideline**: most PRs should either go straight to `In Review` or closed.
|
||||
- The review may be conducted by our team or handed off to the partner's development team, depending on the PR's content.
|
||||
- We maintain communication lines with most partner dev teams to facilitate this process.
|
||||
|
||||
4. **Community PRs**:
|
||||
- Most community PRs will get an initial status of "needs support".
|
||||
- **Triage Guideline**: most PRs should go to `Needs support`. Bugfixes on high-traffic integrations should go straight to `In review`.
|
||||
- **Triage Guideline**: all new features and integrations should go to `Needs support` and will be closed if they do not get enough support (measured by upvotes or comments).
|
||||
- PRs in the `Needs Support` status for 20 days are marked as “stale” and will be closed after 30 days if no action is taken.
|
||||
|
||||
5. **Documentation PRs**:
|
||||
- PRs that touch the documentation content in docs/docs.
|
||||
- **Triage Guideline**:
|
||||
- PRs that fix typos or small errors in a single file and pass CI should go straight to `In Review`.
|
||||
- PRs that make changes that have been discussed and agreed upon in an issue should go straight to `In Review`.
|
||||
- PRs that add new pages or change the structure of the documentation should go to `Needs Support`.
|
||||
- We strive to standardize documentation formats to streamline the review process.
|
||||
- CI jobs run against documentation to ensure adherence to standards, automating much of the review.
|
||||
|
||||
6. **PRs must be in English**:
|
||||
- PRs that are not in English will be closed without review.
|
||||
- This is to ensure that all maintainers can review the PRs effectively.
|
||||
|
||||
## How to see a PR's status
|
||||
|
||||
See screenshot:
|
||||
|
||||

|
||||
|
||||
*To see the status of all open PRs, please visit the [LangChain Project Board](https://github.com/orgs/langchain-ai/projects/12/views/2).*
|
||||
|
||||
## Review Prioritization
|
||||
|
||||
Our goal is to provide the best possible development experience by focusing on making software that:
|
||||
|
||||
- Works: Works as intended (is bug-free).
|
||||
- Is useful: Improves LLM app development with components that work off-the-shelf and runtimes that simplify app building.
|
||||
- Is easy: Is intuitive to use and well-documented.
|
||||
|
||||
We believe this process reflects our priorities and are open to feedback if you feel it does not.
|
||||
|
||||
## Github Discussion
|
||||
|
||||
We welcome your feedback on this process. Please feel free to add a comment in
|
||||
[this GitHub Discussion](https://github.com/langchain-ai/langchain/discussions/25920).
|
||||
@@ -461,7 +461,7 @@
|
||||
"id": "f8014c9d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now, we can initalize the agent with the LLM, the prompt, and the tools. The agent is responsible for taking in input and deciding what actions to take. Crucially, the Agent does not execute those actions - that is done by the AgentExecutor (next step). For more information about how to think about these components, see our [conceptual guide](/docs/concepts/#agents).\n",
|
||||
"Now, we can initialize the agent with the LLM, the prompt, and the tools. The agent is responsible for taking in input and deciding what actions to take. Crucially, the Agent does not execute those actions - that is done by the AgentExecutor (next step). For more information about how to think about these components, see our [conceptual guide](/docs/concepts/#agents).\n",
|
||||
"\n",
|
||||
"Note that we are passing in the `model`, not `model_with_tools`. That is because `create_tool_calling_agent` will call `.bind_tools` for us under the hood."
|
||||
]
|
||||
|
||||
@@ -8,7 +8,7 @@ The Embeddings class is a class designed for interfacing with text embedding mod
|
||||
|
||||
Embeddings create a vector representation of a piece of text. This is useful because it means we can think about text in the vector space, and do things like semantic search where we look for pieces of text that are most similar in the vector space.
|
||||
|
||||
The base Embeddings class in LangChain provides two methods: one for embedding documents and one for embedding a query. The former, `.embed_documents`, takes as input multiple texts, while the latter, `.embed_query`, takes a single text. The reason for having these as two separate methods is that some embedding providers have different embedding methods for documents (to be searched over) vs queries (the search query itself).
|
||||
The base Embeddings class in LangChain provides two methods: one for embedding documents and one for embedding a query. The former, `.embed_documents`, takes as input multiple texts, while the latter, `.embed_query`, takes a single text. The reason for having these as two separate methods is that some embedding providers have different embedding methods for documents (to be searched over) vs queries (the search query itself).
|
||||
`.embed_query` will return a list of floats, whereas `.embed_documents` returns a list of lists of floats.
|
||||
|
||||
## Get started
|
||||
@@ -94,15 +94,6 @@ from langchain_huggingface import HuggingFaceEmbeddings
|
||||
|
||||
embeddings_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
|
||||
```
|
||||
|
||||
You can also leave the `model_name` blank to use the default [sentence-transformers/all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2) model.
|
||||
|
||||
```python
|
||||
from langchain_huggingface import HuggingFaceEmbeddings
|
||||
|
||||
embeddings_model = HuggingFaceEmbeddings()
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"\n",
|
||||
"## Architecture\n",
|
||||
"\n",
|
||||
"At a high-level, the steps of constructing a knowledge are from text are:\n",
|
||||
"At a high-level, the steps of constructing a knowledge graph from text are:\n",
|
||||
"\n",
|
||||
"1. **Extracting structured information from text**: Model is used to extract structured graph information from text.\n",
|
||||
"2. **Storing into graph database**: Storing the extracted structured graph information into a graph database enables downstream RAG applications\n",
|
||||
|
||||
@@ -9,7 +9,7 @@ functionality to install.
|
||||
|
||||
## Official release
|
||||
|
||||
To install the main LangChain package, run:
|
||||
To install the main `langchain` package, run:
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
@@ -26,8 +26,7 @@ import CodeBlock from "@theme/CodeBlock";
|
||||
|
||||
While this package acts as a sane starting point to using LangChain,
|
||||
much of the value of LangChain comes when integrating it with various model providers, datastores, etc.
|
||||
By default, the dependencies needed to do that are NOT installed. You will need to install the dependencies for specific integrations separately.
|
||||
We'll show how to do that in the next sections of this guide.
|
||||
By default, the dependencies needed to do that are NOT installed. You will need to install the dependencies for specific integrations separately, which we show below.
|
||||
|
||||
## Ecosystem packages
|
||||
|
||||
@@ -41,14 +40,6 @@ When installing a package, you do not need to explicitly install that package's
|
||||
However, you may choose to if you are using a feature only available in a certain version of that dependency.
|
||||
If you do, you should make sure that the installed or pinned version is compatible with any other integration packages you use.
|
||||
|
||||
### From source
|
||||
|
||||
If you want to install from source, you can do so by cloning the repo and be sure that the directory is `PATH/TO/REPO/langchain/libs/langchain` running:
|
||||
|
||||
```bash
|
||||
pip install -e .
|
||||
```
|
||||
|
||||
### LangChain core
|
||||
The `langchain-core` package contains base abstractions that the rest of the LangChain ecosystem uses, along with the LangChain Expression Language. It is automatically installed by `langchain`, but can also be used separately. Install with:
|
||||
|
||||
@@ -56,8 +47,18 @@ The `langchain-core` package contains base abstractions that the rest of the Lan
|
||||
pip install langchain-core
|
||||
```
|
||||
|
||||
### LangChain community
|
||||
The `langchain-community` package contains third-party integrations. Install with:
|
||||
### Integration packages
|
||||
|
||||
Certain integrations like OpenAI and Anthropic have their own packages.
|
||||
Any integrations that require their own package will be documented as such in the [Integration docs](/docs/integrations/platforms/).
|
||||
You can see a list of all integration packages in the [API reference](https://api.python.langchain.com) under the "Partner libs" dropdown.
|
||||
To install one of these run:
|
||||
|
||||
```bash
|
||||
pip install langchain-openai
|
||||
```
|
||||
|
||||
Any integrations that haven't been split out into their own packages will live in the `langchain-community` package. Install with:
|
||||
|
||||
```bash
|
||||
pip install langchain-community
|
||||
@@ -89,7 +90,7 @@ pip install "langserve[all]"
|
||||
```
|
||||
for both client and server dependencies. Or `pip install "langserve[client]"` for client code, and `pip install "langserve[server]"` for server code.
|
||||
|
||||
## LangChain CLI
|
||||
### LangChain CLI
|
||||
The LangChain CLI is useful for working with LangChain templates and other LangServe projects.
|
||||
Install with:
|
||||
|
||||
@@ -105,3 +106,13 @@ If you are not using LangChain, you can install it with:
|
||||
```bash
|
||||
pip install langsmith
|
||||
```
|
||||
|
||||
### From source
|
||||
|
||||
If you want to install a package from source, you can do so by cloning the [main LangChain repo](https://github.com/langchain-ai/langchain), enter the directory of the package you want to install `PATH/TO/REPO/langchain/libs/{package}`, and run:
|
||||
|
||||
```bash
|
||||
pip install -e .
|
||||
```
|
||||
|
||||
LangGraph, LangSmith SDK, and certain integration packages live outside the main LangChain repo. You can see [all repos here](https://github.com/langchain-ai).
|
||||
@@ -14,7 +14,7 @@
|
||||
"- [How to use a model to call tools](/docs/how_to/tool_calling)\n",
|
||||
":::\n",
|
||||
"\n",
|
||||
"In order to force our LLM to spelect a specific tool, we can use the `tool_choice` parameter to ensure certain behavior. First, let's define our model and tools:"
|
||||
"In order to force our LLM to select a specific tool, we can use the `tool_choice` parameter to ensure certain behavior. First, let's define our model and tools:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -129,13 +129,13 @@
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def count_emails(last_n_days: int) -> int:\n",
|
||||
" \"\"\"Multiply two integers together.\"\"\"\n",
|
||||
" \"\"\"Dummy function to count number of e-mails. Returns 2 * last_n_days.\"\"\"\n",
|
||||
" return last_n_days * 2\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def send_email(message: str, recipient: str) -> str:\n",
|
||||
" \"Add two integers.\"\n",
|
||||
" \"\"\"Dummy function for sending an e-mail.\"\"\"\n",
|
||||
" return f\"Successfully sent email to {recipient}.\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -50,18 +50,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "62e0dbc3",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"from getpass import getpass\n",
|
||||
"\n",
|
||||
"os.environ[\"AI21_API_KEY\"] = getpass()"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -73,14 +73,14 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7c2e19d3-7c58-4470-9e1a-718b27a32056",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
|
||||
"# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass(\"Enter your LangSmith API key: \")"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -115,15 +115,15 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "c40756fb-cbf8-4d44-a293-3989d707237e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_ai21 import ChatAI21\n",
|
||||
"\n",
|
||||
"llm = ChatAI21(model=\"jamba-instruct\", temperature=0)"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -135,21 +135,8 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "46b982dc-5d8a-46da-a711-81c03ccd6adc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"AIMessage(content=\"J'adore programmer.\", id='run-2e8d16d6-a06e-45cb-8d0c-1c8208645033-0')"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"messages = [\n",
|
||||
" (\n",
|
||||
@@ -160,7 +147,9 @@
|
||||
"]\n",
|
||||
"ai_msg = llm.invoke(messages)\n",
|
||||
"ai_msg"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -174,7 +163,6 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "39353473fce5dd2e",
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
@@ -182,18 +170,6 @@
|
||||
"outputs_hidden": false
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"AIMessage(content='Ich liebe das Programmieren.', id='run-e1bd82dc-1a7e-4b2e-bde9-ac995929ac0f-0')"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"\n",
|
||||
@@ -215,7 +191,95 @@
|
||||
" \"input\": \"I love programming.\",\n",
|
||||
" }\n",
|
||||
")"
|
||||
]
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "markdown",
|
||||
"source": "# Tool Calls / Function Calling",
|
||||
"id": "39c0ccd229927eab"
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "markdown",
|
||||
"source": "This example shows how to use tool calling with AI21 models:",
|
||||
"id": "2bf6b40be07fe2d4"
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"import os\n",
|
||||
"from getpass import getpass\n",
|
||||
"\n",
|
||||
"from langchain_ai21.chat_models import ChatAI21\n",
|
||||
"from langchain_core.messages import HumanMessage, SystemMessage, ToolMessage\n",
|
||||
"from langchain_core.tools import tool\n",
|
||||
"from langchain_core.utils.function_calling import convert_to_openai_tool\n",
|
||||
"\n",
|
||||
"os.environ[\"AI21_API_KEY\"] = getpass()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def get_weather(location: str, date: str) -> str:\n",
|
||||
" \"\"\"“Provide the weather for the specified location on the given date.”\"\"\"\n",
|
||||
" if location == \"New York\" and date == \"2024-12-05\":\n",
|
||||
" return \"25 celsius\"\n",
|
||||
" elif location == \"New York\" and date == \"2024-12-06\":\n",
|
||||
" return \"27 celsius\"\n",
|
||||
" elif location == \"London\" and date == \"2024-12-05\":\n",
|
||||
" return \"22 celsius\"\n",
|
||||
" return \"32 celsius\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"llm = ChatAI21(model=\"jamba-1.5-mini\")\n",
|
||||
"\n",
|
||||
"llm_with_tools = llm.bind_tools([convert_to_openai_tool(get_weather)])\n",
|
||||
"\n",
|
||||
"chat_messages = [\n",
|
||||
" SystemMessage(\n",
|
||||
" content=\"You are a helpful assistant. You can use the provided tools \"\n",
|
||||
" \"to assist with various tasks and provide accurate information\"\n",
|
||||
" )\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"human_messages = [\n",
|
||||
" HumanMessage(\n",
|
||||
" content=\"What is the forecast for the weather in New York on December 5, 2024?\"\n",
|
||||
" ),\n",
|
||||
" HumanMessage(content=\"And what about the 2024-12-06?\"),\n",
|
||||
" HumanMessage(content=\"OK, thank you.\"),\n",
|
||||
" HumanMessage(content=\"What is the expected weather in London on December 5, 2024?\"),\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"for human_message in human_messages:\n",
|
||||
" print(f\"User: {human_message.content}\")\n",
|
||||
" chat_messages.append(human_message)\n",
|
||||
" response = llm_with_tools.invoke(chat_messages)\n",
|
||||
" chat_messages.append(response)\n",
|
||||
" if response.tool_calls:\n",
|
||||
" tool_call = response.tool_calls[0]\n",
|
||||
" if tool_call[\"name\"] == \"get_weather\":\n",
|
||||
" weather = get_weather.invoke(\n",
|
||||
" {\n",
|
||||
" \"location\": tool_call[\"args\"][\"location\"],\n",
|
||||
" \"date\": tool_call[\"args\"][\"date\"],\n",
|
||||
" }\n",
|
||||
" )\n",
|
||||
" chat_messages.append(\n",
|
||||
" ToolMessage(content=weather, tool_call_id=tool_call[\"id\"])\n",
|
||||
" )\n",
|
||||
" llm_answer = llm_with_tools.invoke(chat_messages)\n",
|
||||
" print(f\"Assistant: {llm_answer.content}\")\n",
|
||||
" else:\n",
|
||||
" print(f\"Assistant: {response.content}\")"
|
||||
],
|
||||
"id": "a181a28df77120fb",
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"\n",
|
||||
"::: {.callout-warning}\n",
|
||||
"\n",
|
||||
"The Anthropic API officially supports tool-calling so this workaround is no longer needed. Please use [ChatAnthropic](/docs/integrations/chat/anthropic) with `langchain-anthropic>=0.1.5`.\n",
|
||||
"The Anthropic API officially supports tool-calling so this workaround is no longer needed. Please use [ChatAnthropic](/docs/integrations/chat/anthropic) with `langchain-anthropic>=0.1.15`.\n",
|
||||
"\n",
|
||||
":::\n",
|
||||
"\n",
|
||||
|
||||
@@ -404,6 +404,7 @@
|
||||
" max_new_tokens=512,\n",
|
||||
" do_sample=False,\n",
|
||||
" repetition_penalty=1.03,\n",
|
||||
" return_full_text=False,\n",
|
||||
" ),\n",
|
||||
" model_kwargs={\"quantization_config\": quantization_config},\n",
|
||||
")\n",
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The ScrapflyLoader also allows passigng ScrapeConfig object for customizing the scrape request. See the documentation for the full feature details and their API params: https://scrapfly.io/docs/scrape-api/getting-started"
|
||||
"The ScrapflyLoader also allows passing ScrapeConfig object for customizing the scrape request. See the documentation for the full feature details and their API params: https://scrapfly.io/docs/scrape-api/getting-started"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -6,16 +6,272 @@
|
||||
"source": [
|
||||
"# IPEX-LLM\n",
|
||||
"\n",
|
||||
"> [IPEX-LLM](https://github.com/intel-analytics/ipex-llm/) is a PyTorch library for running LLM on Intel CPU and GPU (e.g., local PC with iGPU, discrete GPU such as Arc, Flex and Max) with very low latency. \n",
|
||||
"> [IPEX-LLM](https://github.com/intel-analytics/ipex-llm) is a PyTorch library for running LLM on Intel CPU and GPU (e.g., local PC with iGPU, discrete GPU such as Arc, Flex and Max) with very low latency.\n",
|
||||
"\n",
|
||||
"This example goes over how to use LangChain to interact with `ipex-llm` for text generation. \n"
|
||||
"- [IPEX-LLM on Intel GPU](#ipex-llm-on-intel-gpu)\n",
|
||||
"- [IPEX-LLM on Intel CPU](#ipex-llm-on-intel-cpu)\n",
|
||||
"\n",
|
||||
"## IPEX-LLM on Intel GPU\n",
|
||||
"\n",
|
||||
"This example goes over how to use LangChain to interact with `ipex-llm` for text generation on Intel GPU. \n",
|
||||
"\n",
|
||||
"> **Note**\n",
|
||||
">\n",
|
||||
"> It is recommended that only Windows users with Intel Arc A-Series GPU (except for Intel Arc A300-Series or Pro A60) run Jupyter notebook directly for section \"IPEX-LLM on Intel GPU\". For other cases (e.g. Linux users, Intel iGPU, etc.), it is recommended to run the code with Python scripts in terminal for best experiences.\n",
|
||||
"\n",
|
||||
"### Install Prerequisites\n",
|
||||
"To benefit from IPEX-LLM on Intel GPUs, there are several prerequisite steps for tools installation and environment preparation.\n",
|
||||
"\n",
|
||||
"If you are a Windows user, visit the [Install IPEX-LLM on Windows with Intel GPU Guide](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_windows_gpu.md), and follow [Install Prerequisites](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_windows_gpu.md#install-prerequisites) to update GPU driver (optional) and install Conda.\n",
|
||||
"\n",
|
||||
"If you are a Linux user, visit the [Install IPEX-LLM on Linux with Intel GPU](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_linux_gpu.md), and follow [**Install Prerequisites**](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_linux_gpu.md#install-prerequisites) to install GPU driver, Intel® oneAPI Base Toolkit 2024.0, and Conda.\n",
|
||||
"\n",
|
||||
"### Setup\n",
|
||||
"\n",
|
||||
"After the prerequisites installation, you should have created a conda environment with all prerequisites installed. **Start the jupyter service in this conda environment**:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -qU langchain langchain-community"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Setup"
|
||||
"Install IEPX-LLM for running LLMs locally on Intel GPU."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install --pre --upgrade ipex-llm[xpu] --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"> **Note**\n",
|
||||
">\n",
|
||||
"> You can also use `https://pytorch-extension.intel.com/release-whl/stable/xpu/cn/` as the extra-indel-url.\n",
|
||||
"\n",
|
||||
"### Runtime Configuration\n",
|
||||
"\n",
|
||||
"For optimal performance, it is recommended to set several environment variables based on your device:\n",
|
||||
"\n",
|
||||
"#### For Windows Users with Intel Core Ultra integrated GPU"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"os.environ[\"SYCL_CACHE_PERSISTENT\"] = \"1\"\n",
|
||||
"os.environ[\"BIGDL_LLM_XMX_DISABLED\"] = \"1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### For Windows Users with Intel Arc A-Series GPU"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"os.environ[\"SYCL_CACHE_PERSISTENT\"] = \"1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"> **Note**\n",
|
||||
">\n",
|
||||
"> For the first time that each model runs on Intel iGPU/Intel Arc A300-Series or Pro A60, it may take several minutes to compile.\n",
|
||||
">\n",
|
||||
"> For other GPU type, please refer to [here](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Overview/install_gpu.md#runtime-configuration) for Windows users, and [here](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Overview/install_gpu.md#runtime-configuration-1) for Linux users.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Basic Usage\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import warnings\n",
|
||||
"\n",
|
||||
"from langchain.chains import LLMChain\n",
|
||||
"from langchain_community.llms import IpexLLM\n",
|
||||
"from langchain_core.prompts import PromptTemplate\n",
|
||||
"\n",
|
||||
"warnings.filterwarnings(\"ignore\", category=UserWarning, message=\".*padding_mask.*\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Specify the prompt template for your model. In this example, we use the [vicuna-1.5](https://huggingface.co/lmsys/vicuna-7b-v1.5) model. If you're working with a different model, choose a proper template accordingly."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"template = \"USER: {question}\\nASSISTANT:\"\n",
|
||||
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Load the model locally using IpexLLM using `IpexLLM.from_model_id`. It will load the model directly in its Huggingface format and convert it automatically to low-bit format for inference. Set `device` to `\"xpu\"` in `model_kwargs` when initializing IpexLLM in order to load the LLM model to Intel GPU."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"llm = IpexLLM.from_model_id(\n",
|
||||
" model_id=\"lmsys/vicuna-7b-v1.5\",\n",
|
||||
" model_kwargs={\n",
|
||||
" \"temperature\": 0,\n",
|
||||
" \"max_length\": 64,\n",
|
||||
" \"trust_remote_code\": True,\n",
|
||||
" \"device\": \"xpu\",\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Use it in Chains"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"llm_chain = prompt | llm\n",
|
||||
"\n",
|
||||
"question = \"What is AI?\"\n",
|
||||
"output = llm_chain.invoke(question)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Save/Load Low-bit Model\n",
|
||||
"Alternatively, you might save the low-bit model to disk once and use `from_model_id_low_bit` instead of `from_model_id` to reload it for later use - even across different machines. It is space-efficient, as the low-bit model demands significantly less disk space than the original model. And `from_model_id_low_bit` is also more efficient than `from_model_id` in terms of speed and memory usage, as it skips the model conversion step. You can similarly set `device` to `\"xpu\"` in `model_kwargs` in order to load the LLM model to Intel GPU. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"To save the low-bit model, use `save_low_bit` as follows."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saved_lowbit_model_path = \"./vicuna-7b-1.5-low-bit\" # path to save low-bit model\n",
|
||||
"llm.model.save_low_bit(saved_lowbit_model_path)\n",
|
||||
"del llm"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Load the model from saved lowbit model path as follows. \n",
|
||||
"> Note that the saved path for the low-bit model only includes the model itself but not the tokenizers. If you wish to have everything in one place, you will need to manually download or copy the tokenizer files from the original model's directory to the location where the low-bit model is saved."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"llm_lowbit = IpexLLM.from_model_id_low_bit(\n",
|
||||
" model_id=saved_lowbit_model_path,\n",
|
||||
" tokenizer_id=\"lmsys/vicuna-7b-v1.5\",\n",
|
||||
" # tokenizer_name=saved_lowbit_model_path, # copy the tokenizers to saved path if you want to use it this way\n",
|
||||
" model_kwargs={\n",
|
||||
" \"temperature\": 0,\n",
|
||||
" \"max_length\": 64,\n",
|
||||
" \"trust_remote_code\": True,\n",
|
||||
" \"device\": \"xpu\",\n",
|
||||
" },\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Use the loaded model in Chains:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"llm_chain = prompt | llm_lowbit\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"question = \"What is AI?\"\n",
|
||||
"output = llm_chain.invoke(question)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## IPEX-LLM on Intel CPU\n",
|
||||
"\n",
|
||||
"This example goes over how to use LangChain to interact with `ipex-llm` for text generation on Intel CPU.\n",
|
||||
"\n",
|
||||
"### Setup"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -33,7 +289,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Install IEPX-LLM for running LLMs locally on Intel CPU."
|
||||
"Install IEPX-LLM for running LLMs locally on Intel CPU:\n",
|
||||
"\n",
|
||||
"#### For Windows users:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -49,7 +307,23 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Basic Usage"
|
||||
"#### For Linux users:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install --pre --upgrade ipex-llm[all] --extra-index-url https://download.pytorch.org/whl/cpu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Basic Usage"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -126,15 +400,11 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Save/Load Low-bit Model\n",
|
||||
"Alternatively, you might save the low-bit model to disk once and use `from_model_id_low_bit` instead of `from_model_id` to reload it for later use - even across different machines. It is space-efficient, as the low-bit model demands significantly less disk space than the original model. And `from_model_id_low_bit` is also more efficient than `from_model_id` in terms of speed and memory usage, as it skips the model conversion step."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"To save the low-bit model, use `save_low_bit` as follows."
|
||||
"### Save/Load Low-bit Model\n",
|
||||
"\n",
|
||||
"Alternatively, you might save the low-bit model to disk once and use `from_model_id_low_bit` instead of `from_model_id` to reload it for later use - even across different machines. It is space-efficient, as the low-bit model demands significantly less disk space than the original model. And `from_model_id_low_bit` is also more efficient than `from_model_id` in terms of speed and memory usage, as it skips the model conversion step.\n",
|
||||
"\n",
|
||||
"To save the low-bit model, use `save_low_bit` as follows:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -152,7 +422,8 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Load the model from saved lowbit model path as follows. \n",
|
||||
"Load the model from saved lowbit model path as follows.\n",
|
||||
"\n",
|
||||
"> Note that the saved path for the low-bit model only includes the model itself but not the tokenizers. If you wish to have everything in one place, you will need to manually download or copy the tokenizer files from the original model's directory to the location where the low-bit model is saved."
|
||||
]
|
||||
},
|
||||
@@ -192,22 +463,8 @@
|
||||
}
|
||||
],
|
||||
"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.5"
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -58,7 +58,7 @@ The value of image_url can be any of the following:
|
||||
|
||||
### Vertex AI
|
||||
|
||||
Access PaLM chat models like `chat-bison` and `codechat-bison` via Google Cloud.
|
||||
Access chat models like `Gemini` via Google Cloud.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
@@ -72,7 +72,7 @@ See a [usage example](/docs/integrations/chat/google_vertex_ai_palm).
|
||||
from langchain_google_vertexai import ChatVertexAI
|
||||
```
|
||||
|
||||
### Chat Anthropic on Vertex AI
|
||||
### Chat Anthropic on Vertex AI Model Garden
|
||||
|
||||
See a [usage example](/docs/integrations/llms/google_vertex_ai_palm).
|
||||
|
||||
@@ -80,6 +80,114 @@ See a [usage example](/docs/integrations/llms/google_vertex_ai_palm).
|
||||
from langchain_google_vertexai.model_garden import ChatAnthropicVertex
|
||||
```
|
||||
|
||||
### Chat Llama on Vertex AI Model Garden
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.model_garden_maas.llama import VertexModelGardenLlama
|
||||
```
|
||||
|
||||
### Chat Mistral on Vertex AI Model Garden
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.model_garden_maas.mistral import VertexModelGardenMistral
|
||||
```
|
||||
|
||||
### Chat Gemma local from Hugging Face
|
||||
|
||||
>Local `Gemma` model loaded from `HuggingFace`.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaChatLocalHF
|
||||
```
|
||||
|
||||
### Chat Gemma local from Kaggle
|
||||
|
||||
>Local `Gemma` model loaded from `Kaggle`.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaChatLocalKaggle
|
||||
```
|
||||
|
||||
### Chat Gemma on Vertex AI Model Garden
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaChatVertexAIModelGarden
|
||||
```
|
||||
|
||||
### Vertex AI image captioning chat
|
||||
|
||||
>Implementation of the `Image Captioning model` as a chat.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIImageCaptioningChat
|
||||
```
|
||||
|
||||
### Vertex AI image editor chat
|
||||
|
||||
>Given an image and a prompt, edit the image. Currently only supports mask-free editing.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIImageEditorChat
|
||||
```
|
||||
|
||||
### Vertex AI image generator chat
|
||||
|
||||
>Generates an image from a prompt.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIImageGeneratorChat
|
||||
```
|
||||
|
||||
### Vertex AI visual QnA chat
|
||||
|
||||
>Chat implementation of a visual QnA model
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIVisualQnAChat
|
||||
```
|
||||
|
||||
## LLMs
|
||||
|
||||
### Google Generative AI
|
||||
@@ -114,9 +222,63 @@ See a [usage example](/docs/integrations/llms/google_vertex_ai_palm#vertex-model
|
||||
from langchain_google_vertexai import VertexAIModelGarden
|
||||
```
|
||||
|
||||
### Gemma local from Hugging Face
|
||||
|
||||
>Local `Gemma` model loaded from `HuggingFace`.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaLocalHF
|
||||
```
|
||||
|
||||
### Gemma local from Kaggle
|
||||
|
||||
>Local `Gemma` model loaded from `Kaggle`.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaLocalKaggle
|
||||
```
|
||||
|
||||
### Gemma on Vertex AI Model Garden
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.gemma import GemmaVertexAIModelGarden
|
||||
```
|
||||
|
||||
### Vertex AI image captioning
|
||||
|
||||
>Implementation of the `Image Captioning model` as an LLM.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.vision_models import VertexAIImageCaptioning
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
### Google Generative AI Embeddings
|
||||
### Google Generative AI embedding
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/google_generative_ai).
|
||||
|
||||
@@ -134,6 +296,18 @@ export GOOGLE_API_KEY=your-api-key
|
||||
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
||||
```
|
||||
|
||||
### Google Generative AI server-side embedding
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
pip install langchain-google-genai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_genai.google_vector_store import ServerSideEmbedding
|
||||
```
|
||||
|
||||
### Vertex AI
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
@@ -148,7 +322,7 @@ See a [usage example](/docs/integrations/text_embedding/google_vertex_ai_palm).
|
||||
from langchain_google_vertexai import VertexAIEmbeddings
|
||||
```
|
||||
|
||||
### Palm Embedding
|
||||
### Palm embedding
|
||||
|
||||
We need to install `langchain-community` python package.
|
||||
|
||||
@@ -197,6 +371,7 @@ from langchain_google_community import BigQueryLoader
|
||||
### Bigtable
|
||||
|
||||
> [Google Cloud Bigtable](https://cloud.google.com/bigtable/docs) is Google's fully managed NoSQL Big Data database service in Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -212,6 +387,7 @@ from langchain_google_bigtable import BigtableLoader
|
||||
### Cloud SQL for MySQL
|
||||
|
||||
> [Google Cloud SQL for MySQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your MySQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -221,12 +397,13 @@ pip install langchain-google-cloud-sql-mysql
|
||||
See [usage example](/docs/integrations/document_loaders/google_cloud_sql_mysql).
|
||||
|
||||
```python
|
||||
from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLDocumentLoader
|
||||
from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLLoader
|
||||
```
|
||||
|
||||
### Cloud SQL for SQL Server
|
||||
|
||||
> [Google Cloud SQL for SQL Server](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your SQL Server databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -242,6 +419,7 @@ from langchain_google_cloud_sql_mssql import MSSQLEngine, MSSQLLoader
|
||||
### Cloud SQL for PostgreSQL
|
||||
|
||||
> [Google Cloud SQL for PostgreSQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your PostgreSQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -326,6 +504,7 @@ from langchain_google_community import GoogleDriveLoader
|
||||
### Firestore (Native Mode)
|
||||
|
||||
> [Google Cloud Firestore](https://cloud.google.com/firestore/docs/) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -342,6 +521,7 @@ from langchain_google_firestore import FirestoreLoader
|
||||
|
||||
> [Google Cloud Firestore in Datastore mode](https://cloud.google.com/datastore/docs) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
> Firestore is the newest version of Datastore and introduces several improvements over Datastore.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -357,6 +537,7 @@ from langchain_google_datastore import DatastoreLoader
|
||||
### Memorystore for Redis
|
||||
|
||||
> [Google Cloud Memorystore for Redis](https://cloud.google.com/memorystore/docs/redis) is a fully managed Redis service for Google Cloud. Applications running on Google Cloud can achieve extreme performance by leveraging the highly scalable, available, secure Redis service without the burden of managing complex Redis deployments.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -366,12 +547,13 @@ pip install langchain-google-memorystore-redis
|
||||
See [usage example](/docs/integrations/document_loaders/google_memorystore_redis).
|
||||
|
||||
```python
|
||||
from langchain_google_memorystore_redis import MemorystoreLoader
|
||||
from langchain_google_memorystore_redis import MemorystoreDocumentLoader
|
||||
```
|
||||
|
||||
### Spanner
|
||||
|
||||
> [Google Cloud Spanner](https://cloud.google.com/spanner/docs) is a fully managed, mission-critical, relational database service on Google Cloud that offers transactional consistency at global scale, automatic, synchronous replication for high availability, and support for two SQL dialects: GoogleSQL (ANSI 2011 with extensions) and PostgreSQL.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -490,6 +672,7 @@ from langchain.vectorstores import BigQueryVectorSearch
|
||||
### Memorystore for Redis
|
||||
|
||||
> [Google Cloud Memorystore for Redis](https://cloud.google.com/memorystore/docs/redis) is a fully managed Redis service for Google Cloud. Applications running on Google Cloud can achieve extreme performance by leveraging the highly scalable, available, secure Redis service without the burden of managing complex Redis deployments.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -505,6 +688,7 @@ from langchain_google_memorystore_redis import RedisVectorStore
|
||||
### Spanner
|
||||
|
||||
> [Google Cloud Spanner](https://cloud.google.com/spanner/docs) is a fully managed, mission-critical, relational database service on Google Cloud that offers transactional consistency at global scale, automatic, synchronous replication for high availability, and support for two SQL dialects: GoogleSQL (ANSI 2011 with extensions) and PostgreSQL.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -520,6 +704,7 @@ from langchain_google_spanner import SpannerVectorStore
|
||||
### Firestore (Native Mode)
|
||||
|
||||
> [Google Cloud Firestore](https://cloud.google.com/firestore/docs/) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -529,12 +714,13 @@ pip install langchain-google-firestore
|
||||
See [usage example](/docs/integrations/vectorstores/google_firestore).
|
||||
|
||||
```python
|
||||
from langchain_google_firestore import FirestoreVectorstore
|
||||
from langchain_google_firestore import FirestoreVectorStore
|
||||
```
|
||||
|
||||
### Cloud SQL for MySQL
|
||||
|
||||
> [Google Cloud SQL for MySQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your MySQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -550,6 +736,7 @@ from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLVectorStore
|
||||
### Cloud SQL for PostgreSQL
|
||||
|
||||
> [Google Cloud SQL for PostgreSQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your PostgreSQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -581,6 +768,52 @@ See a [usage example](/docs/integrations/vectorstores/google_vertex_ai_vector_se
|
||||
from langchain_google_vertexai import VectorSearchVectorStore
|
||||
```
|
||||
|
||||
### Vertex AI Vector Search with DataStore
|
||||
|
||||
> VectorSearch with DatasTore document storage.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
See a [usage example](/docs/integrations/vectorstores/google_vertex_ai_vector_search/#optional--you-can-also-create-vectore-and-store-chunks-in-a-datastore).
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai import VectorSearchVectorStoreDatastore
|
||||
```
|
||||
|
||||
### VectorSearchVectorStoreGCS
|
||||
|
||||
> Alias of `VectorSearchVectorStore` for consistency
|
||||
> with the rest of vector stores with different document storage backends.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai import VectorSearchVectorStoreGCS
|
||||
```
|
||||
|
||||
### Google Generative AI Vector Store
|
||||
|
||||
> Currently, it computes the embedding vectors on the server side.
|
||||
> For more information visit [Guide](https://developers.generativeai.google/guide).
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
pip install langchain-google-genai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_genai.google_vector_store import GoogleVectorStore
|
||||
```
|
||||
|
||||
### ScaNN
|
||||
|
||||
>[Google ScaNN](https://github.com/google-research/google-research/tree/master/scann)
|
||||
@@ -613,7 +846,7 @@ from langchain_community.vectorstores import ScaNN
|
||||
We need to install several python packages.
|
||||
|
||||
```bash
|
||||
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
|
||||
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-googledrive
|
||||
```
|
||||
|
||||
See a [usage example and authorization instructions](/docs/integrations/retrievers/google_drive).
|
||||
@@ -627,16 +860,38 @@ from langchain_googledrive.retrievers import GoogleDriveRetriever
|
||||
> [Vertex AI Search](https://cloud.google.com/generative-ai-app-builder/docs/introduction)
|
||||
> from Google Cloud allows developers to quickly build generative AI powered search engines for customers and employees.
|
||||
|
||||
See a [usage example](/docs/integrations/retrievers/google_vertex_ai_search).
|
||||
|
||||
Note: `GoogleVertexAISearchRetriever` is deprecated, use `VertexAIMultiTurnSearchRetriever`,
|
||||
`VertexAISearchSummaryTool`, and `VertexAISearchRetriever` (see below).
|
||||
|
||||
#### GoogleVertexAISearchRetriever
|
||||
|
||||
We need to install the `google-cloud-discoveryengine` python package.
|
||||
|
||||
```bash
|
||||
pip install google-cloud-discoveryengine
|
||||
```
|
||||
|
||||
See a [usage example](/docs/integrations/retrievers/google_vertex_ai_search).
|
||||
```python
|
||||
from langchain_community.retrievers import GoogleVertexAISearchRetriever
|
||||
```
|
||||
|
||||
#### VertexAIMultiTurnSearchRetriever
|
||||
|
||||
```python
|
||||
from langchain.retrievers import GoogleVertexAISearchRetriever
|
||||
from langchain_google_community import VertexAIMultiTurnSearchRetriever
|
||||
```
|
||||
#### VertexAISearchRetriever
|
||||
|
||||
```python
|
||||
from langchain_google_community import VertexAIMultiTurnSearchRetriever
|
||||
```
|
||||
|
||||
#### VertexAISearchSummaryTool
|
||||
|
||||
```python
|
||||
from langchain_google_community import VertexAISearchSummaryTool
|
||||
```
|
||||
|
||||
### Document AI Warehouse
|
||||
@@ -670,10 +925,10 @@ from langchain_google_community.documentai_warehouse import DocumentAIWarehouseR
|
||||
> It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks
|
||||
> to deliver the highest fidelity possible.
|
||||
|
||||
We need to install a python package.
|
||||
We need to install python packages.
|
||||
|
||||
```bash
|
||||
pip install google-cloud-text-to-speech
|
||||
pip install google-cloud-text-to-speech langchain-google-community
|
||||
```
|
||||
|
||||
See a [usage example and authorization instructions](/docs/integrations/tools/google_cloud_texttospeech).
|
||||
@@ -688,13 +943,14 @@ We need to install several python packages.
|
||||
|
||||
```bash
|
||||
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
|
||||
pip install langchain-googledrive
|
||||
```
|
||||
|
||||
See a [usage example and authorization instructions](/docs/integrations/tools/google_drive).
|
||||
|
||||
```python
|
||||
from langchain_community.utilities.google_drive import GoogleDriveAPIWrapper
|
||||
from langchain_community.tools.google_drive.tool import GoogleDriveSearchTool
|
||||
from langchain_googledrive.utilities.google_drive import GoogleDriveAPIWrapper
|
||||
from langchain_googledrive.tools.google_drive.tool import GoogleDriveSearchTool
|
||||
```
|
||||
|
||||
### Google Finance
|
||||
@@ -784,6 +1040,23 @@ from langchain.agents import load_tools
|
||||
tools = load_tools(["google-search"])
|
||||
```
|
||||
|
||||
#### GoogleSearchResults
|
||||
|
||||
Tool that queries the `Google Search` API (via `GoogleSearchAPIWrapper`) and gets back JSON.
|
||||
|
||||
```python
|
||||
from langchain_community.tools import GoogleSearchResults
|
||||
```
|
||||
|
||||
#### GoogleSearchRun
|
||||
|
||||
Tool that queries the `Google Search` API (via `GoogleSearchAPIWrapper`).
|
||||
|
||||
```python
|
||||
from langchain_community.tools import GoogleSearchRun
|
||||
```
|
||||
|
||||
|
||||
### Google Trends
|
||||
|
||||
We need to install a python package.
|
||||
@@ -818,6 +1091,18 @@ See a [usage example and authorization instructions](/docs/integrations/tools/gm
|
||||
from langchain_google_community import GmailToolkit
|
||||
```
|
||||
|
||||
#### GMail individual tools
|
||||
|
||||
You can use individual tools from GMail Toolkit.
|
||||
|
||||
```python
|
||||
from langchain_google_community.gmail.create_draft import GmailCreateDraft
|
||||
from langchain_google_community.gmail.get_message import GmailGetMessage
|
||||
from langchain_google_community.gmail.get_thread import GmailGetThread
|
||||
from langchain_google_community.gmail.search import GmailSearch
|
||||
from langchain_google_community.gmail.send_message import GmailSendMessage
|
||||
```
|
||||
|
||||
## Memory
|
||||
|
||||
### AlloyDB for PostgreSQL
|
||||
@@ -839,6 +1124,7 @@ from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBChatMessageHistory
|
||||
### Cloud SQL for PostgreSQL
|
||||
|
||||
> [Cloud SQL for PostgreSQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your PostgreSQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -855,6 +1141,7 @@ from langchain_google_cloud_sql_pg import PostgresEngine, PostgresChatMessageHis
|
||||
### Cloud SQL for MySQL
|
||||
|
||||
> [Cloud SQL for MySQL](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your MySQL relational databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -870,6 +1157,7 @@ from langchain_google_cloud_sql_mysql import MySQLEngine, MySQLChatMessageHistor
|
||||
### Cloud SQL for SQL Server
|
||||
|
||||
> [Cloud SQL for SQL Server](https://cloud.google.com/sql) is a fully-managed database service that helps you set up, maintain, manage, and administer your SQL Server databases on Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -885,6 +1173,7 @@ from langchain_google_cloud_sql_mssql import MSSQLEngine, MSSQLChatMessageHistor
|
||||
### Spanner
|
||||
|
||||
> [Google Cloud Spanner](https://cloud.google.com/spanner/docs) is a fully managed, mission-critical, relational database service on Google Cloud that offers transactional consistency at global scale, automatic, synchronous replication for high availability, and support for two SQL dialects: GoogleSQL (ANSI 2011 with extensions) and PostgreSQL.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -900,6 +1189,7 @@ from langchain_google_spanner import SpannerChatMessageHistory
|
||||
### Memorystore for Redis
|
||||
|
||||
> [Google Cloud Memorystore for Redis](https://cloud.google.com/memorystore/docs/redis) is a fully managed Redis service for Google Cloud. Applications running on Google Cloud can achieve extreme performance by leveraging the highly scalable, available, secure Redis service without the burden of managing complex Redis deployments.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -915,6 +1205,7 @@ from langchain_google_memorystore_redis import MemorystoreChatMessageHistory
|
||||
### Bigtable
|
||||
|
||||
> [Google Cloud Bigtable](https://cloud.google.com/bigtable/docs) is Google's fully managed NoSQL Big Data database service in Google Cloud.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -930,6 +1221,7 @@ from langchain_google_bigtable import BigtableChatMessageHistory
|
||||
### Firestore (Native Mode)
|
||||
|
||||
> [Google Cloud Firestore](https://cloud.google.com/firestore/docs/) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -946,6 +1238,7 @@ from langchain_google_firestore import FirestoreChatMessageHistory
|
||||
|
||||
> [Google Cloud Firestore in Datastore mode](https://cloud.google.com/datastore/docs) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
|
||||
> Firestore is the newest version of Datastore and introduces several improvements over Datastore.
|
||||
|
||||
Install the python package:
|
||||
|
||||
```bash
|
||||
@@ -974,6 +1267,22 @@ See [usage example](/docs/integrations/memory/google_el_carro).
|
||||
from langchain_google_el_carro import ElCarroChatMessageHistory
|
||||
```
|
||||
|
||||
## Callbacks
|
||||
|
||||
### Vertex AI callback handler
|
||||
|
||||
>Callback Handler that tracks `VertexAI` info.
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.callbacks import VertexAICallbackHandler
|
||||
```
|
||||
|
||||
## Chat Loaders
|
||||
|
||||
### GMail
|
||||
@@ -993,6 +1302,30 @@ See a [usage example and authorization instructions](/docs/integrations/chat_loa
|
||||
from langchain_google_community import GMailLoader
|
||||
```
|
||||
|
||||
## Evaluators
|
||||
|
||||
We need to install `langchain-google-vertexai` python package.
|
||||
|
||||
```bash
|
||||
pip install langchain-google-vertexai
|
||||
```
|
||||
|
||||
### VertexPairWiseStringEvaluator
|
||||
|
||||
>Pair-wise evaluation of the perplexity of a predicted string.
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.evaluators.evaluation import VertexPairWiseStringEvaluator
|
||||
```
|
||||
|
||||
### VertexStringEvaluator
|
||||
|
||||
>Evaluate the perplexity of a predicted string.
|
||||
|
||||
```python
|
||||
from langchain_google_vertexai.evaluators.evaluation import VertexPairWiseStringEvaluator
|
||||
```
|
||||
|
||||
## 3rd Party Integrations
|
||||
|
||||
### SearchApi
|
||||
|
||||
@@ -12,7 +12,7 @@ pip install langchain-huggingface
|
||||
|
||||
## Chat models
|
||||
|
||||
### Models from Hugging Face
|
||||
### ChatHuggingFace
|
||||
|
||||
We can use the `Hugging Face` LLM classes or directly use the `ChatHuggingFace` class.
|
||||
|
||||
@@ -24,7 +24,16 @@ from langchain_huggingface import ChatHuggingFace
|
||||
|
||||
## LLMs
|
||||
|
||||
### Hugging Face Local Pipelines
|
||||
### HuggingFaceEndpoint
|
||||
|
||||
|
||||
See a [usage example](/docs/integrations/llms/huggingface_endpoint).
|
||||
|
||||
```python
|
||||
from langchain_huggingface import HuggingFaceEndpoint
|
||||
```
|
||||
|
||||
### HuggingFacePipeline
|
||||
|
||||
Hugging Face models can be run locally through the `HuggingFacePipeline` class.
|
||||
|
||||
@@ -44,6 +53,22 @@ See a [usage example](/docs/integrations/text_embedding/huggingfacehub).
|
||||
from langchain_huggingface import HuggingFaceEmbeddings
|
||||
```
|
||||
|
||||
### HuggingFaceEndpointEmbeddings
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/huggingfacehub).
|
||||
|
||||
```python
|
||||
from langchain_huggingface import HuggingFaceEndpointEmbeddings
|
||||
```
|
||||
|
||||
### HuggingFaceInferenceAPIEmbeddings
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/huggingfacehub).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
|
||||
```
|
||||
|
||||
### HuggingFaceInstructEmbeddings
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/instruct_embeddings).
|
||||
@@ -54,7 +79,7 @@ from langchain_community.embeddings import HuggingFaceInstructEmbeddings
|
||||
|
||||
### HuggingFaceBgeEmbeddings
|
||||
|
||||
>[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en) are [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).
|
||||
>[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en-v1.5) are one of [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).
|
||||
>BGE model is created by the [Beijing Academy of Artificial Intelligence (BAAI)](https://en.wikipedia.org/wiki/Beijing_Academy_of_Artificial_Intelligence). `BAAI` is a private non-profit organization engaged in AI research and development.
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/bge_huggingface).
|
||||
@@ -63,33 +88,14 @@ See a [usage example](/docs/integrations/text_embedding/bge_huggingface).
|
||||
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
||||
```
|
||||
|
||||
### Hugging Face Text Embeddings Inference (TEI)
|
||||
|
||||
>[Hugging Face Text Embeddings Inference (TEI)](https://huggingface.co/docs/text-generation-inference/index) is a toolkit for deploying and serving open-source
|
||||
> text embeddings and sequence classification models. `TEI` enables high-performance extraction for the most popular models,
|
||||
>including `FlagEmbedding`, `Ember`, `GTE` and `E5`.
|
||||
|
||||
We need to install `huggingface-hub` python package.
|
||||
|
||||
```bash
|
||||
pip install huggingface-hub
|
||||
```
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/text_embeddings_inference).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import HuggingFaceHubEmbeddings
|
||||
```
|
||||
|
||||
|
||||
## Document Loaders
|
||||
|
||||
### Hugging Face dataset
|
||||
|
||||
>[Hugging Face Hub](https://huggingface.co/docs/hub/index) is home to over 75,000
|
||||
> [datasets](https://huggingface.co/docs/hub/index#datasets) in more than 100 languages
|
||||
>[Hugging Face Hub](https://huggingface.co/docs/hub/index) is home to over 75,000
|
||||
> [datasets](https://huggingface.co/docs/hub/index#datasets) in more than 100 languages
|
||||
> that can be used for a broad range of tasks across NLP, Computer Vision, and Audio.
|
||||
> They used for a diverse range of tasks such as translation, automatic speech
|
||||
> They used for a diverse range of tasks such as translation, automatic speech
|
||||
> recognition, and image classification.
|
||||
|
||||
We need to install `datasets` python package.
|
||||
@@ -104,13 +110,40 @@ See a [usage example](/docs/integrations/document_loaders/hugging_face_dataset).
|
||||
from langchain_community.document_loaders.hugging_face_dataset import HuggingFaceDatasetLoader
|
||||
```
|
||||
|
||||
### Hugging Face model loader
|
||||
|
||||
>Load model information from `Hugging Face Hub`, including README content.
|
||||
>
|
||||
>This loader interfaces with the `Hugging Face Models API` to fetch
|
||||
> and load model metadata and README files.
|
||||
> The API allows you to search and filter models based on
|
||||
> specific criteria such as model tags, authors, and more.
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import HuggingFaceModelLoader
|
||||
```
|
||||
|
||||
### Image captions
|
||||
|
||||
It uses the Hugging Face models to generate image captions.
|
||||
|
||||
We need to install several python packages.
|
||||
|
||||
```bash
|
||||
pip install transformers pillow
|
||||
```
|
||||
|
||||
See a [usage example](/docs/integrations/document_loaders/image_captions).
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import ImageCaptionLoader
|
||||
```
|
||||
|
||||
## Tools
|
||||
|
||||
### Hugging Face Hub Tools
|
||||
|
||||
>[Hugging Face Tools](https://huggingface.co/docs/transformers/v4.29.0/en/custom_tools)
|
||||
>[Hugging Face Tools](https://huggingface.co/docs/transformers/v4.29.0/en/custom_tools)
|
||||
> support text I/O and are loaded using the `load_huggingface_tool` function.
|
||||
|
||||
We need to install several python packages.
|
||||
@@ -124,3 +157,12 @@ See a [usage example](/docs/integrations/tools/huggingface_tools).
|
||||
```python
|
||||
from langchain_community.agent_toolkits.load_tools import load_huggingface_tool
|
||||
```
|
||||
|
||||
### Hugging Face Text-to-Speech Model Inference.
|
||||
|
||||
> It is a wrapper around `OpenAI Text-to-Speech API`.
|
||||
|
||||
```python
|
||||
from langchain_community.tools.audio import HuggingFaceTextToSpeechModelInference
|
||||
```
|
||||
|
||||
|
||||
@@ -436,6 +436,8 @@ See a [usage example](/docs/integrations/tools/azure_ai_services).
|
||||
from langchain_community.agent_toolkits import azure_ai_services
|
||||
```
|
||||
|
||||
#### Azure AI Services individual tools
|
||||
|
||||
The `azure_ai_services` toolkit includes the following tools:
|
||||
|
||||
- Image Analysis: [AzureAiServicesImageAnalysisTool](https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.azure_ai_services.image_analysis.AzureAiServicesImageAnalysisTool.html)
|
||||
@@ -460,6 +462,23 @@ See a [usage example](/docs/integrations/tools/office365).
|
||||
from langchain_community.agent_toolkits import O365Toolkit
|
||||
```
|
||||
|
||||
#### Office 365 individual tools
|
||||
|
||||
You can use individual tools from the Office 365 Toolkit:
|
||||
- `O365CreateDraftMessage`: tool for creating a draft email in Office 365
|
||||
- `O365SearchEmails`: tool for searching email messages in Office 365
|
||||
- `O365SearchEvents`: tool for searching calendar events in Office 365
|
||||
- `O365SendEvent`: tool for sending calendar events in Office 365
|
||||
- `O365SendMessage`: tool for sending an email in Office 365
|
||||
|
||||
```python
|
||||
from langchain_community.tools.office365 import O365CreateDraftMessage
|
||||
from langchain_community.tools.office365 import O365SearchEmails
|
||||
from langchain_community.tools.office365 import O365SearchEvents
|
||||
from langchain_community.tools.office365 import O365SendEvent
|
||||
from langchain_community.tools.office365 import O365SendMessage
|
||||
```
|
||||
|
||||
### Microsoft Azure PowerBI
|
||||
|
||||
We need to install `azure-identity` python package.
|
||||
@@ -475,6 +494,20 @@ from langchain_community.agent_toolkits import PowerBIToolkit
|
||||
from langchain_community.utilities.powerbi import PowerBIDataset
|
||||
```
|
||||
|
||||
#### PowerBI individual tools
|
||||
|
||||
You can use individual tools from the Azure PowerBI Toolkit:
|
||||
- `InfoPowerBITool`: tool for getting metadata about a PowerBI Dataset
|
||||
- `ListPowerBITool`: tool for getting tables names
|
||||
- `QueryPowerBITool`: tool for querying a PowerBI Dataset
|
||||
|
||||
```python
|
||||
from langchain_community.tools.powerbi.tool import InfoPowerBITool
|
||||
from langchain_community.tools.powerbi.tool import ListPowerBITool
|
||||
from langchain_community.tools.powerbi.tool import QueryPowerBITool
|
||||
```
|
||||
|
||||
|
||||
### PlayWright Browser Toolkit
|
||||
|
||||
>[Playwright](https://github.com/microsoft/playwright) is an open-source automation tool
|
||||
|
||||
63
docs/docs/integrations/providers/apache.mdx
Normal file
63
docs/docs/integrations/providers/apache.mdx
Normal file
@@ -0,0 +1,63 @@
|
||||
# Apache Software Foundation
|
||||
|
||||
>[The Apache Software Foundation (Wikipedia)](https://en.wikipedia.org/wiki/The_Apache_Software_Foundation)
|
||||
> is a decentralized open source community of developers. The software they
|
||||
> produce is distributed under the terms of the Apache License, a permissive
|
||||
> open-source license for free and open-source software (FOSS). The Apache projects
|
||||
> are characterized by a collaborative, consensus-based development process
|
||||
> and an open and pragmatic software license, which is to say that it
|
||||
> allows developers, who receive the software freely, to redistribute
|
||||
> it under non-free terms. Each project is managed by a self-selected
|
||||
> team of technical experts who are active contributors to the project.
|
||||
|
||||
## Apache AGE
|
||||
|
||||
>[Apache AGE](https://age.apache.org/) is a `PostgreSQL` extension that provides
|
||||
> graph database functionality. `AGE` is an acronym for `A Graph Extension`, and
|
||||
> is inspired by Bitnine’s fork of `PostgreSQL 10`, `AgensGraph`, which is
|
||||
> a multimodal database. The goal of the project is to create single
|
||||
> storage that can handle both relational and graph model data so that users
|
||||
> can use standard ANSI SQL along with `openCypher`, the Graph query language.
|
||||
> The data elements `Apache AGE` stores are nodes, edges connecting them, and
|
||||
> attributes of nodes and edges.
|
||||
|
||||
See more about [integrating with Apache AGE](/docs/integrations/graphs/apache_age).
|
||||
|
||||
## Apache Cassandra
|
||||
|
||||
>[Apache Cassandra](https://cassandra.apache.org/) is a NoSQL, row-oriented,
|
||||
> highly scalable and highly available database. Starting with version 5.0,
|
||||
> the database ships with vector search capabilities.
|
||||
|
||||
See more about [integrating with Apache Cassandra](/docs/integrations/providers/cassandra/).
|
||||
|
||||
## Apache Doris
|
||||
|
||||
>[Apache Doris](https://doris.apache.org/) is a modern data warehouse for
|
||||
> real-time analytics. It delivers lightning-fast analytics on real-time data at scale.
|
||||
>
|
||||
>Usually `Apache Doris` is categorized into OLAP, and it has showed excellent
|
||||
> performance in ClickBench — a Benchmark For Analytical DBMS. Since it has
|
||||
> a super-fast vectorized execution engine, it could also be used as a fast vectordb.
|
||||
|
||||
See more about [integrating with Apache Doris](/docs/integrations/providers/apache_doris/).
|
||||
|
||||
## Apache Kafka
|
||||
|
||||
>[Apache Kafka](https://github.com/apache/kafka) is a distributed messaging system
|
||||
> that is used to publish and subscribe to streams of records.
|
||||
|
||||
See more about [integrating with Apache Kafka](/docs/integrations/memory/kafka_chat_message_history).
|
||||
|
||||
|
||||
## Apache Spark
|
||||
|
||||
>[Apache Spark](https://spark.apache.org/) is a unified analytics engine for
|
||||
> large-scale data processing. It provides high-level APIs in Scala, Java,
|
||||
> Python, and R, and an optimized engine that supports general computation
|
||||
> graphs for data analysis. It also supports a rich set of higher-level
|
||||
> tools including `Spark SQL` for SQL and DataFrames, `pandas API on Spark`
|
||||
> for pandas workloads, `MLlib` for machine learning,
|
||||
> `GraphX` for graph processing, and `Structured Streaming` for stream processing.
|
||||
|
||||
See more about [integrating with Apache Spark](/docs/integrations/providers/spark).
|
||||
22
docs/docs/integrations/providers/apple.mdx
Normal file
22
docs/docs/integrations/providers/apple.mdx
Normal file
@@ -0,0 +1,22 @@
|
||||
# Apple
|
||||
|
||||
>[Apple Inc. (Wikipedia)](https://en.wikipedia.org/wiki/Apple_Inc.) is an American
|
||||
> multinational corporation and technology company.
|
||||
>
|
||||
> [iMessage (Wikipedia)](https://en.wikipedia.org/wiki/IMessage) is an instant
|
||||
> messaging service developed by Apple Inc. and launched in 2011.
|
||||
> `iMessage` functions exclusively on Apple platforms.
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
See [setup instructions](/docs/integrations/chat_loaders/imessage).
|
||||
|
||||
## Chat loader
|
||||
|
||||
It loads chat sessions from the `iMessage` `chat.db` `SQLite` file.
|
||||
|
||||
See a [usage example](/docs/integrations/chat_loaders/imessage).
|
||||
|
||||
```python
|
||||
from langchain_community.chat_loaders.imessage import IMessageChatLoader
|
||||
```
|
||||
@@ -83,3 +83,28 @@ from langchain_community.agent_toolkits.cassandra_database.toolkit import (
|
||||
Learn more in the [example notebook](/docs/integrations/tools/cassandra_database).
|
||||
|
||||
|
||||
Cassandra Database individual tools:
|
||||
|
||||
### Get Schema
|
||||
|
||||
Tool for getting the schema of a keyspace in an Apache Cassandra database.
|
||||
|
||||
```python
|
||||
from langchain_community.tools import GetSchemaCassandraDatabaseTool
|
||||
```
|
||||
|
||||
### Get Table Data
|
||||
|
||||
Tool for getting data from a table in an Apache Cassandra database.
|
||||
|
||||
```python
|
||||
from langchain_community.tools import GetTableDataCassandraDatabaseTool
|
||||
```
|
||||
|
||||
### Query
|
||||
|
||||
Tool for querying an Apache Cassandra database with provided CQL.
|
||||
|
||||
```python
|
||||
from langchain_community.tools import QueryCassandraDatabaseTool
|
||||
```
|
||||
|
||||
@@ -11,13 +11,22 @@ Databricks embraces the LangChain ecosystem in various ways:
|
||||
4. 🌐 **SQL Database** - [Databricks SQL](https://www.databricks.com/product/databricks-sql) is integrated with `SQLDatabase` in LangChain, allowing you to access the auto-optimizing, exceptionally performant data warehouse.
|
||||
5. 💡 **Open Models** - Databricks open sources models, such as [DBRX](https://www.databricks.com/blog/introducing-dbrx-new-state-art-open-llm), which are available through the [Hugging Face Hub](https://huggingface.co/databricks/dbrx-instruct). These models can be directly utilized with LangChain, leveraging its integration with the `transformers` library.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
First-party Databricks integrations are available in the langchain-databricks partner package.
|
||||
|
||||
```
|
||||
pip install langchain-databricks
|
||||
```
|
||||
|
||||
Chat Model
|
||||
----------
|
||||
|
||||
`ChatDatabricks` is a Chat Model class to access chat endpoints hosted on Databricks, including state-of-the-art models such as Llama3, Mixtral, and DBRX, as well as your own fine-tuned models.
|
||||
|
||||
```
|
||||
from langchain_community.chat_models.databricks import ChatDatabricks
|
||||
from langchain_databricks import ChatDatabricks
|
||||
|
||||
chat_model = ChatDatabricks(endpoint="databricks-meta-llama-3-70b-instruct")
|
||||
```
|
||||
@@ -29,6 +38,10 @@ LLM
|
||||
|
||||
`Databricks` is an LLM class to access completion endpoints hosted on Databricks.
|
||||
|
||||
:::caution
|
||||
Text completion models have been deprecated and the latest and most popular models are [chat completion models](/docs/concepts/#chat-models). Use `ChatDatabricks` chat model instead to use those models and advanced features such as tool calling.
|
||||
:::
|
||||
|
||||
```
|
||||
from langchain_community.llm.databricks import Databricks
|
||||
|
||||
@@ -44,7 +57,7 @@ Embeddings
|
||||
`DatabricksEmbeddings` is an Embeddings class to access text-embedding endpoints hosted on Databricks, including state-of-the-art models such as BGE, as well as your own fine-tuned models.
|
||||
|
||||
```
|
||||
from langchain_community.embeddings import DatabricksEmbeddings
|
||||
from langchain_databricks import DatabricksEmbeddings
|
||||
|
||||
embeddings = DatabricksEmbeddings(endpoint="databricks-bge-large-en")
|
||||
```
|
||||
@@ -58,10 +71,15 @@ Vector Search
|
||||
Databricks Vector Search is a serverless similarity search engine that allows you to store a vector representation of your data, including metadata, in a vector database. With Vector Search, you can create auto-updating vector search indexes from [Delta](https://docs.databricks.com/en/introduction/delta-comparison.html) tables managed by [Unity Catalog](https://www.databricks.com/product/unity-catalog) and query them with a simple API to return the most similar vectors.
|
||||
|
||||
```
|
||||
from langchain_community.vectorstores import DatabricksVectorSearch
|
||||
from langchain_databricks.vectorstores import DatabricksVectorSearch
|
||||
|
||||
dvs = DatabricksVectorSearch(
|
||||
index, text_column="text", embedding=embeddings, columns=["source"]
|
||||
endpoint="<YOUT_ENDPOINT_NAME>",
|
||||
index_name="<YOUR_INDEX_NAME>",
|
||||
index,
|
||||
text_column="text",
|
||||
embedding=embeddings,
|
||||
columns=["source"]
|
||||
)
|
||||
docs = dvs.similarity_search("What is vector search?)
|
||||
```
|
||||
|
||||
26
docs/docs/integrations/providers/falkordb.mdx
Normal file
26
docs/docs/integrations/providers/falkordb.mdx
Normal file
@@ -0,0 +1,26 @@
|
||||
# FalkorDB
|
||||
|
||||
>[FalkorDB](https://www.falkordb.com/) is a creator of the [FalkorDB](https://docs.falkordb.com/),
|
||||
> a low-latency Graph Database that delivers knowledge to GenAI.
|
||||
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
See [installation instructions here](/docs/integrations/graphs/falkordb/).
|
||||
|
||||
|
||||
## Graphs
|
||||
|
||||
See a [usage example](/docs/integrations/graphs/falkordb).
|
||||
|
||||
```python
|
||||
from langchain_community.graphs import FalkorDBGraph
|
||||
```
|
||||
|
||||
## Chains
|
||||
|
||||
See a [usage example](/docs/integrations/graphs/falkordb).
|
||||
|
||||
```python
|
||||
from langchain_community.chains.graph_qa.falkordb import FalkorDBQAChain
|
||||
```
|
||||
22
docs/docs/integrations/providers/firecrawl.mdx
Normal file
22
docs/docs/integrations/providers/firecrawl.mdx
Normal file
@@ -0,0 +1,22 @@
|
||||
# FireCrawl
|
||||
|
||||
>[FireCrawl](https://firecrawl.dev/?ref=langchain) crawls and converts any website into LLM-ready data.
|
||||
> It crawls all accessible subpages and give you clean markdown
|
||||
> and metadata for each. No sitemap required.
|
||||
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
Install the python SDK:
|
||||
|
||||
```bash
|
||||
pip install firecrawl-py
|
||||
```
|
||||
|
||||
## Document loader
|
||||
|
||||
See a [usage example](/docs/integrations/document_loaders/firecrawl).
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import FireCrawlLoader
|
||||
```
|
||||
32
docs/docs/integrations/providers/friendly.md
Normal file
32
docs/docs/integrations/providers/friendly.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Friendli AI
|
||||
|
||||
>[Friendli AI](https://friendli.ai/) is a company that fine-tunes, deploys LLMs,
|
||||
> and serves a wide range of Generative AI use cases.
|
||||
|
||||
|
||||
## Installation and setup
|
||||
|
||||
- Install the integration package:
|
||||
|
||||
```
|
||||
pip install friendli-client
|
||||
```
|
||||
|
||||
- Sign in to [Friendli Suite](https://suite.friendli.ai/) to create a Personal Access Token,
|
||||
and set it as the `FRIENDLI_TOKEN` environment.
|
||||
|
||||
## Chat models
|
||||
|
||||
See a [usage example](/docs/integrations/chat/friendli).
|
||||
|
||||
```python
|
||||
from langchain_community.chat_models.friendli import ChatFriendli
|
||||
```
|
||||
|
||||
## LLMs
|
||||
|
||||
See a [usage example](/docs/integrations/llms/friendli).
|
||||
|
||||
```python
|
||||
from langchain_community.llms.friendli import Friendli
|
||||
```
|
||||
@@ -20,3 +20,26 @@ See a [usage example](/docs/integrations/document_loaders/github).
|
||||
```python
|
||||
from langchain_community.document_loaders import GitHubIssuesLoader, GithubFileLoader
|
||||
```
|
||||
|
||||
## Tools/Toolkit
|
||||
|
||||
### GitHubToolkit
|
||||
The `GitHub` toolkit contains tools that enable an LLM agent to interact
|
||||
with a GitHub repository.
|
||||
|
||||
The toolkit is a wrapper for the `PyGitHub` library.
|
||||
|
||||
```python
|
||||
from langchain_community.agent_toolkits.github.toolkit import GitHubToolkit
|
||||
```
|
||||
|
||||
Learn more in the [example notebook](/docs/integrations/tools/github).
|
||||
|
||||
### GitHubAction
|
||||
|
||||
Tool for interacting with the GitHub API.
|
||||
|
||||
```python
|
||||
from langchain_community.tools.github.tool import GitHubAction
|
||||
```
|
||||
|
||||
|
||||
31
docs/docs/integrations/providers/gitlab.mdx
Normal file
31
docs/docs/integrations/providers/gitlab.mdx
Normal file
@@ -0,0 +1,31 @@
|
||||
# GitLab
|
||||
|
||||
>[GitLab Inc.](https://about.gitlab.com/) is an open-core company
|
||||
> that operates `GitLab`, a DevOps software package that can develop,
|
||||
> secure, and operate software. `GitLab` includes a distributed version
|
||||
> control based on Git, including features such as access control, bug tracking,
|
||||
> software feature requests, task management, and wikis for every project,
|
||||
> as well as snippets.
|
||||
|
||||
|
||||
## Tools/Toolkits
|
||||
|
||||
### GitLabToolkit
|
||||
|
||||
The `Gitlab` toolkit contains tools that enable an LLM agent to interact with a gitlab repository.
|
||||
|
||||
The toolkit is a wrapper for the `python-gitlab` library.
|
||||
|
||||
See a [usage example](/docs/integrations/tools/gitlab).
|
||||
|
||||
```python
|
||||
from langchain_community.agent_toolkits.gitlab.toolkit import GitLabToolkit
|
||||
```
|
||||
|
||||
### GitLabAction
|
||||
|
||||
Tool for interacting with the GitLab API.
|
||||
|
||||
```python
|
||||
from langchain_community.tools.github.tool import GitHubAction
|
||||
```
|
||||
@@ -1,69 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Nomic\n",
|
||||
"\n",
|
||||
"Nomic currently offers two products:\n",
|
||||
"\n",
|
||||
"- Atlas: their Visual Data Engine\n",
|
||||
"- GPT4All: their Open Source Edge Language Model Ecosystem\n",
|
||||
"\n",
|
||||
"The Nomic integration exists in its own [partner package](https://pypi.org/project/langchain-nomic/). You can install it with:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -qU langchain-nomic"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Currently, you can import their hosted [embedding model](/docs/integrations/text_embedding/nomic) as follows:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"id": "y8ku6X96sebl"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_nomic import NomicEmbeddings"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"provenance": []
|
||||
},
|
||||
"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.10.11"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
58
docs/docs/integrations/providers/nomic.mdx
Normal file
58
docs/docs/integrations/providers/nomic.mdx
Normal file
@@ -0,0 +1,58 @@
|
||||
# Nomic
|
||||
|
||||
>[Nomic](https://www.nomic.ai/) builds tools that enable everyone to interact with AI scale datasets and run AI models on consumer computers.
|
||||
>
|
||||
>`Nomic` currently offers two products:
|
||||
>
|
||||
>- `Atlas`: the Visual Data Engine
|
||||
>- `GPT4All`: the Open Source Edge Language Model Ecosystem
|
||||
|
||||
The Nomic integration exists in two partner packages: [langchain-nomic](https://pypi.org/project/langchain-nomic/)
|
||||
and in [langchain-community](https://pypi.org/project/langchain-community/).
|
||||
|
||||
## Installation
|
||||
|
||||
You can install them with:
|
||||
|
||||
```bash
|
||||
pip install -U langchain-nomic
|
||||
pip install -U langchain-community
|
||||
```
|
||||
|
||||
## LLMs
|
||||
|
||||
### GPT4All
|
||||
|
||||
See [a usage example](/docs/integrations/llms/gpt4all).
|
||||
|
||||
```python
|
||||
from langchain_community.llms import GPT4All
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
### NomicEmbeddings
|
||||
|
||||
See [a usage example](/docs/integrations/text_embedding/nomic).
|
||||
|
||||
```python
|
||||
from langchain_nomic import NomicEmbeddings
|
||||
```
|
||||
|
||||
### GPT4All
|
||||
|
||||
See [a usage example](/docs/integrations/text_embedding/gpt4all).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import GPT4AllEmbeddings
|
||||
```
|
||||
|
||||
## Vector store
|
||||
|
||||
### Atlas
|
||||
|
||||
See [a usage example and installation instructions](/docs/integrations/vectorstores/atlas).
|
||||
|
||||
```python
|
||||
from langchain_community.vectorstores import AtlasDB
|
||||
```
|
||||
@@ -13,6 +13,19 @@ Install the Python partner package:
|
||||
pip install langchain-qdrant
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
### FastEmbedSparse
|
||||
|
||||
```python
|
||||
from langchain_qdrant import FastEmbedSparse
|
||||
```
|
||||
|
||||
### SparseEmbeddings
|
||||
|
||||
```python
|
||||
from langchain_qdrant import SparseEmbeddings
|
||||
```
|
||||
|
||||
## Vector Store
|
||||
|
||||
|
||||
49
docs/docs/integrations/providers/spark.mdx
Normal file
49
docs/docs/integrations/providers/spark.mdx
Normal file
@@ -0,0 +1,49 @@
|
||||
# Spark
|
||||
|
||||
>[Apache Spark](https://spark.apache.org/) is a unified analytics engine for
|
||||
> large-scale data processing. It provides high-level APIs in Scala, Java,
|
||||
> Python, and R, and an optimized engine that supports general computation
|
||||
> graphs for data analysis. It also supports a rich set of higher-level
|
||||
> tools including `Spark SQL` for SQL and DataFrames, `pandas API on Spark`
|
||||
> for pandas workloads, `MLlib` for machine learning,
|
||||
> `GraphX` for graph processing, and `Structured Streaming` for stream processing.
|
||||
|
||||
## Document loaders
|
||||
|
||||
### PySpark
|
||||
|
||||
It loads data from a `PySpark` DataFrame.
|
||||
|
||||
See a [usage example](/docs/integrations/document_loaders/pyspark_dataframe).
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import PySparkDataFrameLoader
|
||||
```
|
||||
|
||||
## Tools/Toolkits
|
||||
|
||||
### Spark SQL toolkit
|
||||
|
||||
Toolkit for interacting with `Spark SQL`.
|
||||
|
||||
See a [usage example](/docs/integrations/tools/spark_sql).
|
||||
|
||||
```python
|
||||
from langchain_community.agent_toolkits import SparkSQLToolkit, create_spark_sql_agent
|
||||
from langchain_community.utilities.spark_sql import SparkSQL
|
||||
```
|
||||
|
||||
#### Spark SQL individual tools
|
||||
|
||||
You can use individual tools from the Spark SQL Toolkit:
|
||||
- `InfoSparkSQLTool`: tool for getting metadata about a Spark SQL
|
||||
- `ListSparkSQLTool`: tool for getting tables names
|
||||
- `QueryCheckerTool`: tool uses an LLM to check if a query is correct
|
||||
- `QuerySparkSQLTool`: tool for querying a Spark SQL
|
||||
|
||||
```python
|
||||
from langchain_community.tools.spark_sql.tool import InfoSparkSQLTool
|
||||
from langchain_community.tools.spark_sql.tool import ListSparkSQLTool
|
||||
from langchain_community.tools.spark_sql.tool import QueryCheckerTool
|
||||
from langchain_community.tools.spark_sql.tool import QuerySparkSQLTool
|
||||
```
|
||||
@@ -4,11 +4,26 @@
|
||||
It has cross-domain knowledge and language understanding ability by learning a large amount of texts, codes and images.
|
||||
It can understand and perform tasks based on natural dialogue.
|
||||
|
||||
## SparkLLM LLM Model
|
||||
An example is available at [example](/docs/integrations/llms/sparkllm).
|
||||
## Chat models
|
||||
|
||||
## SparkLLM Chat Model
|
||||
An example is available at [example](/docs/integrations/chat/sparkllm).
|
||||
See a [usage example](/docs/integrations/chat/sparkllm).
|
||||
|
||||
## SparkLLM Text Embedding Model
|
||||
An example is available at [example](/docs/integrations/text_embedding/sparkllm)
|
||||
```python
|
||||
from langchain_community.chat_models import ChatSparkLLM
|
||||
```
|
||||
|
||||
## LLMs
|
||||
|
||||
See a [usage example](/docs/integrations/llms/sparkllm).
|
||||
|
||||
```python
|
||||
from langchain_community.llms import SparkLLM
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/sparkllm)
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import SparkLLMTextEmbeddings
|
||||
```
|
||||
|
||||
34
docs/docs/integrations/providers/transwarp.mdx
Normal file
34
docs/docs/integrations/providers/transwarp.mdx
Normal file
@@ -0,0 +1,34 @@
|
||||
# Transwarp
|
||||
|
||||
>[Transwarp](https://www.transwarp.cn/en/introduction) aims to build
|
||||
> enterprise-level big data and AI infrastructure software,
|
||||
> to shape the future of data world. It provides enterprises with
|
||||
> infrastructure software and services around the whole data lifecycle,
|
||||
> including integration, storage, governance, modeling, analysis,
|
||||
> mining and circulation.
|
||||
>
|
||||
> `Transwarp` focuses on technology research and
|
||||
> development and has accumulated core technologies in these aspects:
|
||||
> distributed computing, SQL compilations, database technology,
|
||||
> unification for multi-model data management, container-based cloud computing,
|
||||
> and big data analytics and intelligence.
|
||||
|
||||
## Installation
|
||||
|
||||
You have to install several python packages:
|
||||
|
||||
```bash
|
||||
pip install -U tiktoken hippo-api
|
||||
```
|
||||
|
||||
and get the connection configuration.
|
||||
|
||||
## Vector stores
|
||||
|
||||
### Hippo
|
||||
|
||||
See [a usage example and installation instructions](/docs/integrations/vectorstores/hippo).
|
||||
|
||||
```python
|
||||
from langchain_community.vectorstores.hippo import Hippo
|
||||
```
|
||||
@@ -6,45 +6,18 @@
|
||||
"source": [
|
||||
"# Upstage\n",
|
||||
"\n",
|
||||
"[Upstage](https://upstage.ai) is a leading artificial intelligence (AI) company specializing in delivering above-human-grade performance LLM components. \n"
|
||||
">[Upstage](https://upstage.ai) is a leading artificial intelligence (AI) company specializing in delivering above-human-grade performance LLM components.\n",
|
||||
">\n",
|
||||
">**Solar Mini Chat** is a fast yet powerful advanced large language model focusing on English and Korean. It has been specifically fine-tuned for multi-turn chat purposes, showing enhanced performance across a wide range of natural language processing tasks, like multi-turn conversation or tasks that require an understanding of long contexts, such as RAG (Retrieval-Augmented Generation), compared to other models of a similar size. This fine-tuning equips it with the ability to handle longer conversations more effectively, making it particularly adept for interactive applications.\n",
|
||||
"\n",
|
||||
">Other than Solar, Upstage also offers features for real-world RAG (retrieval-augmented generation), such as **Groundedness Check** and **Layout Analysis**. \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Solar LLM\n",
|
||||
"\n",
|
||||
"**Solar Mini Chat** is a fast yet powerful advanced large language model focusing on English and Korean. It has been specifically fine-tuned for multi-turn chat purposes, showing enhanced performance across a wide range of natural language processing tasks, like multi-turn conversation or tasks that require an understanding of long contexts, such as RAG (Retrieval-Augmented Generation), compared to other models of a similar size. This fine-tuning equips it with the ability to handle longer conversations more effectively, making it particularly adept for interactive applications.\n",
|
||||
"\n",
|
||||
"Other than Solar, Upstage also offers features for real-world RAG (retrieval-augmented generation), such as **Groundedness Check** and **Layout Analysis**. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Installation and Setup\n",
|
||||
"\n",
|
||||
"Install `langchain-upstage` package:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install -qU langchain-core langchain-upstage\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Get [API Keys](https://console.upstage.ai) and set environment variable `UPSTAGE_API_KEY`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Upstage LangChain integrations\n",
|
||||
"### Upstage LangChain integrations\n",
|
||||
"\n",
|
||||
"| API | Description | Import | Example usage |\n",
|
||||
"| --- | --- | --- | --- |\n",
|
||||
@@ -60,9 +33,20 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Quick Examples\n",
|
||||
"## Installation and Setup\n",
|
||||
"\n",
|
||||
"### Environment Setup"
|
||||
"Install `langchain-upstage` package:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install -qU langchain-core langchain-upstage\n",
|
||||
"```\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Get [API Keys](https://console.upstage.ai) and set environment variable `UPSTAGE_API_KEY`."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -80,8 +64,11 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Chat models\n",
|
||||
"\n",
|
||||
"### Chat\n"
|
||||
"### Solar LLM\n",
|
||||
"\n",
|
||||
"See [a usage example](/docs/integrations/chat/upstage)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -101,10 +88,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Embedding models\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Text embedding\n",
|
||||
"\n"
|
||||
"See [a usage example](/docs/integrations/text_embedding/upstage)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -134,7 +120,45 @@
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Groundedness Check"
|
||||
"## Document loader\n",
|
||||
"\n",
|
||||
"### Layout Analysis\n",
|
||||
"\n",
|
||||
"See [a usage example](/docs/integrations/document_loaders/upstage)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_upstage import UpstageLayoutAnalysisLoader\n",
|
||||
"\n",
|
||||
"file_path = \"/PATH/TO/YOUR/FILE.pdf\"\n",
|
||||
"layzer = UpstageLayoutAnalysisLoader(file_path, split=\"page\")\n",
|
||||
"\n",
|
||||
"# For improved memory efficiency, consider using the lazy_load method to load documents page by page.\n",
|
||||
"docs = layzer.load() # or layzer.lazy_load()\n",
|
||||
"\n",
|
||||
"for doc in docs[:3]:\n",
|
||||
" print(doc)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"jupyter": {
|
||||
"outputs_hidden": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## Tools\n",
|
||||
"\n",
|
||||
"### Groundedness Check\n",
|
||||
"\n",
|
||||
"See [a usage example](/docs/integrations/tools/upstage_groundedness_check)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -159,36 +183,6 @@
|
||||
"response = groundedness_check.invoke(request_input)\n",
|
||||
"print(response)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"jupyter": {
|
||||
"outputs_hidden": false
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Layout Analysis"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_upstage import UpstageLayoutAnalysisLoader\n",
|
||||
"\n",
|
||||
"file_path = \"/PATH/TO/YOUR/FILE.pdf\"\n",
|
||||
"layzer = UpstageLayoutAnalysisLoader(file_path, split=\"page\")\n",
|
||||
"\n",
|
||||
"# For improved memory efficiency, consider using the lazy_load method to load documents page by page.\n",
|
||||
"docs = layzer.load() # or layzer.lazy_load()\n",
|
||||
"\n",
|
||||
"for doc in docs[:3]:\n",
|
||||
" print(doc)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
@@ -210,7 +204,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.13"
|
||||
"version": "3.10.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -44,11 +44,12 @@ from langchain_community.vectorstores.vdms import VDMS_Client
|
||||
from langchain_huggingface import HuggingFaceEmbeddings
|
||||
|
||||
client = VDMS_Client("localhost", 55555)
|
||||
model_name = "sentence-transformers/all-mpnet-base-v2"
|
||||
vectorstore = VDMS.from_documents(
|
||||
docs,
|
||||
client=client,
|
||||
collection_name="langchain-demo",
|
||||
embedding_function=HuggingFaceEmbeddings(),
|
||||
embedding_function=HuggingFaceEmbeddings(model_name=model_name),
|
||||
engine="FaissFlat"
|
||||
distance_strategy="L2",
|
||||
)
|
||||
@@ -58,5 +59,3 @@ results = vectorstore.similarity_search(query)
|
||||
```
|
||||
|
||||
For a more detailed walkthrough of the VDMS wrapper, see [this notebook](/docs/integrations/vectorstores/vdms)
|
||||
|
||||
|
||||
|
||||
24
docs/docs/integrations/providers/yahoo.mdx
Normal file
24
docs/docs/integrations/providers/yahoo.mdx
Normal file
@@ -0,0 +1,24 @@
|
||||
# Yahoo
|
||||
|
||||
>[Yahoo (Wikipedia)](https://en.wikipedia.org/wiki/Yahoo) is an American web services provider.
|
||||
>
|
||||
> It provides a web portal, search engine Yahoo Search, and related
|
||||
> services, including `My Yahoo`, `Yahoo Mail`, `Yahoo News`,
|
||||
> `Yahoo Finance`, `Yahoo Sports` and its advertising platform, `Yahoo Native`.
|
||||
|
||||
|
||||
## Tools
|
||||
|
||||
### Yahoo Finance News
|
||||
|
||||
We have to install a python package:
|
||||
|
||||
```bash
|
||||
pip install yfinance
|
||||
```
|
||||
See a [usage example](/docs/integrations/tools/yahoo_finance_news).
|
||||
|
||||
|
||||
```python
|
||||
from langchain_community.tools import YahooFinanceNewsTool
|
||||
```
|
||||
@@ -31,3 +31,26 @@ See a [usage example](/docs/integrations/chat/yandex).
|
||||
```python
|
||||
from langchain_community.chat_models import ChatYandexGPT
|
||||
```
|
||||
|
||||
## Embedding models
|
||||
|
||||
### YandexGPT
|
||||
|
||||
See a [usage example](/docs/integrations/text_embedding/yandex).
|
||||
|
||||
```python
|
||||
from langchain_community.embeddings import YandexGPTEmbeddings
|
||||
```
|
||||
|
||||
## Parser
|
||||
|
||||
### YandexSTTParser
|
||||
|
||||
It transcribes and parses audio files.
|
||||
|
||||
`YandexSTTParser` is similar to the `OpenAIWhisperParser`.
|
||||
See a [usage example with OpenAIWhisperParser](/docs/integrations/document_loaders/youtube_audio).
|
||||
|
||||
```python
|
||||
from langchain_community.document_loaders import YandexSTTParser
|
||||
```
|
||||
|
||||
17
docs/docs/integrations/providers/yellowbrick.mdx
Normal file
17
docs/docs/integrations/providers/yellowbrick.mdx
Normal file
@@ -0,0 +1,17 @@
|
||||
# Yellowbrick
|
||||
|
||||
>[Yellowbrick](https://yellowbrick.com/) is a provider of
|
||||
> Enterprise Data Warehousing, Ad-hoc and Streaming Analytics,
|
||||
> BI and AI workloads.
|
||||
|
||||
## Vector store
|
||||
|
||||
We have to install a python package:
|
||||
|
||||
```bash
|
||||
pip install psycopg2
|
||||
```
|
||||
|
||||
```python
|
||||
from langchain_community.vectorstores import Yellowbrick
|
||||
```
|
||||
19
docs/docs/integrations/providers/you.mdx
Normal file
19
docs/docs/integrations/providers/you.mdx
Normal file
@@ -0,0 +1,19 @@
|
||||
# You
|
||||
|
||||
>[You](https://you.com/about) company provides an AI productivity platform.
|
||||
|
||||
## Retriever
|
||||
|
||||
See a [usage example](/docs/integrations/retrievers/you-retriever).
|
||||
|
||||
```python
|
||||
from langchain_community.retrievers.you import YouRetriever
|
||||
```
|
||||
|
||||
## Tools
|
||||
|
||||
See a [usage example](/docs/integrations/tools/you).
|
||||
|
||||
```python
|
||||
from langchain_community.tools.you import YouSearchTool
|
||||
```
|
||||
@@ -7,7 +7,7 @@
|
||||
"source": [
|
||||
"# BGE on Hugging Face\n",
|
||||
"\n",
|
||||
">[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en) are [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).\n",
|
||||
">[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en-v1.5) are one of [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).\n",
|
||||
">BGE model is created by the [Beijing Academy of Artificial Intelligence (BAAI)](https://en.wikipedia.org/wiki/Beijing_Academy_of_Artificial_Intelligence). `BAAI` is a private non-profit organization engaged in AI research and development.\n",
|
||||
"\n",
|
||||
"This notebook shows how to use `BGE Embeddings` through `Hugging Face`"
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"embeddings = HuggingFaceEmbeddings()"
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
"## Install Prerequisites\n",
|
||||
"To benefit from IPEX-LLM on Intel GPUs, there are several prerequisite steps for tools installation and environment preparation.\n",
|
||||
"\n",
|
||||
"If you are a Windows user, visit the [Install IPEX-LLM on Windows with Intel GPU Guide](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/install_windows_gpu.html), and follow [Install Prerequisites](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/install_windows_gpu.html#install-prerequisites) to update GPU driver (optional) and install Conda.\n",
|
||||
"If you are a Windows user, visit the [Install IPEX-LLM on Windows with Intel GPU Guide](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_windows_gpu.md), and follow [Install Prerequisites](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_windows_gpu.md#install-prerequisites) to update GPU driver (optional) and install Conda.\n",
|
||||
"\n",
|
||||
"If you are a Linux user, visit the [Install IPEX-LLM on Linux with Intel GPU](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/install_linux_gpu.html), and follow [**Install Prerequisites**](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Quickstart/install_linux_gpu.html#install-prerequisites) to install GPU driver, Intel® oneAPI Base Toolkit 2024.0, and Conda.\n",
|
||||
"If you are a Linux user, visit the [Install IPEX-LLM on Linux with Intel GPU](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_linux_gpu.md), and follow [**Install Prerequisites**](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/install_linux_gpu.md#install-prerequisites) to install GPU driver, Intel® oneAPI Base Toolkit 2024.0, and Conda.\n",
|
||||
"\n",
|
||||
"## Setup\n",
|
||||
"\n",
|
||||
@@ -105,7 +105,7 @@
|
||||
">\n",
|
||||
"> For the first time that each model runs on Intel iGPU/Intel Arc A300-Series or Pro A60, it may take several minutes to compile.\n",
|
||||
">\n",
|
||||
"> For other GPU type, please refer to [here](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Overview/install_gpu.html#runtime-configuration) for Windows users, and [here](https://ipex-llm.readthedocs.io/en/latest/doc/LLM/Overview/install_gpu.html#id5) for Linux users.\n",
|
||||
"> For other GPU type, please refer to [here](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Overview/install_gpu.md#runtime-configuration) for Windows users, and [here](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Overview/install_gpu.md#runtime-configuration-1) for Linux users.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Basic Usage\n",
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
"# Google Cloud Text-to-Speech\n",
|
||||
"\n",
|
||||
">[Google Cloud Text-to-Speech](https://cloud.google.com/text-to-speech) enables developers to synthesize natural-sounding speech with 100+ voices, available in multiple languages and variants. It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks to deliver the highest fidelity possible.\n",
|
||||
">\n",
|
||||
">It supports multiple languages, including English, German, Polish, Spanish, Italian, French, Portuguese, and Hindi.\n",
|
||||
"\n",
|
||||
"This notebook shows how to interact with the `Google Cloud Text-to-Speech API` to achieve speech synthesis capabilities."
|
||||
]
|
||||
@@ -22,12 +24,38 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"id": "0a309c0e-5310-4eaa-8af9-bcbc252e45da",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install --upgrade --quiet google-cloud-text-to-speech langchain-community"
|
||||
"!pip install --upgrade langchain-google-community[texttospeech]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5b86ad38-ac8a-4f0a-a492-01a6e3090c8c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Instantiation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "e2efded2-894b-4683-89ed-2a6948913fa9",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-09-01T17:47:31.565221Z",
|
||||
"iopub.status.busy": "2024-09-01T17:47:31.564804Z",
|
||||
"iopub.status.idle": "2024-09-01T17:47:31.570600Z",
|
||||
"shell.execute_reply": "2024-09-01T17:47:31.569764Z",
|
||||
"shell.execute_reply.started": "2024-09-01T17:47:31.565188Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_google_community import TextToSpeechTool"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -35,18 +63,34 @@
|
||||
"id": "434b2454-2bff-484d-822c-4026a9dc1383",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Usage"
|
||||
"## Deprecated GoogleCloudTextToSpeechTool"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "2f57a647-9214-4562-a8cf-f263a15d1f40",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-09-01T17:51:28.763915Z",
|
||||
"iopub.status.busy": "2024-09-01T17:51:28.763664Z",
|
||||
"iopub.status.idle": "2024-09-01T17:51:28.779073Z",
|
||||
"shell.execute_reply": "2024-09-01T17:51:28.778477Z",
|
||||
"shell.execute_reply.started": "2024-09-01T17:51:28.763897Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.tools import GoogleCloudTextToSpeechTool"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2f57a647-9214-4562-a8cf-f263a15d1f40",
|
||||
"id": "a2647bc5-e494-41f9-9f53-4a278ea30cc1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.tools import GoogleCloudTextToSpeechTool\n",
|
||||
"\n",
|
||||
"text_to_speak = \"Hello world!\"\n",
|
||||
"\n",
|
||||
"tts = GoogleCloudTextToSpeechTool()\n",
|
||||
|
||||
284
docs/docs/integrations/tools/jina_search.ipynb
Normal file
284
docs/docs/integrations/tools/jina_search.ipynb
Normal file
@@ -0,0 +1,284 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "10238e62-3465-4973-9279-606cbb7ccf16",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"sidebar_label: Jina Search\n",
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a6f91f20",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Jina Search\n",
|
||||
"\n",
|
||||
"This notebook provides a quick overview for getting started with Jina [tool](/docs/integrations/tools/). For detailed documentation of all Jina features and configurations head to the [API reference](https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.jina_search.tool.JinaSearch.html).\n",
|
||||
"\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"### Integration details\n",
|
||||
"\n",
|
||||
"| Class | Package | Serializable | JS support | Package latest |\n",
|
||||
"| :--- | :--- | :---: | :---: | :---: |\n",
|
||||
"| [JinaSearch](https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.jina_search.tool.JinaSearch.html) | [langchain-community](https://python.langchain.com/v0.2/api_reference/community/) | ❌ | ❌ |  |\n",
|
||||
"\n",
|
||||
"### Tool features\n",
|
||||
"| [Returns artifact](/docs/how_to/tool_artifacts/) | Native async | Return data | Pricing |\n",
|
||||
"| :---: | :---: | :---: | :---: |\n",
|
||||
"| ❌ | ❌ | URL, Snippet, Title, Page Content | 1M response tokens free | \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Setup\n",
|
||||
"\n",
|
||||
"The integration lives in the `langchain-community` package and was added in version `0.2.16`:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f85b4089",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install --quiet -U \"langchain-community>=0.2.16\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b15e9266",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Credentials"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "e0b178a2-8816-40ca-b57c-ccdd86dde9c9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import getpass\n",
|
||||
"import os"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bc5ab717-fd27-4c59-b912-bdd099541478",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"It's also helpful (but not needed) to set up [LangSmith](https://smith.langchain.com/) for best-in-class observability:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "a6c2f136-6367-4f1f-825d-ae741e1bf281",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n",
|
||||
"# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1c97218f-f366-479d-8bf7-fe9f2f6df73f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Instantiation\n",
|
||||
"\n",
|
||||
"- TODO: Fill in instantiation params\n",
|
||||
"\n",
|
||||
"Here we show how to instantiate an instance of the Jina tool, with "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "8b3ddfe9-ca79-494c-a7ab-1f56d9407a64",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.tools import JinaSearch\n",
|
||||
"\n",
|
||||
"tool = JinaSearch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "74147a1a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Invocation\n",
|
||||
"\n",
|
||||
"### [Invoke directly with args](/docs/concepts/#invoke-with-just-the-arguments)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "65310a8b-eb0c-4d9e-a618-4f4abe2414fc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[{\"title\": \"LangGraph\", \"link\": \"https://www.langchain.com/langgraph\", \"snippet\": \"<strong>LangGraph</strong> helps teams of all sizes, across all industries, from ambitious startups to established enterprises. \\u201cLangChain is streets ahead with what they've put forward with <strong>LangGraph</strong>.\", \"content\": \"\\n\\nControllable cognitive architecture for any task\\n------------------------------------------------\\n\\nLangGraph's flexible API supports diverse control flows \\u2013 single agent, multi-agent, hierarchical, sequential \\u2013 and robustly handles realistic, complex scenarios.\\n\\nEnsure reliability with easy-to-add moderation and quality loops that prevent agents from veering off course.\\n\\n[See the docs](https://langchain-ai.github.io/langgraph/)\\n\\nDesigned for human-agent collaboration\\n--------------------------------------\\n\\nWith built-in stat\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(tool.invoke({\"query\": \"what is langgraph\"})[:1000])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d6e73897",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### [Invoke with ToolCall](/docs/concepts/#invoke-with-toolcall)\n",
|
||||
"\n",
|
||||
"We can also invoke the tool with a model-generated ToolCall, in which case a ToolMessage will be returned:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "f90e33a7",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[{\"title\": \"LangGraph Tutorial: What Is LangGraph and How to Use It?\", \"link\": \"https://www.datacamp.com/tutorial/langgraph-tutorial\", \"snippet\": \"<strong>LangGraph</strong> <strong>is</strong> a library within the LangChain ecosystem that provides a framework for defining, coordinating, and executing multiple LLM agents (or chains) in a structured and efficient manner.\", \"content\": \"Imagine you're building a complex, multi-agent large language model (LLM) application. It's exciting, but it comes with challenges: managing the state of various agents, coordinating their interactions, and handling errors effectively. This is where LangGraph can help.\\n\\nLangGraph is a library within the LangChain ecosystem designed to tackle these challenges head-on. LangGraph provides a framework for defining, coordinating, and executing multiple LLM agents (or chains) in a structured manner.\\n\\nIt simplifies the development process by enabling the creation of cyclical graphs, which are essential for de\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# This is usually generated by a model, but we'll create a tool call directly for demo purposes.\n",
|
||||
"model_generated_tool_call = {\n",
|
||||
" \"args\": {\"query\": \"what is langgraph\"},\n",
|
||||
" \"id\": \"1\",\n",
|
||||
" \"name\": tool.name,\n",
|
||||
" \"type\": \"tool_call\",\n",
|
||||
"}\n",
|
||||
"tool_msg = tool.invoke(model_generated_tool_call)\n",
|
||||
"print(tool_msg.content[:1000])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "659f9fbd-6fcf-445f-aa8c-72d8e60154bd",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Chaining\n",
|
||||
"\n",
|
||||
"We can use our tool in a chain by first binding it to a [tool-calling model](/docs/how_to/tool_calling/) and then calling it:\n",
|
||||
"\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
"\n",
|
||||
"<ChatModelTabs customVarName=\"llm\" />\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "af3123ad-7a02-40e5-b58e-7d56e23e5830",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# | output: false\n",
|
||||
"# | echo: false\n",
|
||||
"\n",
|
||||
"# !pip install -qU langchain langchain-openai\n",
|
||||
"from langchain.chat_models import init_chat_model\n",
|
||||
"\n",
|
||||
"llm = init_chat_model(model=\"gpt-4o\", model_provider=\"openai\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "fdbf35b5-3aaf-4947-9ec6-48c21533fb95",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"AIMessage(content=\"LangGraph is a library designed for building stateful, multi-actor applications with language models (LLMs). It is particularly useful for creating agent and multi-agent workflows. Compared to other LLM frameworks, LangGraph offers unique benefits such as cycles, controllability, and persistence. Here are some key points:\\n\\n1. **Stateful and Multi-Actor Applications**: LangGraph allows for the definition of flows involving cycles, essential for most agentic architectures. This is a significant differentiation from Directed Acyclic Graph (DAG)-based solutions.\\n\\n2. **Controllability**: The framework offers fine-grained control over both the flow and state of applications, which is crucial for creating reliable agents.\\n\\n3. **Persistence**: Built-in persistence is available, enabling advanced features like human-in-the-loop workflows and memory.\\n\\n4. **Human-in-the-Loop**: LangGraph supports interrupting graph execution for human approval or editing of the agent's next planned action.\\n\\n5. **Streaming Support**: The library can stream outputs as they are produced by each node, including token streaming.\\n\\n6. **Integration with LangChain**: While it integrates seamlessly with LangChain and LangSmith, LangGraph can also be used independently.\\n\\n7. **Inspiration and Interface**: LangGraph is inspired by systems like Pregel and Apache Beam, with its public interface drawing inspiration from NetworkX.\\n\\nLangGraph is designed to handle more complex agent applications that require cycles and state management, making it an ideal choice for developers seeking to build sophisticated LLM-driven applications. For more detailed information, you can visit their [official documentation](https://langchain-ai.github.io/langgraph/).\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 338, 'prompt_tokens': 14774, 'total_tokens': 15112}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_157b3831f5', 'finish_reason': 'stop', 'logprobs': None}, id='run-420d16ed-535c-41c6-8814-2186b42be0f8-0', usage_metadata={'input_tokens': 14774, 'output_tokens': 338, 'total_tokens': 15112})"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_core.runnables import RunnableConfig, chain\n",
|
||||
"\n",
|
||||
"prompt = ChatPromptTemplate(\n",
|
||||
" [\n",
|
||||
" (\"system\", \"You are a helpful assistant.\"),\n",
|
||||
" (\"human\", \"{user_input}\"),\n",
|
||||
" (\"placeholder\", \"{messages}\"),\n",
|
||||
" ]\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"llm_with_tools = llm.bind_tools([tool])\n",
|
||||
"llm_chain = prompt | llm_with_tools\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@chain\n",
|
||||
"def tool_chain(user_input: str, config: RunnableConfig):\n",
|
||||
" input_ = {\"user_input\": user_input}\n",
|
||||
" ai_msg = llm_chain.invoke(input_, config=config)\n",
|
||||
" tool_msgs = tool.batch(ai_msg.tool_calls, config=config)\n",
|
||||
" return llm_chain.invoke({**input_, \"messages\": [ai_msg, *tool_msgs]}, config=config)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"tool_chain.invoke(\"what's langgraph\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4ac8146c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## API reference\n",
|
||||
"\n",
|
||||
"For detailed documentation of all Jina features and configurations head to the API reference: https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.jina_search.tool.JinaSearch.html"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "poetry-venv-311",
|
||||
"language": "python",
|
||||
"name": "poetry-venv-311"
|
||||
},
|
||||
"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
|
||||
}
|
||||
@@ -57,7 +57,8 @@
|
||||
"from langchain_community.vectorstores import Annoy\n",
|
||||
"from langchain_huggingface import HuggingFaceEmbeddings\n",
|
||||
"\n",
|
||||
"embeddings_func = HuggingFaceEmbeddings()"
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings_func = HuggingFaceEmbeddings(model_name=model_name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
"source": [
|
||||
"# Faiss\n",
|
||||
"\n",
|
||||
">[Facebook AI Similarity Search (FAISS)](https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also contains supporting code for evaluation and parameter tuning.\n",
|
||||
">[Facebook AI Similarity Search (FAISS)](https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also includes supporting code for evaluation and parameter tuning.\n",
|
||||
">\n",
|
||||
">See [The FAISS Library](https://arxiv.org/pdf/2401.08281) paper.\n",
|
||||
"\n",
|
||||
"You can find the FAISS documentation at [this page](https://faiss.ai/).\n",
|
||||
"\n",
|
||||
@@ -528,7 +530,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.9"
|
||||
"version": "3.10.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
"source": [
|
||||
"# Faiss (Async)\n",
|
||||
"\n",
|
||||
">[Facebook AI Similarity Search (Faiss)](https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also contains supporting code for evaluation and parameter tuning.\n",
|
||||
">[Facebook AI Similarity Search (Faiss)](https://engineering.fb.com/2017/03/29/data-infrastructure/faiss-a-library-for-efficient-similarity-search/) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also includes supporting code for evaluation and parameter tuning.\n",
|
||||
">\n",
|
||||
">See [The FAISS Library](https://arxiv.org/pdf/2401.08281) paper.\n",
|
||||
"\n",
|
||||
"[Faiss documentation](https://faiss.ai/).\n",
|
||||
"\n",
|
||||
|
||||
@@ -325,7 +325,13 @@
|
||||
"id": "20cf6074081b"
|
||||
},
|
||||
"source": [
|
||||
"### Search for documents with metadata filter"
|
||||
"### Searching Documents with Metadata Filters\n",
|
||||
"The vectorstore supports two methods for applying filters to metadata fields when performing document searches:\n",
|
||||
"\n",
|
||||
"- Dictionary-based Filters\n",
|
||||
" - You can pass a dictionary (dict) where the keys represent metadata fields and the values specify the filter condition. This method applies an equality filter between the key and the corresponding value. When multiple key-value pairs are provided, they are combined using a logical AND operation.\n",
|
||||
"- SQL-based Filters\n",
|
||||
" - Alternatively, you can provide a string representing an SQL WHERE clause to define more complex filtering conditions. This allows for greater flexibility, supporting SQL expressions such as comparison operators and logical operators."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -336,11 +342,24 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Dictionary-based Filters\n",
|
||||
"# This should only return \"Banana\" document.\n",
|
||||
"docs = store.similarity_search_by_vector(query_vector, filter={\"len\": 6})\n",
|
||||
"print(docs)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# SQL-based Filters\n",
|
||||
"# This should return \"Banana\", \"Apples and oranges\" and \"Cars and airplanes\" documents.\n",
|
||||
"docs = store.similarity_search_by_vector(query_vector, filter={\"len = 6 AND len > 17\"})\n",
|
||||
"print(docs)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
||||
@@ -61,7 +61,8 @@
|
||||
"docs = text_splitter.split_documents(documents)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"embeddings = HuggingFaceEmbeddings()\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"\n",
|
||||
"db = ScaNN.from_documents(docs, embeddings)\n",
|
||||
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
|
||||
|
||||
@@ -45,7 +45,8 @@
|
||||
"source": [
|
||||
"from langchain_huggingface import HuggingFaceEmbeddings\n",
|
||||
"\n",
|
||||
"embeddings = HuggingFaceEmbeddings()"
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -92,7 +92,8 @@
|
||||
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
||||
"docs = text_splitter.split_documents(documents)\n",
|
||||
"\n",
|
||||
"embeddings = HuggingFaceEmbeddings()"
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -51,7 +51,8 @@
|
||||
"raw_documents = TextLoader(\"../../how_to/state_of_the_union.txt\").load()\n",
|
||||
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
||||
"documents = text_splitter.split_documents(raw_documents)\n",
|
||||
"embeddings = HuggingFaceEmbeddings()\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"db = TileDB.from_documents(\n",
|
||||
" documents, embeddings, index_uri=\"/tmp/tiledb_index\", index_type=\"FLAT\"\n",
|
||||
")"
|
||||
|
||||
@@ -50,7 +50,8 @@
|
||||
"raw_documents = TextLoader(\"state_of_the_union.txt\").load()\n",
|
||||
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
||||
"documents = text_splitter.split_documents(raw_documents)\n",
|
||||
"embeddings = HuggingFaceEmbeddings()\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"db = Vald.from_documents(documents, embeddings, host=\"localhost\", port=8080)"
|
||||
]
|
||||
},
|
||||
@@ -197,7 +198,8 @@
|
||||
"raw_documents = TextLoader(\"state_of_the_union.txt\").load()\n",
|
||||
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
||||
"documents = text_splitter.split_documents(raw_documents)\n",
|
||||
"embeddings = HuggingFaceEmbeddings()\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embeddings = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"\n",
|
||||
"db = Vald.from_documents(\n",
|
||||
" documents,\n",
|
||||
|
||||
@@ -200,7 +200,8 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"# create the open-source embedding function\n",
|
||||
"embedding = HuggingFaceEmbeddings()\n",
|
||||
"model_name = \"sentence-transformers/all-mpnet-base-v2\"\n",
|
||||
"embedding = HuggingFaceEmbeddings(model_name=model_name)\n",
|
||||
"print(\n",
|
||||
" f\"# Embedding Dimensions: {len(embedding.embed_query('This is a test document.'))}\"\n",
|
||||
")"
|
||||
|
||||
@@ -55,7 +55,7 @@ These are the best ones to get started with:
|
||||
- [Build an Agent](/docs/tutorials/agents)
|
||||
- [Introduction to LangGraph](https://langchain-ai.github.io/langgraph/tutorials/introduction/)
|
||||
|
||||
Explore the full list of LangChain tutorials [here](/docs/tutorials), and check out other [LangGraph tutorials here](https://langchain-ai.github.io/langgraph/tutorials/).
|
||||
Explore the full list of LangChain tutorials [here](/docs/tutorials), and check out other [LangGraph tutorials here](https://langchain-ai.github.io/langgraph/tutorials/). To learn more about LangGraph, check out our first LangChain Academy course, *Introduction to LangGraph*, available [here](https://academy.langchain.com/courses/intro-to-langgraph).
|
||||
|
||||
|
||||
## [How-to guides](/docs/how_to)
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
"\n",
|
||||
"## Quickstart\n",
|
||||
"\n",
|
||||
"First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangably - select the one you want to use below!\n",
|
||||
"First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangeably - select the one you want to use below!\n",
|
||||
"\n",
|
||||
"```{=mdx}\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
@@ -254,7 +254,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# ! pip install langchain_community"
|
||||
"%pip install langchain_community"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -952,7 +952,7 @@
|
||||
"source": [
|
||||
"## Streaming\n",
|
||||
"\n",
|
||||
"Now we've got a function chatbot. However, one *really* important UX consideration for chatbot application is streaming. LLMs can sometimes take a while to respond, and so in order to improve the user experience one thing that most application do is stream back each token as it is generated. This allows the user to see progress.\n",
|
||||
"Now we've got a functioning chatbot. However, one *really* important UX consideration for chatbot applications is streaming. LLMs can sometimes take a while to respond, and so in order to improve the user experience one thing that most applications do is stream back each token as it is generated. This allows the user to see progress.\n",
|
||||
"\n",
|
||||
"It's actually super easy to do this!\n",
|
||||
"\n",
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
"source": [
|
||||
"## Using Language Models\n",
|
||||
"\n",
|
||||
"First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangably - select the one you want to use below!\n",
|
||||
"First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangeably - select the one you want to use below!\n",
|
||||
"\n",
|
||||
"```{=mdx}\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
@@ -159,9 +159,7 @@
|
||||
"cell_type": "markdown",
|
||||
"id": "f83373db",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If we've enable LangSmith, we can see that this run is logged to LangSmith, and can see the [LangSmith trace](https://smith.langchain.com/public/88baa0b2-7c1a-4d09-ba30-a47985dde2ea/r)"
|
||||
]
|
||||
"source": "If we've enabled LangSmith, we can see that this run is logged to LangSmith, and can see the [LangSmith trace](https://smith.langchain.com/public/88baa0b2-7c1a-4d09-ba30-a47985dde2ea/r)"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -479,8 +477,6 @@
|
||||
"\n",
|
||||
"```python\n",
|
||||
"#!/usr/bin/env python\n",
|
||||
"from typing import List\n",
|
||||
"\n",
|
||||
"from fastapi import FastAPI\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_core.output_parsers import StrOutputParser\n",
|
||||
@@ -512,7 +508,6 @@
|
||||
")\n",
|
||||
"\n",
|
||||
"# 5. Adding chain route\n",
|
||||
"\n",
|
||||
"add_routes(\n",
|
||||
" app,\n",
|
||||
" chain,\n",
|
||||
|
||||
@@ -337,8 +337,6 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from typing import List\n",
|
||||
"\n",
|
||||
"from langchain_core.documents import Document\n",
|
||||
"from langchain_core.runnables import RunnableLambda\n",
|
||||
"\n",
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
"\n",
|
||||
"2. `Map-reduce`: Summarize each document on its own in a \"map\" step and then \"reduce\" the summaries into a final summary (see [here](https://python.langchain.com/v0.2/api_reference/langchain/chains/langchain.chains.combine_documents.map_reduce.MapReduceDocumentsChain.html) for more on the `MapReduceDocumentsChain`, which is used for this method).\n",
|
||||
"\n",
|
||||
"Note that map-reduce is especially effective when understanding of a sub-document does not rely on preceeding context. For example, when summarizing a corpus of many, shorter documents. In other cases, such as summarizing a novel or body of text with an inherent sequence, [iterative refinement](/docs/how_to/summarize_refine) may be more effective."
|
||||
"Note that map-reduce is especially effective when understanding of a sub-document does not rely on preceding context. For example, when summarizing a corpus of many, shorter documents. In other cases, such as summarizing a novel or body of text with an inherent sequence, [iterative refinement](/docs/how_to/summarize_refine) may be more effective."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -346,7 +346,7 @@
|
||||
"\n",
|
||||
"Note that the map step is typically parallelized over the input documents.\n",
|
||||
"\n",
|
||||
"[LangGraph](https://langchain-ai.github.io/langgraph/), built on top of `langchain-core`, suports [map-reduce](https://langchain-ai.github.io/langgraph/how-tos/map-reduce/) workflows and is well-suited to this problem:\n",
|
||||
"[LangGraph](https://langchain-ai.github.io/langgraph/), built on top of `langchain-core`, supports [map-reduce](https://langchain-ai.github.io/langgraph/how-tos/map-reduce/) workflows and is well-suited to this problem:\n",
|
||||
"\n",
|
||||
"- LangGraph allows for individual steps (such as successive summarizations) to be streamed, allowing for greater control of execution;\n",
|
||||
"- LangGraph's [checkpointing](https://langchain-ai.github.io/langgraph/how-tos/persistence/) supports error recovery, extending with human-in-the-loop workflows, and easier incorporation into conversational applications.\n",
|
||||
|
||||
@@ -125,8 +125,9 @@ const config = {
|
||||
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
|
||||
({
|
||||
announcementBar: {
|
||||
content: 'LangChain 0.2 is out! Leave feedback on the v0.2 docs <a href="https://github.com/langchain-ai/langchain/discussions/21716">here</a>. You can view the v0.1 docs <a href="/v0.1/docs/get_started/introduction/">here</a>.',
|
||||
isCloseable: true,
|
||||
content:
|
||||
'A newer LangChain version is out! Check out the <a href="https://python.langchain.com/docs/introduction">latest version</a>.',
|
||||
isCloseable: false,
|
||||
},
|
||||
docs: {
|
||||
sidebar: {
|
||||
@@ -219,6 +220,10 @@ const config = {
|
||||
label: "v0.2",
|
||||
position: "right",
|
||||
items: [
|
||||
{
|
||||
label: "Latest",
|
||||
href: "https://python.langchain.com/docs/introduction/"
|
||||
},
|
||||
{
|
||||
label: "v0.2",
|
||||
href: "/docs/introduction"
|
||||
|
||||
@@ -4,20 +4,25 @@ echo "VERCEL_ENV: $VERCEL_ENV"
|
||||
echo "VERCEL_GIT_COMMIT_REF: $VERCEL_GIT_COMMIT_REF"
|
||||
|
||||
|
||||
if [ "$VERCEL_ENV" == "production" ] || [ "$VERCEL_GIT_COMMIT_REF" == "master" ] || [ "$VERCEL_GIT_COMMIT_REF" == "v0.1" ]; then
|
||||
echo "✅ Production build - proceeding with build"
|
||||
exit 1;
|
||||
else
|
||||
echo "Checking for changes in docs/"
|
||||
if [ "$VERCEL_ENV" == "production" ] || \
|
||||
[ "$VERCEL_GIT_COMMIT_REF" == "master" ] || \
|
||||
[ "$VERCEL_GIT_COMMIT_REF" == "v0.1" ] || \
|
||||
[ "$VERCEL_GIT_COMMIT_REF" == "v0.2" ]
|
||||
then
|
||||
echo "✅ Production build - proceeding with build"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "Checking for changes in docs/"
|
||||
echo "---"
|
||||
git log -n 50 --pretty=format:"%s" -- . | grep -v '(#'
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "---"
|
||||
git log -n 50 --pretty=format:"%s" -- . | grep -v '(#'
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "---"
|
||||
echo "✅ Changes detected in docs/ - proceeding with build"
|
||||
exit 1
|
||||
else
|
||||
echo "---"
|
||||
echo "🛑 No changes detected in docs/ - ignoring build"
|
||||
exit 0
|
||||
fi
|
||||
echo "✅ Changes detected in docs/ - proceeding with build"
|
||||
exit 1
|
||||
else
|
||||
echo "---"
|
||||
echo "🛑 No changes detected in docs/ - ignoring build"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -15,6 +15,7 @@ EXTERNAL_PACKAGES = {
|
||||
"astradb",
|
||||
"aws",
|
||||
"cohere",
|
||||
"databricks",
|
||||
"elasticsearch",
|
||||
"google-community",
|
||||
"google-genai",
|
||||
|
||||
@@ -62,6 +62,11 @@ SEARCH_TOOL_FEAT_TABLE = {
|
||||
"available_data": "Answer",
|
||||
"link": "/docs/integrations/tools/serpapi",
|
||||
},
|
||||
"Jina Search": {
|
||||
"pricing": "1M Response Tokens Free",
|
||||
"available_data": "URL, Snippet, Title, Page Content",
|
||||
"link": "/docs/integrations/tools/jina_search/",
|
||||
},
|
||||
}
|
||||
|
||||
CODE_INTERPRETER_TOOL_FEAT_TABLE = {
|
||||
|
||||
@@ -398,6 +398,7 @@ module.exports = {
|
||||
{ type: "doc", id: "contributing/documentation/style_guide", className: "hidden" },
|
||||
{ type: "doc", id: "contributing/documentation/setup", className: "hidden" },
|
||||
"contributing/testing",
|
||||
"contributing/review_process",
|
||||
"contributing/faq",
|
||||
],
|
||||
collapsible: false,
|
||||
|
||||
@@ -248,16 +248,26 @@ nav, h1, h2, h3, h4 {
|
||||
no-repeat;
|
||||
}
|
||||
|
||||
div[class^=announcementBar_] {
|
||||
height:40px !important;
|
||||
font-size: 20px !important;
|
||||
}
|
||||
div[class^='announcementBar_'] {
|
||||
font-size: 20px;
|
||||
|
||||
[data-theme='dark'] div[class^=announcementBar_] {
|
||||
background-color: #1b1b1b;
|
||||
color: #fff;
|
||||
}
|
||||
/*
|
||||
--site-announcement-bar-stripe-color1: hsl(
|
||||
var(--site-primary-hue-saturation) 85%
|
||||
);
|
||||
--site-announcement-bar-stripe-color2: hsl(
|
||||
var(--site-primary-hue-saturation) 95%
|
||||
);
|
||||
*/
|
||||
--site-announcement-bar-stripe-color1: rgb(197,186,254);
|
||||
--site-announcement-bar-stripe-color2: rgb(255,246,224);
|
||||
|
||||
[data-theme='dark'] div[class^=announcementBar_] button {
|
||||
color: #fff;
|
||||
background: repeating-linear-gradient(
|
||||
-35deg,
|
||||
var(--site-announcement-bar-stripe-color1),
|
||||
var(--site-announcement-bar-stripe-color1) 20px,
|
||||
var(--site-announcement-bar-stripe-color2) 10px,
|
||||
var(--site-announcement-bar-stripe-color2) 40px
|
||||
);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@@ -3,18 +3,10 @@
|
||||
|
||||
import React from 'react';
|
||||
import clsx from 'clsx';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import Link from '@docusaurus/Link';
|
||||
import Translate from '@docusaurus/Translate';
|
||||
import {
|
||||
useActivePlugin,
|
||||
useDocVersionSuggestions,
|
||||
} from '@docusaurus/plugin-content-docs/client';
|
||||
import {ThemeClassNames} from '@docusaurus/theme-common';
|
||||
import {
|
||||
useDocsPreferredVersion,
|
||||
useDocsVersion,
|
||||
} from '@docusaurus/theme-common/internal';
|
||||
import { useLocalPathname } from '@docusaurus/theme-common/internal';
|
||||
function UnreleasedVersionLabel({siteTitle, versionMetadata}) {
|
||||
return (
|
||||
<Translate
|
||||
@@ -79,123 +71,40 @@ function LatestVersionSuggestionLabel({versionLabel, to, onClick}) {
|
||||
</Translate>
|
||||
);
|
||||
}
|
||||
function DocVersionBannerEnabled({className, versionMetadata}) {
|
||||
const {
|
||||
siteConfig: {title: siteTitle},
|
||||
} = useDocusaurusContext();
|
||||
const {pluginId} = useActivePlugin({failfast: true});
|
||||
const getVersionMainDoc = (version) =>
|
||||
version.docs.find((doc) => doc.id === version.mainDocId);
|
||||
const {savePreferredVersionName} = useDocsPreferredVersion(pluginId);
|
||||
const {latestDocSuggestion, latestVersionSuggestion} =
|
||||
useDocVersionSuggestions(pluginId);
|
||||
// Try to link to same doc in latest version (not always possible), falling
|
||||
// back to main doc of latest version
|
||||
const latestVersionSuggestedDoc =
|
||||
latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion);
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
className,
|
||||
ThemeClassNames.docs.docVersionBanner,
|
||||
'alert alert--warning margin-bottom--md',
|
||||
)}
|
||||
role="alert">
|
||||
<div>
|
||||
<BannerLabel siteTitle={siteTitle} versionMetadata={versionMetadata} />
|
||||
</div>
|
||||
<div className="margin-top--md">
|
||||
<LatestVersionSuggestionLabel
|
||||
versionLabel={latestVersionSuggestion.label}
|
||||
to={latestVersionSuggestedDoc.path}
|
||||
onClick={() => savePreferredVersionName(latestVersionSuggestion.name)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LatestDocVersionBanner({className, versionMetadata}) {
|
||||
const {
|
||||
siteConfig: {title: siteTitle},
|
||||
} = useDocusaurusContext();
|
||||
const {pluginId} = useActivePlugin({failfast: true});
|
||||
const getVersionMainDoc = (version) =>
|
||||
version.docs.find((doc) => doc.id === version.mainDocId);
|
||||
const {savePreferredVersionName} = useDocsPreferredVersion(pluginId);
|
||||
const {latestDocSuggestion, latestVersionSuggestion} =
|
||||
useDocVersionSuggestions(pluginId);
|
||||
// Try to link to same doc in latest version (not always possible), falling
|
||||
// back to main doc of latest version
|
||||
const latestVersionSuggestedDoc =
|
||||
latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion);
|
||||
const canaryPath = `/docs/0.2.x/${latestVersionSuggestedDoc.path.slice("/docs/".length)}`;
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
className,
|
||||
ThemeClassNames.docs.docVersionBanner,
|
||||
'alert alert--info margin-bottom--md',
|
||||
)}
|
||||
role="alert">
|
||||
<div>
|
||||
<Translate
|
||||
id="theme.docs.versions.unmaintainedVersionLabel"
|
||||
description="The label used to encourage the user to view the experimental 0.2.x version"
|
||||
values={{
|
||||
siteTitle,
|
||||
versionLabel: <b>{versionMetadata.label}</b>,
|
||||
}}>
|
||||
{
|
||||
'This is a stable version of documentation for {siteTitle}\'s version {versionLabel}.'
|
||||
}
|
||||
</Translate>
|
||||
</div>
|
||||
<div className="margin-top--md">
|
||||
<Translate
|
||||
id="theme.docs.versions.latestVersionSuggestionLabel"
|
||||
description="The label used to tell the user to check the experimental version"
|
||||
values={{
|
||||
versionLabel: <b>{versionMetadata.label}</b>,
|
||||
latestVersionLink: (
|
||||
<b>
|
||||
<Link to={canaryPath} onClick={() => savePreferredVersionName("0.2.x")}>
|
||||
<Translate
|
||||
id="theme.docs.versions.latestVersionLinkLabel"
|
||||
description="The label used for the latest version suggestion link label">
|
||||
this experimental version
|
||||
</Translate>
|
||||
</Link>
|
||||
</b>
|
||||
),
|
||||
}}>
|
||||
{
|
||||
'You can also check out {latestVersionLink} for an updated experience.'
|
||||
}
|
||||
</Translate>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function DocVersionBanner({className}) {
|
||||
const versionMetadata = useDocsVersion();
|
||||
const versionMetadata = {
|
||||
badge: false,
|
||||
banner: 'unmaintained',
|
||||
isLast: false,
|
||||
label: 'v0.2',
|
||||
noIndex: false,
|
||||
pluginId: 'default',
|
||||
version: 'Latest',
|
||||
}
|
||||
console.log({versionMetadata});
|
||||
const localPathname = useLocalPathname();
|
||||
if (versionMetadata.banner) {
|
||||
return (
|
||||
<DocVersionBannerEnabled
|
||||
className={className}
|
||||
versionMetadata={versionMetadata}
|
||||
/>
|
||||
<div
|
||||
className={clsx(
|
||||
className,
|
||||
ThemeClassNames.docs.docVersionBanner,
|
||||
'alert alert--warning margin-bottom--md',
|
||||
)}
|
||||
role="alert">
|
||||
<div>
|
||||
<BannerLabel siteTitle={"LangChain"} versionMetadata={versionMetadata} />
|
||||
</div>
|
||||
<div className="margin-top--md">
|
||||
<LatestVersionSuggestionLabel
|
||||
versionLabel={"Latest"}
|
||||
to={`https://python.langchain.com${localPathname}`}
|
||||
onClick={() => {}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
} else if (versionMetadata.isLast) {
|
||||
// Uncomment when we are ready to direct people to new build
|
||||
// return (
|
||||
// <LatestDocVersionBanner
|
||||
// className={className}
|
||||
// versionMetadata={versionMetadata}
|
||||
// />
|
||||
// );
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -204,6 +204,17 @@ const FEATURE_TABLES = {
|
||||
"multimodal": false,
|
||||
"local": false,
|
||||
"apiLink": "https://python.langchain.com/v0.2/api_reference/upstage/chat_models/langchain_upstage.chat_models.ChatUpstage.html"
|
||||
},
|
||||
{
|
||||
"name": "ChatDatabricks",
|
||||
"package": "langchain-databricks",
|
||||
"link": "databricks",
|
||||
"structured_output": true,
|
||||
"tool_calling": true,
|
||||
"json_mode": false,
|
||||
"multimodal": false,
|
||||
"local": false,
|
||||
"apiLink": "https://python.langchain.com/v0.2/api_reference/upstage/chat_models/langchain_databricks.chat_models.ChatDatabricks.html"
|
||||
}
|
||||
],
|
||||
},
|
||||
@@ -347,6 +358,12 @@ const FEATURE_TABLES = {
|
||||
package: "langchain-nomic",
|
||||
apiLink: "https://python.langchain.com/v0.2/api_reference/nomic/embeddings/langchain_nomic.embeddings.NomicEmbeddings.html"
|
||||
},
|
||||
{
|
||||
name: "Databricks",
|
||||
link: "databricks",
|
||||
package: "langchain-databricks",
|
||||
apiLink: "https://python.langchain.com/v0.2/api_reference/nomic/embeddings/langchain_databricks.embeddings.DatabricksEmbeddings.html"
|
||||
},
|
||||
]
|
||||
},
|
||||
document_retrievers: {
|
||||
@@ -945,6 +962,19 @@ const FEATURE_TABLES = {
|
||||
local: true,
|
||||
idsInAddDocuments: false,
|
||||
},
|
||||
{
|
||||
name: "DatabricksVectorSearch",
|
||||
link: "databricks_vector_search",
|
||||
deleteById: true,
|
||||
filtering: true,
|
||||
searchByVector: true,
|
||||
searchWithScore: true,
|
||||
async: true,
|
||||
passesStandardTests: false,
|
||||
multiTenancy: false,
|
||||
local: false,
|
||||
idsInAddDocuments: false,
|
||||
},
|
||||
{
|
||||
name: "ElasticsearchStore",
|
||||
link: "elasticsearch",
|
||||
@@ -1012,7 +1042,7 @@ const FEATURE_TABLES = {
|
||||
},
|
||||
{
|
||||
name: "PGVector",
|
||||
link: "pg_vector",
|
||||
link: "pgvector",
|
||||
deleteById: true,
|
||||
filtering: true,
|
||||
searchByVector: true,
|
||||
|
||||
120
docs/src/theme/SiteMetadata/index.js
Normal file
120
docs/src/theme/SiteMetadata/index.js
Normal file
@@ -0,0 +1,120 @@
|
||||
import React from 'react';
|
||||
import Head from '@docusaurus/Head';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||
import {PageMetadata, useThemeConfig} from '@docusaurus/theme-common';
|
||||
import {
|
||||
DEFAULT_SEARCH_TAG,
|
||||
useAlternatePageUtils,
|
||||
keyboardFocusedClassName,
|
||||
} from '@docusaurus/theme-common/internal';
|
||||
import {useLocation} from '@docusaurus/router';
|
||||
import {applyTrailingSlash} from '@docusaurus/utils-common';
|
||||
import SearchMetadata from '@theme/SearchMetadata';
|
||||
// TODO move to SiteMetadataDefaults or theme-common ?
|
||||
// Useful for i18n/SEO
|
||||
// See https://developers.google.com/search/docs/advanced/crawling/localized-versions
|
||||
// See https://github.com/facebook/docusaurus/issues/3317
|
||||
function AlternateLangHeaders() {
|
||||
const {
|
||||
i18n: {defaultLocale, localeConfigs},
|
||||
} = useDocusaurusContext();
|
||||
const alternatePageUtils = useAlternatePageUtils();
|
||||
// Note: it is fine to use both "x-default" and "en" to target the same url
|
||||
// See https://www.searchviu.com/en/multiple-hreflang-tags-one-url/
|
||||
return (
|
||||
<Head>
|
||||
{Object.entries(localeConfigs).map(([locale, {htmlLang}]) => (
|
||||
<link
|
||||
key={locale}
|
||||
rel="alternate"
|
||||
href={alternatePageUtils.createUrl({
|
||||
locale,
|
||||
fullyQualified: true,
|
||||
})}
|
||||
hrefLang={htmlLang}
|
||||
/>
|
||||
))}
|
||||
<link
|
||||
rel="alternate"
|
||||
href={alternatePageUtils.createUrl({
|
||||
locale: defaultLocale,
|
||||
fullyQualified: true,
|
||||
})}
|
||||
hrefLang="x-default"
|
||||
/>
|
||||
</Head>
|
||||
);
|
||||
}
|
||||
// Default canonical url inferred from current page location pathname
|
||||
function useDefaultCanonicalUrl() {
|
||||
const {
|
||||
siteConfig: {url: siteUrl, baseUrl, trailingSlash},
|
||||
} = useDocusaurusContext();
|
||||
// TODO using useLocation().pathname is not a super idea
|
||||
// See https://github.com/facebook/docusaurus/issues/9170
|
||||
const {pathname} = useLocation();
|
||||
const baseUrlPathname = useBaseUrl(pathname);
|
||||
const canonicalPathname = applyTrailingSlash(baseUrlPathname, {
|
||||
trailingSlash,
|
||||
baseUrl,
|
||||
});
|
||||
const canonicalPathnameNoVersion = canonicalPathname.startsWith('/v0.') ? "/"+canonicalPathname.split('/').slice(2).join('/') : canonicalPathname;
|
||||
return siteUrl + canonicalPathnameNoVersion;
|
||||
}
|
||||
|
||||
// TODO move to SiteMetadataDefaults or theme-common ?
|
||||
function CanonicalUrlHeaders({permalink}) {
|
||||
const {
|
||||
siteConfig: {url: siteUrl},
|
||||
} = useDocusaurusContext();
|
||||
const defaultCanonicalUrl = useDefaultCanonicalUrl();
|
||||
const canonicalUrl = permalink
|
||||
? `${siteUrl}${permalink}`
|
||||
: defaultCanonicalUrl;
|
||||
return (
|
||||
<Head>
|
||||
<meta property="og:url" content={canonicalUrl} />
|
||||
<link rel="canonical" href={canonicalUrl} />
|
||||
</Head>
|
||||
);
|
||||
}
|
||||
export default function SiteMetadata() {
|
||||
const {
|
||||
i18n: {currentLocale},
|
||||
} = useDocusaurusContext();
|
||||
// TODO maybe move these 2 themeConfig to siteConfig?
|
||||
// These seems useful for other themes as well
|
||||
const {metadata, image: defaultImage} = useThemeConfig();
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
{/* The keyboard focus class name need to be applied when SSR so links
|
||||
are outlined when JS is disabled */}
|
||||
<body className={keyboardFocusedClassName} />
|
||||
</Head>
|
||||
|
||||
{defaultImage && <PageMetadata image={defaultImage} />}
|
||||
|
||||
<CanonicalUrlHeaders />
|
||||
|
||||
<AlternateLangHeaders />
|
||||
|
||||
<SearchMetadata tag={DEFAULT_SEARCH_TAG} locale={currentLocale} />
|
||||
|
||||
{/*
|
||||
It's important to have an additional <Head> element here, as it allows
|
||||
react-helmet to override default metadata values set in previous <Head>
|
||||
like "twitter:card". In same Head, the same meta would appear twice
|
||||
instead of overriding.
|
||||
*/}
|
||||
<Head>
|
||||
{/* Yes, "metadatum" is the grammatically correct term */}
|
||||
{metadata.map((metadatum, i) => (
|
||||
<meta key={i} {...metadatum} />
|
||||
))}
|
||||
</Head>
|
||||
</>
|
||||
);
|
||||
}
|
||||
BIN
docs/static/img/review_process_status.png
vendored
Normal file
BIN
docs/static/img/review_process_status.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 161 KiB |
@@ -4,6 +4,10 @@
|
||||
"ignoreCommand": "bash ignore-step.sh",
|
||||
"trailingSlash": true,
|
||||
"rewrites": [
|
||||
{
|
||||
"source": "/v0.2/docs/integrations(/?)",
|
||||
"destination": "/v0.2/docs/integrations/platforms/"
|
||||
},
|
||||
{
|
||||
"source": "/v0.1",
|
||||
"destination": "https://langchain-v01.vercel.app/v0.1"
|
||||
|
||||
@@ -12,6 +12,9 @@ integration_test integration_tests: TEST_FILE = tests/integration_tests/
|
||||
test tests:
|
||||
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)
|
||||
|
||||
test_watch:
|
||||
poetry run ptw --snapshot-update --now . -- -vv $(TEST_FILE)
|
||||
|
||||
# integration tests are run without the --disable-socket flag to allow network calls
|
||||
integration_test integration_tests:
|
||||
poetry run pytest $(TEST_FILE)
|
||||
|
||||
@@ -23,6 +23,7 @@ pytest = "^7.4.3"
|
||||
pytest-asyncio = "^0.23.2"
|
||||
pytest-socket = "^0.7.0"
|
||||
langchain-core = { path = "../../core", develop = true }
|
||||
pytest-watcher = "^0.3.4"
|
||||
|
||||
[tool.poetry.group.codespell]
|
||||
optional = true
|
||||
|
||||
@@ -91,7 +91,7 @@ def _is_assistants_builtin_tool(
|
||||
A boolean response of true or false indicating if the tool corresponds to
|
||||
OpenAI Assistants built-in.
|
||||
"""
|
||||
assistants_builtin_tools = ("code_interpreter", "retrieval")
|
||||
assistants_builtin_tools = ("code_interpreter", "retrieval", "file_search")
|
||||
return (
|
||||
isinstance(tool, dict)
|
||||
and ("type" in tool)
|
||||
|
||||
@@ -16,6 +16,7 @@ from langchain_core.messages import (
|
||||
ChatMessageChunk,
|
||||
HumanMessage,
|
||||
HumanMessageChunk,
|
||||
SystemMessage,
|
||||
)
|
||||
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
|
||||
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator
|
||||
@@ -33,6 +34,8 @@ def _convert_message_to_dict(message: BaseMessage) -> dict:
|
||||
message_dict: Dict[str, Any]
|
||||
if isinstance(message, ChatMessage):
|
||||
message_dict = {"Role": message.role, "Content": message.content}
|
||||
elif isinstance(message, SystemMessage):
|
||||
message_dict = {"Role": "system", "Content": message.content}
|
||||
elif isinstance(message, HumanMessage):
|
||||
message_dict = {"Role": "user", "Content": message.content}
|
||||
elif isinstance(message, AIMessage):
|
||||
@@ -45,7 +48,9 @@ def _convert_message_to_dict(message: BaseMessage) -> dict:
|
||||
|
||||
def _convert_dict_to_message(_dict: Mapping[str, Any]) -> BaseMessage:
|
||||
role = _dict["Role"]
|
||||
if role == "user":
|
||||
if role == "system":
|
||||
return SystemMessage(content=_dict.get("Content", "") or "")
|
||||
elif role == "user":
|
||||
return HumanMessage(content=_dict["Content"])
|
||||
elif role == "assistant":
|
||||
return AIMessage(content=_dict.get("Content", "") or "")
|
||||
@@ -73,6 +78,7 @@ def _create_chat_result(response: Mapping[str, Any]) -> ChatResult:
|
||||
generations = []
|
||||
for choice in response["Choices"]:
|
||||
message = _convert_dict_to_message(choice["Message"])
|
||||
message.id = response.get("Id", "")
|
||||
generations.append(ChatGeneration(message=message))
|
||||
|
||||
token_usage = response["Usage"]
|
||||
@@ -115,7 +121,7 @@ class ChatHunyuan(BaseChatModel):
|
||||
model: str = "hunyuan-lite"
|
||||
"""What Model to use.
|
||||
Optional model:
|
||||
- hunyuan-lite、
|
||||
- hunyuan-lite
|
||||
- hunyuan-standard
|
||||
- hunyuan-standard-256K
|
||||
- hunyuan-pro
|
||||
@@ -233,6 +239,7 @@ class ChatHunyuan(BaseChatModel):
|
||||
chunk = _convert_delta_to_message_chunk(
|
||||
choice["Delta"], default_chunk_class
|
||||
)
|
||||
chunk.id = response.get("Id", "")
|
||||
default_chunk_class = chunk.__class__
|
||||
cg_chunk = ChatGenerationChunk(message=chunk)
|
||||
if run_manager:
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
"""OctoAI Endpoints chat wrapper. Relies heavily on ChatOpenAI."""
|
||||
|
||||
from typing import Dict
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
Literal,
|
||||
Optional,
|
||||
Sequence,
|
||||
Type,
|
||||
Union,
|
||||
)
|
||||
|
||||
from langchain_core.language_models import LanguageModelInput
|
||||
from langchain_core.messages import BaseMessage
|
||||
from langchain_core.pydantic_v1 import Field, SecretStr
|
||||
from langchain_core.runnables import Runnable
|
||||
from langchain_core.tools import BaseTool
|
||||
from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env, pre_init
|
||||
from langchain_core.utils.function_calling import convert_to_openai_tool
|
||||
|
||||
from langchain_community.chat_models.openai import ChatOpenAI
|
||||
from langchain_community.utils.openai import is_openai_v1
|
||||
@@ -92,3 +106,53 @@ class ChatOctoAI(ChatOpenAI):
|
||||
)
|
||||
|
||||
return values
|
||||
|
||||
def bind_tools(
|
||||
self,
|
||||
tools: Sequence[Union[Dict[str, Any], Type, Callable, BaseTool]],
|
||||
*,
|
||||
tool_choice: Optional[
|
||||
Union[dict, str, Literal["auto", "none", "required", "any"], bool]
|
||||
] = None,
|
||||
strict: Optional[bool] = None,
|
||||
**kwargs: Any,
|
||||
) -> Runnable[LanguageModelInput, BaseMessage]:
|
||||
"""Imitating bind_tool method from langchain_openai.ChatOpenAI"""
|
||||
|
||||
formatted_tools = [
|
||||
convert_to_openai_tool(tool, strict=strict) for tool in tools
|
||||
]
|
||||
if tool_choice:
|
||||
if isinstance(tool_choice, str):
|
||||
# tool_choice is a tool/function name
|
||||
if tool_choice not in ("auto", "none", "any", "required"):
|
||||
tool_choice = {
|
||||
"type": "function",
|
||||
"function": {"name": tool_choice},
|
||||
}
|
||||
# 'any' is not natively supported by OpenAI API.
|
||||
# We support 'any' since other models use this instead of 'required'.
|
||||
if tool_choice == "any":
|
||||
tool_choice = "required"
|
||||
elif isinstance(tool_choice, bool):
|
||||
tool_choice = "required"
|
||||
elif isinstance(tool_choice, dict):
|
||||
tool_names = [
|
||||
formatted_tool["function"]["name"]
|
||||
for formatted_tool in formatted_tools
|
||||
]
|
||||
if not any(
|
||||
tool_name == tool_choice["function"]["name"]
|
||||
for tool_name in tool_names
|
||||
):
|
||||
raise ValueError(
|
||||
f"Tool choice {tool_choice} was specified, but the only "
|
||||
f"provided tools were {tool_names}."
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Unrecognized tool_choice type. Expected str, bool or dict. "
|
||||
f"Received: {tool_choice}"
|
||||
)
|
||||
kwargs["tool_choice"] = tool_choice
|
||||
return super().bind(tools=formatted_tools, **kwargs)
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
@@ -146,6 +147,33 @@ def _convert_delta_to_message_chunk(
|
||||
return default_class(content=content) # type: ignore[call-arg]
|
||||
|
||||
|
||||
def _update_token_usage(
|
||||
overall_token_usage: Union[int, dict], new_usage: Union[int, dict]
|
||||
) -> Union[int, dict]:
|
||||
# Token usage is either ints or dictionaries
|
||||
# `reasoning_tokens` is nested inside `completion_tokens_details`
|
||||
if isinstance(new_usage, int):
|
||||
if not isinstance(overall_token_usage, int):
|
||||
raise ValueError(
|
||||
f"Got different types for token usage: "
|
||||
f"{type(new_usage)} and {type(overall_token_usage)}"
|
||||
)
|
||||
return new_usage + overall_token_usage
|
||||
elif isinstance(new_usage, dict):
|
||||
if not isinstance(overall_token_usage, dict):
|
||||
raise ValueError(
|
||||
f"Got different types for token usage: "
|
||||
f"{type(new_usage)} and {type(overall_token_usage)}"
|
||||
)
|
||||
return {
|
||||
k: _update_token_usage(overall_token_usage.get(k, 0), v)
|
||||
for k, v in new_usage.items()
|
||||
}
|
||||
else:
|
||||
warnings.warn(f"Unexpected type for token usage: {type(new_usage)}")
|
||||
return new_usage
|
||||
|
||||
|
||||
@deprecated(
|
||||
since="0.0.10", removal="1.0", alternative_import="langchain_openai.ChatOpenAI"
|
||||
)
|
||||
@@ -374,7 +402,9 @@ class ChatOpenAI(BaseChatModel):
|
||||
if token_usage is not None:
|
||||
for k, v in token_usage.items():
|
||||
if k in overall_token_usage:
|
||||
overall_token_usage[k] += v
|
||||
overall_token_usage[k] = _update_token_usage(
|
||||
overall_token_usage[k], v
|
||||
)
|
||||
else:
|
||||
overall_token_usage[k] = v
|
||||
if system_fingerprint is None:
|
||||
@@ -403,6 +433,8 @@ class ChatOpenAI(BaseChatModel):
|
||||
if len(chunk["choices"]) == 0:
|
||||
continue
|
||||
choice = chunk["choices"][0]
|
||||
if choice["delta"] is None:
|
||||
continue
|
||||
chunk = _convert_delta_to_message_chunk(
|
||||
choice["delta"], default_chunk_class
|
||||
)
|
||||
@@ -495,6 +527,8 @@ class ChatOpenAI(BaseChatModel):
|
||||
if len(chunk["choices"]) == 0:
|
||||
continue
|
||||
choice = chunk["choices"][0]
|
||||
if choice["delta"] is None:
|
||||
continue
|
||||
chunk = _convert_delta_to_message_chunk(
|
||||
choice["delta"], default_chunk_class
|
||||
)
|
||||
|
||||
@@ -104,6 +104,8 @@ class CSVLoader(BaseLoader):
|
||||
csv_args: Optional[Dict] = None,
|
||||
encoding: Optional[str] = None,
|
||||
autodetect_encoding: bool = False,
|
||||
*,
|
||||
content_columns: Sequence[str] = (),
|
||||
):
|
||||
"""
|
||||
|
||||
@@ -116,6 +118,8 @@ class CSVLoader(BaseLoader):
|
||||
Optional. Defaults to None.
|
||||
encoding: The encoding of the CSV file. Optional. Defaults to None.
|
||||
autodetect_encoding: Whether to try to autodetect the file encoding.
|
||||
content_columns: A sequence of column names to use for the document content.
|
||||
If not present, use all columns that are not part of the metadata.
|
||||
"""
|
||||
self.file_path = file_path
|
||||
self.source_column = source_column
|
||||
@@ -123,6 +127,7 @@ class CSVLoader(BaseLoader):
|
||||
self.encoding = encoding
|
||||
self.csv_args = csv_args or {}
|
||||
self.autodetect_encoding = autodetect_encoding
|
||||
self.content_columns = content_columns
|
||||
|
||||
def lazy_load(self) -> Iterator[Document]:
|
||||
try:
|
||||
@@ -163,7 +168,11 @@ class CSVLoader(BaseLoader):
|
||||
if isinstance(v, str) else ','.join(map(str.strip, v))
|
||||
if isinstance(v, list) else v}"""
|
||||
for k, v in row.items()
|
||||
if k not in self.metadata_columns
|
||||
if (
|
||||
k in self.content_columns
|
||||
if self.content_columns
|
||||
else k not in self.metadata_columns
|
||||
)
|
||||
)
|
||||
metadata = {"source": source, "row": i}
|
||||
for col in self.metadata_columns:
|
||||
|
||||
@@ -12,6 +12,7 @@ MIN_VERSION = "0.2.0"
|
||||
|
||||
class FastEmbedEmbeddings(BaseModel, Embeddings):
|
||||
"""Qdrant FastEmbedding models.
|
||||
|
||||
FastEmbed is a lightweight, fast, Python library built for embedding generation.
|
||||
See more documentation at:
|
||||
* https://github.com/qdrant/fastembed/
|
||||
|
||||
@@ -67,6 +67,19 @@ class HuggingFaceEmbeddings(BaseModel, Embeddings):
|
||||
def __init__(self, **kwargs: Any):
|
||||
"""Initialize the sentence_transformer."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
if "model_name" not in kwargs:
|
||||
since = "0.2.16"
|
||||
removal = "0.4.0"
|
||||
warn_deprecated(
|
||||
since=since,
|
||||
removal=removal,
|
||||
message=f"Default values for {self.__class__.__name__}.model_name"
|
||||
+ f" were deprecated in LangChain {since} and will be removed in"
|
||||
+ f" {removal}. Explicitly pass a model_name to the"
|
||||
+ f" {self.__class__.__name__} constructor instead.",
|
||||
)
|
||||
|
||||
try:
|
||||
import sentence_transformers
|
||||
|
||||
@@ -159,6 +172,19 @@ class HuggingFaceInstructEmbeddings(BaseModel, Embeddings):
|
||||
def __init__(self, **kwargs: Any):
|
||||
"""Initialize the sentence_transformer."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
if "model_name" not in kwargs:
|
||||
since = "0.2.16"
|
||||
removal = "0.4.0"
|
||||
warn_deprecated(
|
||||
since=since,
|
||||
removal=removal,
|
||||
message=f"Default values for {self.__class__.__name__}.model_name"
|
||||
+ f" were deprecated in LangChain {since} and will be removed in"
|
||||
+ f" {removal}. Explicitly pass a model_name to the"
|
||||
+ f" {self.__class__.__name__} constructor instead.",
|
||||
)
|
||||
|
||||
try:
|
||||
from InstructorEmbedding import INSTRUCTOR
|
||||
|
||||
@@ -231,7 +257,7 @@ class HuggingFaceBgeEmbeddings(BaseModel, Embeddings):
|
||||
|
||||
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
||||
|
||||
model_name = "BAAI/bge-large-en"
|
||||
model_name = "BAAI/bge-large-en-v1.5"
|
||||
model_kwargs = {'device': 'cpu'}
|
||||
encode_kwargs = {'normalize_embeddings': True}
|
||||
hf = HuggingFaceBgeEmbeddings(
|
||||
@@ -279,6 +305,19 @@ class HuggingFaceBgeEmbeddings(BaseModel, Embeddings):
|
||||
def __init__(self, **kwargs: Any):
|
||||
"""Initialize the sentence_transformer."""
|
||||
super().__init__(**kwargs)
|
||||
|
||||
if "model_name" not in kwargs:
|
||||
since = "0.2.5"
|
||||
removal = "0.4.0"
|
||||
warn_deprecated(
|
||||
since=since,
|
||||
removal=removal,
|
||||
message=f"Default values for {self.__class__.__name__}.model_name"
|
||||
+ f" were deprecated in LangChain {since} and will be removed in"
|
||||
+ f" {removal}. Explicitly pass a model_name to the"
|
||||
+ f" {self.__class__.__name__} constructor instead.",
|
||||
)
|
||||
|
||||
try:
|
||||
import sentence_transformers
|
||||
|
||||
|
||||
@@ -57,6 +57,9 @@ class LlamaCppEmbeddings(BaseModel, Embeddings):
|
||||
verbose: bool = Field(True, alias="verbose")
|
||||
"""Print verbose output to stderr."""
|
||||
|
||||
device: Optional[str] = Field(None, alias="device")
|
||||
"""Device type to use and pass to the model"""
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
@@ -75,6 +78,7 @@ class LlamaCppEmbeddings(BaseModel, Embeddings):
|
||||
"n_threads",
|
||||
"n_batch",
|
||||
"verbose",
|
||||
"device",
|
||||
]
|
||||
model_params = {k: values[k] for k in model_param_names}
|
||||
# For backwards compatibility, only include if non-null.
|
||||
@@ -108,8 +112,8 @@ class LlamaCppEmbeddings(BaseModel, Embeddings):
|
||||
Returns:
|
||||
List of embeddings, one for each text.
|
||||
"""
|
||||
embeddings = [self.client.embed(text) for text in texts]
|
||||
return [list(map(float, e)) for e in embeddings]
|
||||
embeddings = self.client.create_embedding(texts)
|
||||
return [list(map(float, e["embedding"])) for e in embeddings["data"]]
|
||||
|
||||
def embed_query(self, text: str) -> List[float]:
|
||||
"""Embed a query using the Llama model.
|
||||
|
||||
@@ -303,7 +303,7 @@ class OpenVINOBgeEmbeddings(OpenVINOEmbeddings):
|
||||
|
||||
from langchain_community.embeddings import OpenVINOBgeEmbeddings
|
||||
|
||||
model_name = "BAAI/bge-large-en"
|
||||
model_name = "BAAI/bge-large-en-v1.5"
|
||||
model_kwargs = {'device': 'CPU'}
|
||||
encode_kwargs = {'normalize_embeddings': True}
|
||||
ov = OpenVINOBgeEmbeddings(
|
||||
|
||||
@@ -1,3 +1,161 @@
|
||||
from langchain_community.graph_vectorstores.cassandra import CassandraGraphVectorStore
|
||||
"""**Graph Vector Store**
|
||||
|
||||
__all__ = ["CassandraGraphVectorStore"]
|
||||
Sometimes embedding models don’t capture all the important relationships between
|
||||
documents.
|
||||
Graph Vector Stores are an extension to both vector stores and retrievers that allow
|
||||
documents to be explicitly connected to each other.
|
||||
|
||||
Graph vector store retrievers use both vector similarity and links to find documents
|
||||
related to an unstructured query.
|
||||
|
||||
Graphs allow linking between documents.
|
||||
Each document identifies tags that link to and from it.
|
||||
For example, a paragraph of text may be linked to URLs based on the anchor tags in
|
||||
it's content and linked from the URL(s) it is published at.
|
||||
|
||||
Link extractors can be used to extract links from documents.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
graph_vector_store = CassandraGraphVectorStore()
|
||||
link_extractor = HtmlLinkExtractor()
|
||||
links = link_extractor.extract_one(HtmlInput(document.page_content, "http://mysite"))
|
||||
add_links(document, links)
|
||||
graph_vector_store.add_document(document)
|
||||
|
||||
***********
|
||||
Get started
|
||||
***********
|
||||
|
||||
We chunk the State of the Union text and split it into documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_community.document_loaders import TextLoader
|
||||
from langchain_text_splitters import CharacterTextSplitter
|
||||
|
||||
raw_documents = TextLoader("state_of_the_union.txt").load()
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
documents = text_splitter.split_documents(raw_documents)
|
||||
|
||||
Links can be added to documents manually but it's easier to use a
|
||||
:class:`~langchain_community.graph_vectorstores.extractors.LinkExtractor`.
|
||||
Several common link extractors are available and you can build your own.
|
||||
For this guide, we'll use the
|
||||
:class:`~langchain_community.graph_vectorstores.extractors.KeybertLinkExtractor`
|
||||
which uses the KeyBERT model to tag documents with keywords and uses these keywords to
|
||||
create links between documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_community.graph_vectorstores.extractors import KeybertLinkExtractor
|
||||
from langchain_community.graph_vectorstores.links import add_links
|
||||
|
||||
extractor = KeybertLinkExtractor()
|
||||
|
||||
for doc in documents:
|
||||
add_links(doc, extractor.extract_one(doc))
|
||||
|
||||
***********************************************
|
||||
Create the graph vector store and add documents
|
||||
***********************************************
|
||||
|
||||
We'll use an Apache Cassandra or Astra DB database as an example.
|
||||
We create a :class:`~langchain_community.graph_vectorstores.CassandraGraphVectorStore`
|
||||
from the documents and an :class:`~langchain_openai.OpenAIEmbeddings` model.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import cassio
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
from langchain_openai import OpenAIEmbeddings
|
||||
|
||||
# Initialize cassio and the Cassandra session from the environment variables
|
||||
cassio.init(auto=True)
|
||||
|
||||
store = CassandraGraphVectorStore.from_documents(
|
||||
embedding=OpenAIEmbeddings(),
|
||||
documents=documents,
|
||||
)
|
||||
|
||||
*****************
|
||||
Similarity search
|
||||
*****************
|
||||
|
||||
If we don't traverse the graph, a graph vector store behaves like a regular vector
|
||||
store.
|
||||
So all methods available in a vector store are also available in a graph vector store.
|
||||
The :meth:`~langchain_community.graph_vectorstores.base.GraphVectorStore.similarity_search`
|
||||
method returns documents similar to a query without considering
|
||||
the links between documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
docs = store.similarity_search(
|
||||
"What did the president say about Ketanji Brown Jackson?"
|
||||
)
|
||||
|
||||
****************
|
||||
Traversal search
|
||||
****************
|
||||
|
||||
The :meth:`~langchain_community.graph_vectorstores.base.GraphVectorStore.traversal_search`
|
||||
method returns documents similar to a query considering the links
|
||||
between documents. It first does a similarity search and then traverses the graph to
|
||||
find linked documents.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
docs = list(
|
||||
store.traversal_search("What did the president say about Ketanji Brown Jackson?")
|
||||
)
|
||||
|
||||
*************
|
||||
Async methods
|
||||
*************
|
||||
|
||||
The graph vector store has async versions of the methods prefixed with ``a``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
docs = [
|
||||
doc
|
||||
async for doc in store.atraversal_search(
|
||||
"What did the president say about Ketanji Brown Jackson?"
|
||||
)
|
||||
]
|
||||
|
||||
****************************
|
||||
Graph vector store retriever
|
||||
****************************
|
||||
|
||||
The graph vector store can be converted to a retriever.
|
||||
It is similar to the vector store retriever but it also has traversal search methods
|
||||
such as ``traversal`` and ``mmr_traversal``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
retriever = store.as_retriever(search_type="mmr_traversal")
|
||||
docs = retriever.invoke("What did the president say about Ketanji Brown Jackson?")
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
from langchain_community.graph_vectorstores.base import (
|
||||
GraphVectorStore,
|
||||
GraphVectorStoreRetriever,
|
||||
Node,
|
||||
)
|
||||
from langchain_community.graph_vectorstores.cassandra import CassandraGraphVectorStore
|
||||
from langchain_community.graph_vectorstores.links import (
|
||||
Link,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"GraphVectorStore",
|
||||
"GraphVectorStoreRetriever",
|
||||
"Node",
|
||||
"Link",
|
||||
"CassandraGraphVectorStore",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
from langchain_core.graph_vectorstores.base import (
|
||||
GraphVectorStore,
|
||||
GraphVectorStoreRetriever,
|
||||
Node,
|
||||
)
|
||||
|
||||
__all__ = ["GraphVectorStore", "GraphVectorStoreRetriever", "Node"]
|
||||
@@ -14,7 +14,117 @@ GLiNERInput = Union[str, Document]
|
||||
|
||||
@beta()
|
||||
class GLiNERLinkExtractor(LinkExtractor[GLiNERInput]):
|
||||
"""Link documents with common named entities using GLiNER <https://github.com/urchade/GLiNER>."""
|
||||
"""Link documents with common named entities using `GLiNER`_.
|
||||
|
||||
`GLiNER`_ is a Named Entity Recognition (NER) model capable of identifying any
|
||||
entity type using a bidirectional transformer encoder (BERT-like).
|
||||
|
||||
The ``GLiNERLinkExtractor`` uses GLiNER to create links between documents that
|
||||
have named entities in common.
|
||||
|
||||
Example::
|
||||
|
||||
extractor = GLiNERLinkExtractor(
|
||||
labels=["Person", "Award", "Date", "Competitions", "Teams"]
|
||||
)
|
||||
results = extractor.extract_one("some long text...")
|
||||
|
||||
.. _GLiNER: https://github.com/urchade/GLiNER
|
||||
|
||||
.. seealso::
|
||||
|
||||
- :mod:`How to use a graph vector store <langchain_community.graph_vectorstores>`
|
||||
- :class:`How to create links between documents <langchain_core.graph_vectorstores.links.Link>`
|
||||
|
||||
How to link Documents on common named entities
|
||||
==============================================
|
||||
|
||||
Preliminaries
|
||||
-------------
|
||||
|
||||
Install the ``gliner`` package:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install -q langchain_community gliner
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
We load the ``state_of_the_union.txt`` file, chunk it, then for each chunk we
|
||||
extract named entity links and add them to the chunk.
|
||||
|
||||
Using extract_one()
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
We can use :meth:`extract_one` on a document to get the links and add the links
|
||||
to the document metadata with
|
||||
:meth:`~langchain_core.graph_vectorstores.links.add_links`::
|
||||
|
||||
from langchain_community.document_loaders import TextLoader
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
from langchain_community.graph_vectorstores.extractors import GLiNERLinkExtractor
|
||||
from langchain_core.graph_vectorstores.links import add_links
|
||||
from langchain_text_splitters import CharacterTextSplitter
|
||||
|
||||
loader = TextLoader("state_of_the_union.txt")
|
||||
raw_documents = loader.load()
|
||||
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
documents = text_splitter.split_documents(raw_documents)
|
||||
|
||||
ner_extractor = GLiNERLinkExtractor(["Person", "Topic"])
|
||||
for document in documents:
|
||||
links = ner_extractor.extract_one(document)
|
||||
add_links(document, links)
|
||||
|
||||
print(documents[0].metadata)
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
{'source': 'state_of_the_union.txt', 'links': [Link(kind='entity:Person', direction='bidir', tag='President Zelenskyy'), Link(kind='entity:Person', direction='bidir', tag='Vladimir Putin')]}
|
||||
|
||||
Using LinkExtractorTransformer
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Using the :class:`~langchain_community.graph_vectorstores.extractors.keybert_link_extractor.LinkExtractorTransformer`,
|
||||
we can simplify the link extraction::
|
||||
|
||||
from langchain_community.document_loaders import TextLoader
|
||||
from langchain_community.graph_vectorstores.extractors import (
|
||||
GLiNERLinkExtractor,
|
||||
LinkExtractorTransformer,
|
||||
)
|
||||
from langchain_text_splitters import CharacterTextSplitter
|
||||
|
||||
loader = TextLoader("state_of_the_union.txt")
|
||||
raw_documents = loader.load()
|
||||
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
documents = text_splitter.split_documents(raw_documents)
|
||||
|
||||
ner_extractor = GLiNERLinkExtractor(["Person", "Topic"])
|
||||
transformer = LinkExtractorTransformer([ner_extractor])
|
||||
documents = transformer.transform_documents(documents)
|
||||
|
||||
print(documents[0].metadata)
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
{'source': 'state_of_the_union.txt', 'links': [Link(kind='entity:Person', direction='bidir', tag='President Zelenskyy'), Link(kind='entity:Person', direction='bidir', tag='Vladimir Putin')]}
|
||||
|
||||
The documents with named entity links can then be added to a :class:`~langchain_core.graph_vectorstores.base.GraphVectorStore`::
|
||||
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
|
||||
store = CassandraGraphVectorStore.from_documents(documents=documents, embedding=...)
|
||||
|
||||
Args:
|
||||
labels: List of kinds of entities to extract.
|
||||
kind: Kind of links to produce with this extractor.
|
||||
model: GLiNER model to use.
|
||||
extract_kwargs: Keyword arguments to pass to GLiNER.
|
||||
""" # noqa: E501
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -24,23 +134,6 @@ class GLiNERLinkExtractor(LinkExtractor[GLiNERInput]):
|
||||
model: str = "urchade/gliner_mediumv2.1",
|
||||
extract_kwargs: Optional[Dict[str, Any]] = None,
|
||||
):
|
||||
"""Extract keywords using GLiNER.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
extractor = GLiNERLinkExtractor(
|
||||
labels=["Person", "Award", "Date", "Competitions", "Teams"]
|
||||
)
|
||||
results = extractor.extract_one("some long text...")
|
||||
|
||||
Args:
|
||||
labels: List of kinds of entities to extract.
|
||||
kind: Kind of links to produce with this extractor.
|
||||
model: GLiNER model to use.
|
||||
extract_kwargs: Keyword arguments to pass to GLiNER.
|
||||
"""
|
||||
try:
|
||||
from gliner import GLiNER
|
||||
|
||||
|
||||
@@ -69,11 +69,175 @@ class HtmlLinkExtractor(LinkExtractor[HtmlInput]):
|
||||
|
||||
Expects the input to be an HTML string or a `BeautifulSoup` object.
|
||||
|
||||
Example::
|
||||
|
||||
extractor = HtmlLinkExtractor()
|
||||
results = extractor.extract_one(HtmlInput(html, url))
|
||||
|
||||
.. seealso::
|
||||
|
||||
- :mod:`How to use a graph vector store <langchain_community.graph_vectorstores>`
|
||||
- :class:`How to create links between documents <langchain_core.graph_vectorstores.links.Link>`
|
||||
|
||||
How to link Documents on hyperlinks in HTML
|
||||
===========================================
|
||||
|
||||
Preliminaries
|
||||
-------------
|
||||
|
||||
Install the ``beautifulsoup4`` package:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install -q langchain_community beautifulsoup4
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
For this example, we'll scrape 2 HTML pages that have an hyperlink from one
|
||||
page to the other using an ``AsyncHtmlLoader``.
|
||||
Then we use the ``HtmlLinkExtractor`` to create the links in the documents.
|
||||
|
||||
Using extract_one()
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
We can use :meth:`extract_one` on a document to get the links and add the links
|
||||
to the document metadata with
|
||||
:meth:`~langchain_core.graph_vectorstores.links.add_links`::
|
||||
|
||||
from langchain_community.document_loaders import AsyncHtmlLoader
|
||||
from langchain_community.graph_vectorstores.extractors import (
|
||||
HtmlInput,
|
||||
HtmlLinkExtractor,
|
||||
)
|
||||
from langchain_community.graph_vectorstores.links import add_links
|
||||
from langchain_core.documents import Document
|
||||
|
||||
loader = AsyncHtmlLoader(
|
||||
[
|
||||
"https://python.langchain.com/v0.2/docs/integrations/providers/astradb/",
|
||||
"https://docs.datastax.com/en/astra/home/astra.html",
|
||||
]
|
||||
)
|
||||
|
||||
documents = loader.load()
|
||||
|
||||
html_extractor = HtmlLinkExtractor()
|
||||
|
||||
for doc in documents:
|
||||
links = html_extractor.extract_one(HtmlInput(doc.page_content, url))
|
||||
add_links(doc, links)
|
||||
|
||||
documents[0].metadata["links"][:5]
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
[Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/spreedly/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/nvidia/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/ray_serve/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/bageldb/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/introduction/')]
|
||||
|
||||
Using as_document_extractor()
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
If you use a document loader that returns the raw HTML and that sets the source
|
||||
key in the document metadata such as ``AsyncHtmlLoader``,
|
||||
you can simplify by using :meth:`as_document_extractor` that takes directly a
|
||||
``Document`` as input::
|
||||
|
||||
from langchain_community.document_loaders import AsyncHtmlLoader
|
||||
from langchain_community.graph_vectorstores.extractors import HtmlLinkExtractor
|
||||
from langchain_core.graph_vectorstores.links import add_links
|
||||
|
||||
loader = AsyncHtmlLoader(
|
||||
[
|
||||
"https://python.langchain.com/v0.2/docs/integrations/providers/astradb/",
|
||||
"https://docs.datastax.com/en/astra/home/astra.html",
|
||||
]
|
||||
)
|
||||
documents = loader.load()
|
||||
html_extractor = HtmlLinkExtractor().as_document_extractor()
|
||||
|
||||
for document in documents:
|
||||
links = html_extractor.extract_one(document)
|
||||
add_links(document, links)
|
||||
|
||||
documents[0].metadata["links"][:5]
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
[Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/spreedly/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/nvidia/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/ray_serve/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/bageldb/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/introduction/')]
|
||||
|
||||
Using LinkExtractorTransformer
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Using the :class:`~langchain_community.graph_vectorstores.extractors.keybert_link_extractor.LinkExtractorTransformer`,
|
||||
we can simplify the link extraction::
|
||||
|
||||
from langchain_community.document_loaders import AsyncHtmlLoader
|
||||
from langchain_community.graph_vectorstores.extractors import (
|
||||
HtmlLinkExtractor,
|
||||
LinkExtractorTransformer,
|
||||
)
|
||||
from langchain_community.graph_vectorstores.links import add_links
|
||||
|
||||
loader = AsyncHtmlLoader(
|
||||
[
|
||||
"https://python.langchain.com/v0.2/docs/integrations/providers/astradb/",
|
||||
"https://docs.datastax.com/en/astra/home/astra.html",
|
||||
]
|
||||
)
|
||||
|
||||
documents = loader.load()
|
||||
transformer = LinkExtractorTransformer([HtmlLinkExtractor().as_document_extractor()])
|
||||
documents = transformer.transform_documents(documents)
|
||||
|
||||
documents[0].metadata["links"][:5]
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
[Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/spreedly/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/nvidia/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/ray_serve/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/integrations/providers/bageldb/'),
|
||||
Link(kind='hyperlink', direction='out', tag='https://python.langchain.com/v0.2/docs/introduction/')]
|
||||
|
||||
We can check that there is a link from the first document to the second::
|
||||
|
||||
for doc_to in documents:
|
||||
for link_to in doc_to.metadata["links"]:
|
||||
if link_to.direction == "in":
|
||||
for doc_from in documents:
|
||||
for link_from in doc_from.metadata["links"]:
|
||||
if (
|
||||
link_to.direction == "in"
|
||||
and link_from.direction == "out"
|
||||
and link_to.tag == link_from.tag
|
||||
):
|
||||
print(
|
||||
f"Found link from {doc_from.metadata['source']} to {doc_to.metadata['source']}."
|
||||
)
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
Found link from https://python.langchain.com/v0.2/docs/integrations/providers/astradb/ to https://docs.datastax.com/en/astra/home/astra.html.
|
||||
|
||||
The documents with URL links can then be added to a :class:`~langchain_core.graph_vectorstores.base.GraphVectorStore`::
|
||||
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
|
||||
store = CassandraGraphVectorStore.from_documents(documents=documents, embedding=...)
|
||||
|
||||
Args:
|
||||
kind: The kind of edge to extract. Defaults to "hyperlink".
|
||||
kind: The kind of edge to extract. Defaults to ``hyperlink``.
|
||||
drop_fragments: Whether fragments in URLs and links should be
|
||||
dropped. Defaults to `True`.
|
||||
"""
|
||||
dropped. Defaults to ``True``.
|
||||
""" # noqa: E501
|
||||
try:
|
||||
import bs4 # noqa:F401
|
||||
except ImportError as e:
|
||||
@@ -90,9 +254,10 @@ class HtmlLinkExtractor(LinkExtractor[HtmlInput]):
|
||||
) -> LinkExtractor[Document]:
|
||||
"""Return a LinkExtractor that applies to documents.
|
||||
|
||||
NOTE: Since the HtmlLinkExtractor parses HTML, if you use with other similar
|
||||
link extractors it may be more efficient to call the link extractors directly
|
||||
on the parsed BeautifulSoup object.
|
||||
Note:
|
||||
Since the HtmlLinkExtractor parses HTML, if you use with other similar
|
||||
link extractors it may be more efficient to call the link extractors
|
||||
directly on the parsed BeautifulSoup object.
|
||||
|
||||
Args:
|
||||
url_metadata_key: The name of the filed in document metadata with the URL of
|
||||
|
||||
@@ -20,22 +20,114 @@ class KeybertLinkExtractor(LinkExtractor[KeybertInput]):
|
||||
embedding_model: str = "all-MiniLM-L6-v2",
|
||||
extract_keywords_kwargs: Optional[Dict[str, Any]] = None,
|
||||
):
|
||||
"""Extract keywords using KeyBERT <https://maartengr.github.io/KeyBERT/>.
|
||||
"""Extract keywords using `KeyBERT <https://maartengr.github.io/KeyBERT/>`_.
|
||||
|
||||
Example:
|
||||
KeyBERT is a minimal and easy-to-use keyword extraction technique that
|
||||
leverages BERT embeddings to create keywords and keyphrases that are most
|
||||
similar to a document.
|
||||
|
||||
.. code-block:: python
|
||||
The KeybertLinkExtractor uses KeyBERT to create links between documents that
|
||||
have keywords in common.
|
||||
|
||||
extractor = KeybertLinkExtractor()
|
||||
Example::
|
||||
|
||||
results = extractor.extract_one(PAGE_1)
|
||||
extractor = KeybertLinkExtractor()
|
||||
results = extractor.extract_one("lorem ipsum...")
|
||||
|
||||
.. seealso::
|
||||
|
||||
- :mod:`How to use a graph vector store <langchain_community.graph_vectorstores>`
|
||||
- :class:`How to create links between documents <langchain_core.graph_vectorstores.links.Link>`
|
||||
|
||||
How to link Documents on common keywords using Keybert
|
||||
======================================================
|
||||
|
||||
Preliminaries
|
||||
-------------
|
||||
|
||||
Install the keybert package:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install -q langchain_community keybert
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
We load the ``state_of_the_union.txt`` file, chunk it, then for each chunk we
|
||||
extract keyword links and add them to the chunk.
|
||||
|
||||
Using extract_one()
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
We can use :meth:`extract_one` on a document to get the links and add the links
|
||||
to the document metadata with
|
||||
:meth:`~langchain_core.graph_vectorstores.links.add_links`::
|
||||
|
||||
from langchain_community.document_loaders import TextLoader
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
from langchain_community.graph_vectorstores.extractors import KeybertLinkExtractor
|
||||
from langchain_core.graph_vectorstores.links import add_links
|
||||
from langchain_text_splitters import CharacterTextSplitter
|
||||
|
||||
loader = TextLoader("state_of_the_union.txt")
|
||||
|
||||
raw_documents = loader.load()
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
|
||||
documents = text_splitter.split_documents(raw_documents)
|
||||
keyword_extractor = KeybertLinkExtractor()
|
||||
|
||||
for document in documents:
|
||||
links = keyword_extractor.extract_one(document)
|
||||
add_links(document, links)
|
||||
|
||||
print(documents[0].metadata)
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
{'source': 'state_of_the_union.txt', 'links': [Link(kind='kw', direction='bidir', tag='ukraine'), Link(kind='kw', direction='bidir', tag='ukrainian'), Link(kind='kw', direction='bidir', tag='putin'), Link(kind='kw', direction='bidir', tag='vladimir'), Link(kind='kw', direction='bidir', tag='russia')]}
|
||||
|
||||
Using LinkExtractorTransformer
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Using the :class:`~langchain_community.graph_vectorstores.extractors.keybert_link_extractor.LinkExtractorTransformer`,
|
||||
we can simplify the link extraction::
|
||||
|
||||
from langchain_community.document_loaders import TextLoader
|
||||
from langchain_community.graph_vectorstores.extractors import (
|
||||
KeybertLinkExtractor,
|
||||
LinkExtractorTransformer,
|
||||
)
|
||||
from langchain_text_splitters import CharacterTextSplitter
|
||||
|
||||
loader = TextLoader("state_of_the_union.txt")
|
||||
raw_documents = loader.load()
|
||||
|
||||
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
documents = text_splitter.split_documents(raw_documents)
|
||||
|
||||
transformer = LinkExtractorTransformer([KeybertLinkExtractor()])
|
||||
documents = transformer.transform_documents(documents)
|
||||
|
||||
print(documents[0].metadata)
|
||||
|
||||
.. code-block:: output
|
||||
|
||||
{'source': 'state_of_the_union.txt', 'links': [Link(kind='kw', direction='bidir', tag='ukraine'), Link(kind='kw', direction='bidir', tag='ukrainian'), Link(kind='kw', direction='bidir', tag='putin'), Link(kind='kw', direction='bidir', tag='vladimir'), Link(kind='kw', direction='bidir', tag='russia')]}
|
||||
|
||||
The documents with keyword links can then be added to a :class:`~langchain_core.graph_vectorstores.base.GraphVectorStore`::
|
||||
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
|
||||
store = CassandraGraphVectorStore.from_documents(documents=documents, embedding=...)
|
||||
|
||||
Args:
|
||||
kind: Kind of links to produce with this extractor.
|
||||
embedding_model: Name of the embedding model to use with KeyBERT.
|
||||
extract_keywords_kwargs: Keyword arguments to pass to KeyBERT's
|
||||
`extract_keywords` method.
|
||||
"""
|
||||
``extract_keywords`` method.
|
||||
""" # noqa: E501
|
||||
try:
|
||||
import keybert
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from langchain_core.graph_vectorstores.links import (
|
||||
Link,
|
||||
add_links,
|
||||
copy_with_links,
|
||||
get_links,
|
||||
)
|
||||
|
||||
__all__ = ["Link", "add_links", "get_links", "copy_with_links"]
|
||||
@@ -346,18 +346,27 @@ class Neo4jGraph(GraphStore):
|
||||
)
|
||||
|
||||
url = get_from_dict_or_env({"url": url}, "url", "NEO4J_URI")
|
||||
username = get_from_dict_or_env(
|
||||
{"username": username}, "username", "NEO4J_USERNAME"
|
||||
)
|
||||
password = get_from_dict_or_env(
|
||||
{"password": password}, "password", "NEO4J_PASSWORD"
|
||||
)
|
||||
# if username and password are "", assume Neo4j auth is disabled
|
||||
if username == "" and password == "":
|
||||
auth = None
|
||||
else:
|
||||
username = get_from_dict_or_env(
|
||||
{"username": username},
|
||||
"username",
|
||||
"NEO4J_USERNAME",
|
||||
)
|
||||
password = get_from_dict_or_env(
|
||||
{"password": password},
|
||||
"password",
|
||||
"NEO4J_PASSWORD",
|
||||
)
|
||||
auth = (username, password)
|
||||
database = get_from_dict_or_env(
|
||||
{"database": database}, "database", "NEO4J_DATABASE", "neo4j"
|
||||
)
|
||||
|
||||
self._driver = neo4j.GraphDatabase.driver(
|
||||
url, auth=(username, password), **(driver_config or {})
|
||||
url, auth=auth, **(driver_config or {})
|
||||
)
|
||||
self._database = database
|
||||
self.timeout = timeout
|
||||
@@ -401,7 +410,9 @@ class Neo4jGraph(GraphStore):
|
||||
"""Returns the structured schema of the Graph"""
|
||||
return self.structured_schema
|
||||
|
||||
def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]:
|
||||
def query(
|
||||
self, query: str, params: dict = {}, retry_on_session_expired: bool = True
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Query Neo4j database.
|
||||
|
||||
Args:
|
||||
@@ -412,7 +423,7 @@ class Neo4jGraph(GraphStore):
|
||||
List[Dict[str, Any]]: The list of dictionaries containing the query results.
|
||||
"""
|
||||
from neo4j import Query
|
||||
from neo4j.exceptions import CypherSyntaxError
|
||||
from neo4j.exceptions import CypherSyntaxError, SessionExpired
|
||||
|
||||
with self._driver.session(database=self._database) as session:
|
||||
try:
|
||||
@@ -423,6 +434,15 @@ class Neo4jGraph(GraphStore):
|
||||
return json_data
|
||||
except CypherSyntaxError as e:
|
||||
raise ValueError(f"Generated Cypher Statement is not valid\n{e}")
|
||||
except (
|
||||
SessionExpired
|
||||
) as e: # Session expired is a transient error that can be retried
|
||||
if retry_on_session_expired:
|
||||
return self.query(
|
||||
query, params=params, retry_on_session_expired=False
|
||||
)
|
||||
else:
|
||||
raise e
|
||||
|
||||
def refresh_schema(self) -> None:
|
||||
"""
|
||||
|
||||
@@ -139,6 +139,16 @@ class IpexLLM(LLM):
|
||||
kwargs = kwargs or {}
|
||||
|
||||
_tokenizer_id = tokenizer_id or model_id
|
||||
# Set "cpu" as default device
|
||||
if "device" not in _model_kwargs:
|
||||
_model_kwargs["device"] = "cpu"
|
||||
|
||||
if _model_kwargs["device"] not in ["cpu", "xpu"]:
|
||||
raise ValueError(
|
||||
"IpexLLMBgeEmbeddings currently only supports device to be "
|
||||
f"'cpu' or 'xpu', but you have: {_model_kwargs['device']}."
|
||||
)
|
||||
device = _model_kwargs.pop("device")
|
||||
|
||||
try:
|
||||
tokenizer = AutoTokenizer.from_pretrained(_tokenizer_id, **_model_kwargs)
|
||||
@@ -186,6 +196,8 @@ class IpexLLM(LLM):
|
||||
model_kwargs=_model_kwargs,
|
||||
)
|
||||
|
||||
model.to(device)
|
||||
|
||||
return cls(
|
||||
model_id=model_id,
|
||||
model=model,
|
||||
@@ -235,6 +247,7 @@ class IpexLLM(LLM):
|
||||
from transformers import TextStreamer
|
||||
|
||||
input_ids = self.tokenizer.encode(prompt, return_tensors="pt")
|
||||
input_ids = input_ids.to(self.model.device)
|
||||
streamer = TextStreamer(
|
||||
self.tokenizer, skip_prompt=True, skip_special_tokens=True
|
||||
)
|
||||
@@ -261,6 +274,7 @@ class IpexLLM(LLM):
|
||||
return text
|
||||
else:
|
||||
input_ids = self.tokenizer.encode(prompt, return_tensors="pt")
|
||||
input_ids = input_ids.to(self.model.device)
|
||||
if stop is not None:
|
||||
from transformers.generation.stopping_criteria import (
|
||||
StoppingCriteriaList,
|
||||
|
||||
@@ -514,7 +514,7 @@ class SSEndpointHandler:
|
||||
response: requests.Response,
|
||||
) -> Generator[Dict, None, None]:
|
||||
"""Process the streaming response"""
|
||||
if "nlp" in self.api_base_uri:
|
||||
if "api/predict/nlp" in self.api_base_uri:
|
||||
try:
|
||||
import sseclient
|
||||
except ImportError:
|
||||
@@ -535,14 +535,15 @@ class SSEndpointHandler:
|
||||
yield chunk
|
||||
if close_conn:
|
||||
client.close()
|
||||
elif "generic" in self.api_base_uri:
|
||||
elif (
|
||||
"api/v2/predict/generic" in self.api_base_uri
|
||||
or "api/predict/generic" in self.api_base_uri
|
||||
):
|
||||
try:
|
||||
for line in response.iter_lines():
|
||||
chunk = json.loads(line)
|
||||
if "status_code" not in chunk:
|
||||
chunk["status_code"] = response.status_code
|
||||
if chunk["status_code"] == 200 and chunk.get("error"):
|
||||
chunk["result"] = {"responses": [{"stream_token": ""}]}
|
||||
yield chunk
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Error processing streaming response: {e}")
|
||||
@@ -583,12 +584,18 @@ class SSEndpointHandler:
|
||||
"""
|
||||
if isinstance(input, str):
|
||||
input = [input]
|
||||
if "nlp" in self.api_base_uri:
|
||||
if "api/predict/nlp" in self.api_base_uri:
|
||||
if params:
|
||||
data = {"inputs": input, "params": json.loads(params)}
|
||||
else:
|
||||
data = {"inputs": input}
|
||||
elif "generic" in self.api_base_uri:
|
||||
elif "api/v2/predict/generic" in self.api_base_uri:
|
||||
items = [{"id": f"item{i}", "value": item} for i, item in enumerate(input)]
|
||||
if params:
|
||||
data = {"items": items, "params": json.loads(params)}
|
||||
else:
|
||||
data = {"items": items}
|
||||
elif "api/predict/generic" in self.api_base_uri:
|
||||
if params:
|
||||
data = {"instances": input, "params": json.loads(params)}
|
||||
else:
|
||||
@@ -623,14 +630,22 @@ class SSEndpointHandler:
|
||||
:returns: Prediction results
|
||||
:type: dict
|
||||
"""
|
||||
if "nlp" in self.api_base_uri:
|
||||
if "api/predict/nlp" in self.api_base_uri:
|
||||
if isinstance(input, str):
|
||||
input = [input]
|
||||
if params:
|
||||
data = {"inputs": input, "params": json.loads(params)}
|
||||
else:
|
||||
data = {"inputs": input}
|
||||
elif "generic" in self.api_base_uri:
|
||||
elif "api/v2/predict/generic" in self.api_base_uri:
|
||||
if isinstance(input, str):
|
||||
input = [input]
|
||||
items = [{"id": f"item{i}", "value": item} for i, item in enumerate(input)]
|
||||
if params:
|
||||
data = {"items": items, "params": json.loads(params)}
|
||||
else:
|
||||
data = {"items": items}
|
||||
elif "api/predict/generic" in self.api_base_uri:
|
||||
if isinstance(input, list):
|
||||
input = input[0]
|
||||
if params:
|
||||
@@ -770,10 +785,13 @@ class SambaStudio(LLM):
|
||||
# _model_kwargs["stop_sequences"] = ",".join(
|
||||
# f'"{x}"' for x in _stop_sequences
|
||||
# )
|
||||
tuning_params_dict = {
|
||||
k: {"type": type(v).__name__, "value": str(v)}
|
||||
for k, v in (_model_kwargs.items())
|
||||
}
|
||||
if "api/v2/predict/generic" in self.sambastudio_base_uri:
|
||||
tuning_params_dict = _model_kwargs
|
||||
else:
|
||||
tuning_params_dict = {
|
||||
k: {"type": type(v).__name__, "value": str(v)}
|
||||
for k, v in (_model_kwargs.items())
|
||||
}
|
||||
# _model_kwargs["stop_sequences"] = _kwarg_stop_sequences
|
||||
tuning_params = json.dumps(tuning_params_dict)
|
||||
return tuning_params
|
||||
@@ -814,9 +832,11 @@ class SambaStudio(LLM):
|
||||
f"Sambanova /complete call failed with status code "
|
||||
f"{response['status_code']}.\n response {response}"
|
||||
)
|
||||
if "nlp" in self.sambastudio_base_uri:
|
||||
if "api/predict/nlp" in self.sambastudio_base_uri:
|
||||
return response["data"][0]["completion"]
|
||||
elif "generic" in self.sambastudio_base_uri:
|
||||
elif "api/v2/predict/generic" in self.sambastudio_base_uri:
|
||||
return response["items"][0]["value"]["completion"]
|
||||
elif "api/predict/generic" in self.sambastudio_base_uri:
|
||||
return response["predictions"][0]["completion"]
|
||||
else:
|
||||
raise ValueError(
|
||||
@@ -885,10 +905,15 @@ class SambaStudio(LLM):
|
||||
f"{chunk['status_code']}."
|
||||
f"{chunk}."
|
||||
)
|
||||
if "nlp" in self.sambastudio_base_uri:
|
||||
if "api/predict/nlp" in self.sambastudio_base_uri:
|
||||
text = json.loads(chunk["data"])["stream_token"]
|
||||
elif "generic" in self.sambastudio_base_uri:
|
||||
text = chunk["result"]["responses"][0]["stream_token"]
|
||||
elif "api/v2/predict/generic" in self.sambastudio_base_uri:
|
||||
text = chunk["result"]["items"][0]["value"]["stream_token"]
|
||||
elif "api/predict/generic" in self.sambastudio_base_uri:
|
||||
if len(chunk["result"]["responses"]) > 0:
|
||||
text = chunk["result"]["responses"][0]["stream_token"]
|
||||
else:
|
||||
text = ""
|
||||
else:
|
||||
raise ValueError(
|
||||
f"handling of endpoint uri: {self.sambastudio_base_uri}"
|
||||
|
||||
@@ -135,6 +135,8 @@ class WebResearchRetriever(BaseRetriever):
|
||||
text_splitter: Text splitter for splitting web pages into chunks
|
||||
trust_env: Whether to use the http_proxy/https_proxy env variables
|
||||
or check .netrc for proxy configuration
|
||||
allow_dangerous_requests: A flag to force users to acknowledge
|
||||
the risks of SSRF attacks when using this retriever
|
||||
|
||||
Returns:
|
||||
WebResearchRetriever
|
||||
|
||||
@@ -166,6 +166,7 @@ if TYPE_CHECKING:
|
||||
from langchain_community.tools.interaction.tool import (
|
||||
StdInInquireTool,
|
||||
)
|
||||
from langchain_community.tools.jina_search.tool import JinaSearch
|
||||
from langchain_community.tools.jira.tool import (
|
||||
JiraAction,
|
||||
)
|
||||
@@ -419,6 +420,7 @@ __all__ = [
|
||||
"InfoSQLDatabaseTool",
|
||||
"InfoSparkSQLTool",
|
||||
"JiraAction",
|
||||
"JinaSearch",
|
||||
"JsonGetValueTool",
|
||||
"JsonListKeysTool",
|
||||
"ListDirectoryTool",
|
||||
@@ -570,6 +572,7 @@ _module_lookup = {
|
||||
"InfoSQLDatabaseTool": "langchain_community.tools.sql_database.tool",
|
||||
"InfoSparkSQLTool": "langchain_community.tools.spark_sql.tool",
|
||||
"JiraAction": "langchain_community.tools.jira.tool",
|
||||
"JinaSearch": "langchain_community.tools.jina_search.tool",
|
||||
"JsonGetValueTool": "langchain_community.tools.json.tool",
|
||||
"JsonListKeysTool": "langchain_community.tools.json.tool",
|
||||
"ListDirectoryTool": "langchain_community.tools.file_management",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Tool for the Bing search API."""
|
||||
|
||||
from typing import Optional
|
||||
from typing import Dict, List, Literal, Optional, Tuple
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.tools import BaseTool
|
||||
@@ -51,7 +51,7 @@ class BingSearchResults(BaseTool):
|
||||
Invocation with args:
|
||||
.. code-block:: python
|
||||
|
||||
tool.invoke("what is the weather in SF?")
|
||||
tool.invoke({"query": "what is the weather in SF?"})
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -65,7 +65,12 @@ class BingSearchResults(BaseTool):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
ToolMessage(content="[{'snippet': 'Get the latest <b>weather</b> forecast for <b>San Francisco, CA</b>, including temperature, RealFeel, and chance of precipitation. Find out how the <b>weather</b> will affect your plans and activities in the city of ...', 'title': 'San Francisco, CA Weather Forecast | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/weather-forecast/347629'}, {'snippet': 'Radar. Be prepared with the most accurate 10-day forecast for <b>San Francisco, CA</b> with highs, lows, chance of precipitation from The <b>Weather</b> Channel and <b>Weather</b>.com.', 'title': '10-Day Weather Forecast for San Francisco, CA - The Weather Channel', 'link': 'https://weather.com/weather/tenday/l/San+Francisco+CA+USCA0987:1:US'}, {'snippet': 'Tropical Storm Ernesto Forms; Fire <b>Weather</b> Concerns in the Great Basin: Hot Temperatures Return to the South-Central U.S. ... <b>San Francisco CA</b> 37.77°N 122.41°W (Elev. 131 ft) Last Update: 2:21 pm PDT Aug 12, 2024. Forecast Valid: 6pm PDT Aug 12, 2024-6pm PDT Aug 19, 2024 .', 'title': 'National Weather Service', 'link': 'https://forecast.weather.gov/zipcity.php?inputstring=San+Francisco,CA'}, {'snippet': 'Current <b>weather</b> <b>in San Francisco, CA</b>. Check current conditions <b>in San Francisco, CA</b> with radar, hourly, and more.', 'title': 'San Francisco, CA Current Weather | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629'}]", name='bing_search_results_json', tool_call_id='1')
|
||||
ToolMessage(
|
||||
content="[{'snippet': 'Get the latest <b>weather</b> forecast for <b>San Francisco, CA</b>, including temperature, RealFeel, and chance of precipitation. Find out how the <b>weather</b> will affect your plans and activities in the city of ...', 'title': 'San Francisco, CA Weather Forecast | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/weather-forecast/347629'}, {'snippet': 'Radar. Be prepared with the most accurate 10-day forecast for <b>San Francisco, CA</b> with highs, lows, chance of precipitation from The <b>Weather</b> Channel and <b>Weather</b>.com.', 'title': '10-Day Weather Forecast for San Francisco, CA - The Weather Channel', 'link': 'https://weather.com/weather/tenday/l/San+Francisco+CA+USCA0987:1:US'}, {'snippet': 'Tropical Storm Ernesto Forms; Fire <b>Weather</b> Concerns in the Great Basin: Hot Temperatures Return to the South-Central U.S. ... <b>San Francisco CA</b> 37.77°N 122.41°W (Elev. 131 ft) Last Update: 2:21 pm PDT Aug 12, 2024. Forecast Valid: 6pm PDT Aug 12, 2024-6pm PDT Aug 19, 2024 .', 'title': 'National Weather Service', 'link': 'https://forecast.weather.gov/zipcity.php?inputstring=San+Francisco,CA'}, {'snippet': 'Current <b>weather</b> <b>in San Francisco, CA</b>. Check current conditions <b>in San Francisco, CA</b> with radar, hourly, and more.', 'title': 'San Francisco, CA Current Weather | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629'}]",
|
||||
artifact=[{'snippet': 'Get the latest <b>weather</b> forecast for <b>San Francisco, CA</b>, including temperature, RealFeel, and chance of precipitation. Find out how the <b>weather</b> will affect your plans and activities in the city of ...', 'title': 'San Francisco, CA Weather Forecast | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/weather-forecast/347629'}, {'snippet': 'Radar. Be prepared with the most accurate 10-day forecast for <b>San Francisco, CA</b> with highs, lows, chance of precipitation from The <b>Weather</b> Channel and <b>Weather</b>.com.', 'title': '10-Day Weather Forecast for San Francisco, CA - The Weather Channel', 'link': 'https://weather.com/weather/tenday/l/San+Francisco+CA+USCA0987:1:US'}, {'snippet': 'Tropical Storm Ernesto Forms; Fire <b>Weather</b> Concerns in the Great Basin: Hot Temperatures Return to the South-Central U.S. ... <b>San Francisco CA</b> 37.77°N 122.41°W (Elev. 131 ft) Last Update: 2:21 pm PDT Aug 12, 2024. Forecast Valid: 6pm PDT Aug 12, 2024-6pm PDT Aug 19, 2024 .', 'title': 'National Weather Service', 'link': 'https://forecast.weather.gov/zipcity.php?inputstring=San+Francisco,CA'}, {'snippet': 'Current <b>weather</b> <b>in San Francisco, CA</b>. Check current conditions <b>in San Francisco, CA</b> with radar, hourly, and more.', 'title': 'San Francisco, CA Current Weather | AccuWeather', 'link': 'https://www.accuweather.com/en/us/san-francisco/94103/current-weather/347629'}],
|
||||
name='bing_search_results_json',
|
||||
tool_call_id='1'
|
||||
)
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
@@ -73,15 +78,21 @@ class BingSearchResults(BaseTool):
|
||||
description: str = (
|
||||
"A wrapper around Bing Search. "
|
||||
"Useful for when you need to answer questions about current events. "
|
||||
"Input should be a search query. Output is a JSON array of the query results"
|
||||
"Input should be a search query. Output is an array of the query results."
|
||||
)
|
||||
num_results: int = 4
|
||||
"""Max search results to return, default is 4."""
|
||||
api_wrapper: BingSearchAPIWrapper
|
||||
response_format: Literal["content_and_artifact"] = "content_and_artifact"
|
||||
|
||||
def _run(
|
||||
self,
|
||||
query: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
) -> Tuple[str, List[Dict]]:
|
||||
"""Use the tool."""
|
||||
return str(self.api_wrapper.results(query, self.num_results))
|
||||
try:
|
||||
results = self.api_wrapper.results(query, self.num_results)
|
||||
return str(results), results
|
||||
except Exception as e:
|
||||
return repr(e), []
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user