2023-08-03 17:24:51 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Eden AI"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
"Eden AI is revolutionizing the AI landscape by uniting the best AI providers, empowering users to unlock limitless possibilities and tap into the true potential of artificial intelligence. With an all-in-one comprehensive and hassle-free platform, it allows users to deploy AI features to production lightning fast, enabling effortless access to the full breadth of AI capabilities via a single API. (website: https://edenai.co/)"
2023-08-03 17:24:51 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example goes over how to use LangChain to interact with Eden AI models\n",
"\n",
"-----------------------------------------------------------------------------------\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Accessing the EDENAI's API requires an API key, \n",
"\n",
"which you can get by creating an account https://app.edenai.run/user/register and heading here https://app.edenai.run/admin/account/settings\n",
"\n",
"Once we have a key we'll want to set it as an environment variable by running:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"export EDENAI_API_KEY=\"...\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you'd prefer not to set an environment variable you can pass the key in directly via the edenai_api_key named parameter\n",
"\n",
" when initiating the EdenAI LLM class:\n",
"\n"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"from langchain.llms import EdenAI"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
"llm = EdenAI(edenai_api_key=\"...\",provider=\"openai\", temperature=0.2, max_tokens=250)"
2023-08-03 17:24:51 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Calling a model\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The EdenAI API brings together various providers, each offering multiple models.\n",
"\n",
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
"To access a specific model, you can simply add 'model' during instantiation.\n",
2023-08-03 17:24:51 +00:00
"\n",
"For instance, let's explore the models provided by OpenAI, such as GPT3.5 "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### text generation"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
2023-09-01 22:15:12 +00:00
"outputs": [],
2023-08-03 17:24:51 +00:00
"source": [
"from langchain import PromptTemplate, LLMChain\n",
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
"llm=EdenAI(feature=\"text\",provider=\"openai\",model=\"text-davinci-003\",temperature=0.2, max_tokens=250)\n",
2023-08-03 17:24:51 +00:00
"\n",
"prompt = \"\"\"\n",
"User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?\n",
"Assistant:\n",
"\"\"\"\n",
"\n",
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
"llm(prompt)"
2023-08-03 17:24:51 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### image generation"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"import base64\n",
"from io import BytesIO\n",
"from PIL import Image\n",
"import json\n",
"def print_base64_image(base64_string):\n",
" # Decode the base64 string into binary data\n",
" decoded_data = base64.b64decode(base64_string)\n",
"\n",
" # Create an in-memory stream to read the binary data\n",
" image_stream = BytesIO(decoded_data)\n",
"\n",
" # Open the image using PIL\n",
" image = Image.open(image_stream)\n",
"\n",
" # Display the image\n",
" image.show()"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"text2image = EdenAI(\n",
" feature=\"image\" ,\n",
" provider= \"openai\",\n",
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
" resolution=\"512x512\"\n",
2023-08-03 17:24:51 +00:00
")"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"image_output = text2image(\"A cat riding a motorcycle by Picasso\")"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"print_base64_image(image_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### text generation with callback"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
2023-09-01 22:15:12 +00:00
"outputs": [],
2023-08-03 17:24:51 +00:00
"source": [
"from langchain.llms import EdenAI\n",
"from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
"\n",
"llm = EdenAI(\n",
" callbacks=[StreamingStdOutCallbackHandler()],\n",
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
" feature=\"text\",provider=\"openai\", temperature=0.2,max_tokens=250\n",
2023-08-03 17:24:51 +00:00
")\n",
"prompt = \"\"\"\n",
"User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?\n",
"Assistant:\n",
"\"\"\"\n",
"print(llm(prompt))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Chaining Calls"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"from langchain.chains import SimpleSequentialChain\n",
"from langchain.prompts import PromptTemplate\n",
"from langchain.chains import LLMChain"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"llm = EdenAI(\n",
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
"feature=\"text\", provider=\"openai\", temperature=0.2, max_tokens=250\n",
2023-08-03 17:24:51 +00:00
")\n",
"text2image = EdenAI(\n",
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
"feature=\"image\", provider=\"openai\", resolution=\"512x512\"\n",
2023-08-03 17:24:51 +00:00
")"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"prompt = PromptTemplate(\n",
" input_variables=[\"product\"],\n",
" template=\"What is a good name for a company that makes {product}?\",\n",
")\n",
"\n",
"chain = LLMChain(llm=llm, prompt=prompt)"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"second_prompt = PromptTemplate(\n",
" input_variables=[\"company_name\"],\n",
" template=\"Write a description of a logo for this company: {company_name}, the logo should not contain text at all \",\n",
")\n",
"chain_two = LLMChain(llm=llm, prompt=second_prompt)"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"third_prompt = PromptTemplate(\n",
" input_variables=[\"company_logo_description\"],\n",
" template=\"{company_logo_description}\",\n",
")\n",
"chain_three = LLMChain(llm=text2image, prompt=third_prompt)"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
2023-09-01 22:15:12 +00:00
"outputs": [],
2023-08-03 17:24:51 +00:00
"source": [
"# Run the chain specifying only the input variable for the first chain.\n",
"overall_chain = SimpleSequentialChain(\n",
" chains=[chain, chain_two, chain_three],verbose=True\n",
")\n",
"output = overall_chain.run(\"hats\")\n"
]
},
{
"cell_type": "code",
2023-09-01 22:15:12 +00:00
"execution_count": null,
2023-08-03 17:24:51 +00:00
"metadata": {},
"outputs": [],
"source": [
"#print the image\n",
"print_base64_image(output)"
]
}
],
"metadata": {
"kernelspec": {
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
"display_name": "Python 3 (ipykernel)",
2023-08-03 17:24:51 +00:00
"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",
2023-09-01 22:15:12 +00:00
"version": "3.11.3"
EdenAI LLM update. Add models name option (#8963)
This PR follows the **Eden AI (LLM + embeddings) integration**. #8633
We added an optional parameter to choose different AI models for
providers (like 'text-bison' for provider 'google', 'text-davinci-003'
for provider 'openai', etc.).
Usage:
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"model": "text-bison", # new
"temperature": 0.2,
"max_tokens": 250,
},
)
```
You can also change the provider + model after initialization
```python
llm = EdenAI(
feature="text",
provider="google",
params={
"temperature": 0.2,
"max_tokens": 250,
},
)
prompt = """
hi
"""
llm(prompt, providers='openai', model='text-davinci-003') # change provider & model
```
The jupyter notebook as been updated with an example well.
Ping: @hwchase17, @baskaryan
---------
Co-authored-by: RedhaWassim <rwasssim@gmail.com>
Co-authored-by: sam <melaine.samy@gmail.com>
2023-09-01 19:11:33 +00:00
}
2023-08-03 17:24:51 +00:00
},
"nbformat": 4,
"nbformat_minor": 2
}