-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Merge pull request #3 from AI21Labs/pr_fixes_1
fix: Fix LC CR
- Loading branch information
Showing
15 changed files
with
166 additions
and
105 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,75 @@ | ||
# langchain-ai21 | ||
|
||
This package contains the LangChain integrations for [AI21](https://docs.ai21.com/) through their [AI21](https://pypi.org/project/ai21/) SDK. | ||
|
||
## Installation and Setup | ||
|
||
- Install the AI21 partner package | ||
```bash | ||
pip install langchain-ai21 | ||
``` | ||
- Get an AI21 api key and set it as an environment variable (`AI21_API_KEY`) | ||
|
||
|
||
## Chat Models | ||
|
||
This package contains the `ChatAI21` class, which is the recommended way to interface with AI21 Chat models. | ||
|
||
To use, install the requirements, and configure your environment. | ||
|
||
```bash | ||
export AI21_API_KEY=your-api-key | ||
``` | ||
|
||
Then initialize | ||
|
||
```python | ||
from langchain_core.messages import HumanMessage | ||
from langchain_ai21.chat_models import ChatAI21 | ||
|
||
chat = ChatAI21(model="j2-ultra") | ||
messages = [HumanMessage(content="Hello from AI21")] | ||
chat.invoke(messages) | ||
``` | ||
|
||
## LLMs | ||
You can use AI21's generative AI models as Langchain LLMs: | ||
|
||
```python | ||
from langchain.prompts import PromptTemplate | ||
from langchain_ai21 import AI21LLM | ||
|
||
llm = AI21LLM(model="j2-ultra") | ||
|
||
template = """Question: {question} | ||
Answer: Let's think step by step.""" | ||
prompt = PromptTemplate.from_template(template) | ||
|
||
chain = prompt | llm | ||
|
||
question = "Which scientist discovered relativity?" | ||
print(chain.invoke({"question": question})) | ||
``` | ||
|
||
## Embeddings | ||
|
||
You can use AI21's embeddings models as: | ||
|
||
### Query | ||
|
||
```python | ||
from langchain_ai21 import AI21Embeddings | ||
|
||
embeddings = AI21Embeddings() | ||
embeddings.embed_query("Hello! This is some query") | ||
``` | ||
|
||
### Document | ||
|
||
```python | ||
from langchain_ai21 import AI21Embeddings | ||
|
||
embeddings = AI21Embeddings() | ||
embeddings.embed_documents(["Hello! This is document 1", "And this is document 2!"]) | ||
``` |
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,9 +1,9 @@ | ||
from langchain_ai21.chat_models import ChatAI21 | ||
from langchain_ai21.embeddings import AI21Embeddings | ||
from langchain_ai21.llms import AI21 | ||
from langchain_ai21.llms import AI21LLM | ||
|
||
__all__ = [ | ||
"AI21", | ||
"AI21LLM", | ||
"ChatAI21", | ||
"AI21Embeddings", | ||
] |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.