-
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.
Merge pull request #4 from AI21Labs/move_docs
fix: Move docs
- Loading branch information
Showing
5 changed files
with
244 additions
and
317 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 |
---|---|---|
@@ -0,0 +1,161 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e49f1e0d", | ||
"metadata": {}, | ||
"source": [ | ||
"# ChatAI21\n", | ||
"\n", | ||
"This notebook covers how to get started with AI21 chat models.\n", | ||
"\n", | ||
"## Installation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "4c3bef91", | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2024-02-15T06:50:44.929635Z", | ||
"start_time": "2024-02-15T06:50:41.209704Z" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\u001B[33mWARNING: Ignoring invalid distribution -i21 (/Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages)\u001B[0m\u001B[33m\r\n", | ||
"\u001B[0mRequirement already satisfied: langchain-ai21 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (0.0.1)\r\n", | ||
"Collecting ai21==2.0.0rc9 (from langchain-ai21)\r\n", | ||
" Obtaining dependency information for ai21==2.0.0rc9 from https://files.pythonhosted.org/packages/ea/18/46e0fa090f0942a78689d7460034d1bdc6be23429eb0bd2c021a6316fa1c/ai21-2.0.0rc9-py3-none-any.whl.metadata\r\n", | ||
" Downloading ai21-2.0.0rc9-py3-none-any.whl.metadata (8.2 kB)\r\n", | ||
"Requirement already satisfied: langchain-core>=0.0.12 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from langchain-ai21) (0.1.18)\r\n", | ||
"Requirement already satisfied: ai21-tokenizer<0.4.0,>=0.3.9 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from ai21==2.0.0rc9->langchain-ai21) (0.3.11)\r\n", | ||
"Requirement already satisfied: dataclasses-json<0.7.0,>=0.6.3 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from ai21==2.0.0rc9->langchain-ai21) (0.6.3)\r\n", | ||
"Requirement already satisfied: requests<3.0.0,>=2.31.0 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from ai21==2.0.0rc9->langchain-ai21) (2.31.0)\r\n", | ||
"Requirement already satisfied: PyYAML>=5.3 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from langchain-core>=0.0.12->langchain-ai21) (6.0.1)\r\n", | ||
"Requirement already satisfied: anyio<5,>=3 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from langchain-core>=0.0.12->langchain-ai21) (4.2.0)\r\n", | ||
"Requirement already satisfied: jsonpatch<2.0,>=1.33 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from langchain-core>=0.0.12->langchain-ai21) (1.33)\r\n", | ||
"Requirement already satisfied: langsmith<0.1,>=0.0.83 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from langchain-core>=0.0.12->langchain-ai21) (0.0.88)\r\n", | ||
"Requirement already satisfied: packaging<24.0,>=23.2 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from langchain-core>=0.0.12->langchain-ai21) (23.2)\r\n", | ||
"Requirement already satisfied: pydantic<3,>=1 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from langchain-core>=0.0.12->langchain-ai21) (2.5.3)\r\n", | ||
"Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from langchain-core>=0.0.12->langchain-ai21) (8.2.3)\r\n", | ||
"Requirement already satisfied: sentencepiece<0.2.0,>=0.1.96 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from ai21-tokenizer<0.4.0,>=0.3.9->ai21==2.0.0rc9->langchain-ai21) (0.1.99)\r\n", | ||
"Requirement already satisfied: idna>=2.8 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from anyio<5,>=3->langchain-core>=0.0.12->langchain-ai21) (3.6)\r\n", | ||
"Requirement already satisfied: sniffio>=1.1 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from anyio<5,>=3->langchain-core>=0.0.12->langchain-ai21) (1.3.0)\r\n", | ||
"Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from anyio<5,>=3->langchain-core>=0.0.12->langchain-ai21) (1.2.0)\r\n", | ||
"Requirement already satisfied: typing-extensions>=4.1 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from anyio<5,>=3->langchain-core>=0.0.12->langchain-ai21) (4.9.0)\r\n", | ||
"Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from dataclasses-json<0.7.0,>=0.6.3->ai21==2.0.0rc9->langchain-ai21) (3.20.2)\r\n", | ||
"Requirement already satisfied: typing-inspect<1,>=0.4.0 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from dataclasses-json<0.7.0,>=0.6.3->ai21==2.0.0rc9->langchain-ai21) (0.9.0)\r\n", | ||
"Requirement already satisfied: jsonpointer>=1.9 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from jsonpatch<2.0,>=1.33->langchain-core>=0.0.12->langchain-ai21) (2.4)\r\n", | ||
"Requirement already satisfied: annotated-types>=0.4.0 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from pydantic<3,>=1->langchain-core>=0.0.12->langchain-ai21) (0.6.0)\r\n", | ||
"Requirement already satisfied: pydantic-core==2.14.6 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from pydantic<3,>=1->langchain-core>=0.0.12->langchain-ai21) (2.14.6)\r\n", | ||
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.31.0->ai21==2.0.0rc9->langchain-ai21) (3.3.2)\r\n", | ||
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.31.0->ai21==2.0.0rc9->langchain-ai21) (2.1.0)\r\n", | ||
"Requirement already satisfied: certifi>=2017.4.17 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from requests<3.0.0,>=2.31.0->ai21==2.0.0rc9->langchain-ai21) (2023.11.17)\r\n", | ||
"Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7.0,>=0.6.3->ai21==2.0.0rc9->langchain-ai21) (1.0.0)\r\n", | ||
"Downloading ai21-2.0.0rc9-py3-none-any.whl (47 kB)\r\n", | ||
"\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m47.9/47.9 kB\u001B[0m \u001B[31m697.2 kB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\u001B[36m0:00:01\u001B[0m\r\n", | ||
"\u001B[?25h\u001B[33mWARNING: Ignoring invalid distribution -i21 (/Users/asafg/Projects/langchain/.venv/lib/python3.10/site-packages)\u001B[0m\u001B[33m\r\n", | ||
"\u001B[0mInstalling collected packages: ai21\r\n", | ||
" Attempting uninstall: ai21\r\n", | ||
" Found existing installation: ai21 2.0.0\r\n", | ||
" Uninstalling ai21-2.0.0:\r\n", | ||
" Successfully uninstalled ai21-2.0.0\r\n", | ||
"Successfully installed ai21-2.0.0rc9\r\n", | ||
"\r\n", | ||
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m23.2.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m24.0\u001B[0m\r\n", | ||
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\r\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# install package\n", | ||
"!pip install -U langchain-ai21" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "2b4f3e15", | ||
"metadata": {}, | ||
"source": [ | ||
"## Environment Setup\n", | ||
"\n", | ||
"We'll need to get a [AI21 API key](https://docs.ai21.com/) and set the `AI21_API_KEY` environment variable:\n" | ||
] | ||
}, | ||
{ | ||
"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()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"## Usage" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"id": "4828829d3da430ce" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"outputs": [], | ||
"source": [ | ||
"from langchain_ai21.chat_models import ChatAI21\n", | ||
"from langchain_core.prompts import ChatPromptTemplate\n", | ||
"\n", | ||
"chat = ChatAI21()\n", | ||
"\n", | ||
"prompt = ChatPromptTemplate.from_messages(\n", | ||
" [\n", | ||
" (\"system\", \"You are a helpful assistant that translates English to French.\"),\n", | ||
" (\"human\", \"Translate this sentence from English to French. {english_text}.\"),\n", | ||
" ]\n", | ||
")\n", | ||
"\n", | ||
"chain = prompt | chat\n", | ||
"chain.invoke({\"english_text\": \"Hello, how are you?\"})" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"id": "39353473fce5dd2e" | ||
} | ||
], | ||
"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.10.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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.