-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt Jina Embeddings to new Jina AI Embedding API (#13658)
- **Description:** Adapt JinaEmbeddings to run with the new Jina AI Embedding platform - **Twitter handle:** https://twitter.com/JinaAI_ --------- Co-authored-by: Joan Fontanals Martinez <joan.fontanals.martinez@jina.ai> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
- Loading branch information
1 parent
e0c03d6
commit dcccf8f
Showing
3 changed files
with
58 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,20 @@ | ||
# Jina | ||
|
||
This page covers how to use the Jina ecosystem within LangChain. | ||
This page covers how to use the Jina Embeddings within LangChain. | ||
It is broken into two parts: installation and setup, and then references to specific Jina wrappers. | ||
|
||
## Installation and Setup | ||
- Install the Python SDK with `pip install jina` | ||
- Get a Jina AI Cloud auth token from [here](https://cloud.jina.ai/settings/tokens) and set it as an environment variable (`JINA_AUTH_TOKEN`) | ||
|
||
## Wrappers | ||
|
||
### Embeddings | ||
- Get a Jina AI API token from [here](https://jina.ai/embeddings/) and set it as an environment variable (`JINA_API_TOKEN`) | ||
|
||
There exists a Jina Embeddings wrapper, which you can access with | ||
```python | ||
from langchain.embeddings import JinaEmbeddings | ||
``` | ||
For a more detailed walkthrough of this, see [this notebook](/docs/integrations/text_embedding/jina) | ||
|
||
## Deployment | ||
|
||
[Langchain-serve](https://github.com/jina-ai/langchain-serve), powered by Jina, helps take LangChain apps to production with easy to use REST/WebSocket APIs and Slack bots. | ||
|
||
### Usage | ||
|
||
Install the package from PyPI. | ||
|
||
```bash | ||
pip install langchain-serve | ||
``` | ||
|
||
Wrap your LangChain app with the `@serving` decorator. | ||
|
||
```python | ||
# app.py | ||
from lcserve import serving | ||
|
||
@serving | ||
def ask(input: str) -> str: | ||
from langchain.chains import LLMChain | ||
from langchain.llms import OpenAI | ||
from langchain.agents import AgentExecutor, ZeroShotAgent | ||
|
||
tools = [...] # list of tools | ||
prompt = ZeroShotAgent.create_prompt( | ||
tools, input_variables=["input", "agent_scratchpad"], | ||
) | ||
llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt) | ||
agent = ZeroShotAgent( | ||
llm_chain=llm_chain, allowed_tools=[tool.name for tool in tools] | ||
) | ||
agent_executor = AgentExecutor.from_agent_and_tools( | ||
agent=agent, | ||
tools=tools, | ||
verbose=True, | ||
) | ||
return agent_executor.run(input) | ||
``` | ||
|
||
Deploy on Jina AI Cloud with `lc-serve deploy jcloud app`. Once deployed, we can send a POST request to the API endpoint to get a response. | ||
from langchain.embeddings import JinaEmbeddings | ||
|
||
```bash | ||
curl -X 'POST' 'https://<your-app>.wolf.jina.ai/ask' \ | ||
-d '{ | ||
"input": "Your Question here?", | ||
"envs": { | ||
"OPENAI_API_KEY": "sk-***" | ||
} | ||
}' | ||
# you can pas jina_api_key, if none is passed it will be taken from `JINA_API_TOKEN` environment variable | ||
embeddings = JinaEmbeddings(jina_api_key='jina_**', model_name='jina-embeddings-v2-base-en') | ||
``` | ||
|
||
You can also self-host the app on your infrastructure with Docker-compose or Kubernetes. See [here](https://github.com/jina-ai/langchain-serve#-self-host-llm-apps-with-docker-compose-or-kubernetes) for more details. | ||
|
||
You can check the list of available models from [here](https://jina.ai/embeddings/) | ||
|
||
Langchain-serve also allows to deploy the apps with WebSocket APIs and Slack Bots both on [Jina AI Cloud](https://cloud.jina.ai/) or self-hosted infrastructure. | ||
For a more detailed walkthrough of this, see [this notebook](/docs/integrations/text_embedding/jina.ipynb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters