Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reka model integration #26405

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 266 additions & 0 deletions docs/docs/integrations/chat/reka.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.chat_models import ChatReka"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"model = ChatReka()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"image_url = \"https://v0.docs.reka.ai/_images/000000245576.jpg\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"sidebar_label: Reka\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ChatReka\n",
"\n",
"This notebook provides a quick overview for getting started with Reka [chat models](/docs/concepts/#chat-models). \n",
"\n",
"Reka has several chat models. You can find information about their latest models and their costs, context windows, and supported input types in the [Reka docs](https://docs.reka.ai/available-models).\n",
"\n",
"\n",
"\n",
"\n",
"## Overview\n",
"### Integration details\n",
"\n",
"| Class | Package | Local | Serializable | JS support | Package downloads | Package latest |\n",
"| :--- | :--- | :---: | :---: | :---: | :---: | :---: |\n",
"| [ChatReka] | [langchain_community](https://python.langchain.com/v0.2/api_reference/community/index.html) | ✅ | ❌ | ❌ | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain_community?style=flat-square&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain_community?style=flat-square&label=%20) |\n",
"\n",
"### Model features\n",
"| [Tool calling](/docs/how_to/tool_calling) | [Structured output](/docs/how_to/structured_output/) | JSON mode | [Image input](/docs/how_to/multimodal_inputs/) | Audio input | Video input | [Token-level streaming](/docs/how_to/chat_streaming/) | Native async | [Token usage](/docs/how_to/chat_token_usage_tracking/) | [Logprobs](/docs/how_to/logprobs/) |\n",
"| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |\n",
"| ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | \n",
"\n",
"## Setup\n",
"\n",
"To access Reka models you'll need to create an Reka developer account, get an API key, and install the `langchain_community` integration package and the reka python package via 'pip install reka-api'.\n",
"\n",
"### Credentials\n",
"\n",
"Head to https://platform.reka.ai/ to sign up for Reka and generate an API key. Once you've done this set the REKA_API_KEY environment variable:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Installation\n",
"\n",
"The LangChain __ModuleName__ integration lives in the `langchain_community` package:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install -qU langchain_community"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Initialize a client"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import getpass\n",
"import os\n",
"\n",
"# os.environ[\"REKA_API_KEY\"] = getpass.getpass(\"Enter your Reka API key: \")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install -qU langchain_community"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.chat_models import ChatReka\n",
"# This \n",
"model = ChatReka()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Single turn text message"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content=' Hello! How can I help you today? If you have any questions or need assistance with something, feel free to ask.\\n\\n', id='run-492dcda9-79b8-4e16-a81f-2f77b7d4e23a-0')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.invoke('hi')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Images input "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" The image you've uploaded is an indoor shot, and therefore, it does not provide any information about the weather outside. Since there are no windows or outdoor views depicted, it's not possible to determine the weather conditions at the time the photo was taken. If you need information about the weather, you should check a weather app, website, or news source based on your location or the location where the image was captured.\n"
]
}
],
"source": [
"from langchain_community.chat_models import ChatReka\n",
"import httpx\n",
"\n",
"model = ChatReka()\n",
"image_url = \"https://v0.docs.reka.ai/_images/000000245576.jpg\"\n",
"from langchain_core.messages import HumanMessage\n",
"\n",
"message = HumanMessage(\n",
" content=[\n",
" {\"type\": \"text\", \"text\": \"describe the weather in this image\"},\n",
" {\n",
" \"type\": \"image_url\",\n",
" \"image_url\": {\"url\": image_url},\n",
" },\n",
" ],\n",
")\n",
"response = model.invoke([message])\n",
"print(response.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Multiple images as input"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" The two images are quite different in several ways. \n",
"\n",
"Firstly, the subjects of the images are different. The first image features a cat, while the second image features two German Shepherds, an adult and a puppy.\n",
"\n",
"Secondly, the actions depicted are different. In the first image, the cat is sitting still and looking directly at the camera. In contrast, the second image captures the two dogs in motion, running across a grassy field with a stick in the mouth of the adult dog.\n",
"\n",
"Lastly, the setting of the images is different. The first image has a neutral, blurred background, providing no specific context about the location. The second image, on the other hand, is set in an outdoor environment with a grassy field and trees in the background.\n",
"\n",
"These differences highlight the distinct characteristics and behaviors of the animals as well as the varying contexts in which they are photographed.\n"
]
}
],
"source": [
"message = HumanMessage(\n",
" content=[\n",
" {\"type\": \"text\", \"text\": \"What are the difference between the two images? \"},\n",
" {\n",
" \"type\": \"image_url\",\n",
" \"image_url\": {\"url\": \"https://cdn.pixabay.com/photo/2019/07/23/13/51/shepherd-dog-4357790_1280.jpg\"},\n",
" },\n",
" {\n",
" \"type\": \"image_url\",\n",
" \"image_url\": {\"url\": \"https://cdn.pixabay.com/photo/2024/02/17/00/18/cat-8578562_1280.jpg\"},\n",
" },\n",
" ],\n",
")\n",
"response = model.invoke([message])\n",
"print(response.content)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "langchain_reka",
"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.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions libs/community/extended_testing_deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ rapidfuzz>=3.1.1,<4
rapidocr-onnxruntime>=1.3.2,<2
rdflib==7.0.0
requests-toolbelt>=1.0.0,<2
reka-api>=3.2.0
rspace_client>=2.5.0,<3
scikit-learn>=1.2.2,<2
simsimd>=5.0.0,<6
Expand Down
7 changes: 6 additions & 1 deletion libs/community/langchain_community/chat_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@
)
from langchain_community.chat_models.sambanova import (
ChatSambaNovaCloud,
ChatSambaStudio,
ChatSambaStudio
)
from langchain_community.chat_models.reka import (
ChatReka,
)
from langchain_community.chat_models.snowflake import (
ChatSnowflakeCortex,
Expand Down Expand Up @@ -214,6 +217,7 @@
"ChatOllama",
"ChatOpenAI",
"ChatPerplexity",
"ChatReka",
"ChatPremAI",
"ChatSambaNovaCloud",
"ChatSambaStudio",
Expand Down Expand Up @@ -274,6 +278,7 @@
"ChatOCIGenAI": "langchain_community.chat_models.oci_generative_ai",
"ChatOllama": "langchain_community.chat_models.ollama",
"ChatOpenAI": "langchain_community.chat_models.openai",
"ChatReka": "langchain_community.chat_models.reka",
"ChatPerplexity": "langchain_community.chat_models.perplexity",
"ChatSambaNovaCloud": "langchain_community.chat_models.sambanova",
"ChatSambaStudio": "langchain_community.chat_models.sambanova",
Expand Down
Loading