Embedchain comes with built-in support for various popular large language models. We handle the complexity of integrating these models for you, allowing you to easily customize your language model interactions through a user-friendly interface.
With any of the previous inputs, the OpenAI LLM can be queried to provide the appropriate arguments for the function.
Copy
import osfrom embedchain import Appfrom embedchain.llm.openai import OpenAILlmos.environ["OPENAI_API_KEY"] = "sk-xxx"llm = OpenAILlm(tools=multiply)app = App(llm=llm)result = app.query("What is the result of 125 multiplied by fifteen?")
To use Google AI model, you have to set the GOOGLE_API_KEY environment variable. You can obtain the Google API key from the Google Maker Suite
Copy
import osfrom embedchain import Appos.environ["GOOGLE_API_KEY"] = "xxx"app = App.from_config(config_path="config.yaml")app.add("https://www.forbes.com/profile/elon-musk")response = app.query("What is the net worth of Elon Musk?")if app.llm.config.stream: # if stream is enabled, response is a generator for chunk in response: print(chunk)else: print(response)
Install related dependencies using the following command:
Copy
pip install --upgrade 'embedchain[clarifai]'
set the CLARIFAI_PAT as environment variable which you can find in the security page. Optionally you can also pass the PAT key as parameters in LLM/Embedder class.
Now you are all set with exploring Embedchain.
Copy
import osfrom embedchain import Appos.environ["CLARIFAI_PAT"] = "XXX"# load llm configuration from config.yaml fileapp = App.from_config(config_path="config.yaml")#Now let's add some data.app.add("https://www.forbes.com/profile/elon-musk")#Query the appresponse = app.query("what college degrees does elon musk have?")
Install related dependencies using the following command:
Copy
pip install --upgrade 'embedchain[opensource]'
GPT4all is a free-to-use, locally running, privacy-aware chatbot. No GPU or internet required. You can use this with Embedchain using the following code:
Copy
from embedchain import App# load llm configuration from config.yaml fileapp = App.from_config(config_path="config.yaml")
Setup Google Cloud Platform application credentials by following the instruction on GCP. Once setup is done, use the following code to create an app using VertexAI as provider:
Copy
from embedchain import App# load llm configuration from config.yaml fileapp = App.from_config(config_path="config.yaml")
os.environ["MISTRAL_API_KEY"] = "xxx"app = App.from_config(config_path="config.yaml")app.add("https://www.forbes.com/profile/elon-musk")response = app.query("what is the net worth of Elon Musk?")# As of January 16, 2024, Elon Musk's net worth is $225.4 billion.response = app.chat("which companies does elon own?")# Elon Musk owns Tesla, SpaceX, Boring Company, Twitter, and X.response = app.chat("what question did I ask you already?")# You have asked me several times already which companies Elon Musk owns, specifically Tesla, SpaceX, Boring Company, Twitter, and X.
Groq is the creator of the world’s first Language Processing Unit (LPU), providing exceptional speed performance for AI workloads running on their LPU Inference Engine.
In order to use LLMs from Groq, go to their platform and get the API key.
Set the API key as GROQ_API_KEY environment variable or pass in your app configuration to use the model as given below in the example.
Copy
import osfrom embedchain import App# Set your API key here or pass as the environment variablegroq_api_key = "gsk_xxxx"config = { "llm": { "provider": "groq", "config": { "model": "mixtral-8x7b-32768", "api_key": groq_api_key, "stream": True } }}app = App.from_config(config=config)# Add your data source hereapp.add("https://docs.embedchain.ai/sitemap.xml", data_type="sitemap")app.query("Write a poem about Embedchain")# In the realm of data, vast and wide,# Embedchain stands with knowledge as its guide.# A platform open, for all to try,# Building bots that can truly fly.# With REST API, data in reach,# Deployment a breeze, as easy as a speech.# Updating data sources, anytime, anyday,# Embedchain's power, never sway.# A knowledge base, an assistant so grand,# Connecting to platforms, near and far.# Discord, WhatsApp, Slack, and more,# Embedchain's potential, never a bore.
NVIDIA AI Foundation Endpoints let you quickly use NVIDIA’s AI models, such as Mixtral 8x7B, Llama 2 etc, through our API. These models are available in the NVIDIA NGC catalog, fully optimized and ready to use on NVIDIA’s AI platform. They are designed for high speed and easy customization, ensuring smooth performance on any accelerated setup.
In order to use LLMs from NVIDIA AI, create an account on NVIDIA NGC Service.
Generate an API key from their dashboard. Set the API key as NVIDIA_API_KEY environment variable. Note that the NVIDIA_API_KEY will start with nvapi-.
Below is an example of how to use LLM model and embedding model from NVIDIA AI:
Copy
import osfrom embedchain import Appos.environ['NVIDIA_API_KEY'] = 'nvapi-xxxx'config = { "app": { "config": { "id": "my-app", }, }, "llm": { "provider": "nvidia", "config": { "model": "nemotron_steerlm_8b", }, }, "embedder": { "provider": "nvidia", "config": { "model": "nvolveqa_40k", "vector_dimension": 1024, }, },}app = App.from_config(config=config)app.add("https://www.forbes.com/profile/elon-musk")answer = app.query("What is the net worth of Elon Musk today?")# Answer: The net worth of Elon Musk is subject to fluctuations based on the market value of his holdings in various companies.# As of March 1, 2024, his net worth is estimated to be approximately $210 billion. However, this figure can change rapidly due to stock market fluctuations and other factors.# Additionally, his net worth may include other assets such as real estate and art, which are not reflected in his stock portfolio.
You can get the cost of the query by setting token_usage to True in the config file. This will return the token details: prompt_tokens, completion_tokens, total_tokens, total_cost, cost_currency.
The list of paid LLMs that support token usage are:
OpenAI
Vertex AI
Anthropic
Cohere
Together
Groq
Mistral AI
NVIDIA AI
Here is an example of how to use token usage:
Copy
os.environ["OPENAI_API_KEY"] = "xxx"app = App.from_config(config_path="config.yaml")app.add("https://www.forbes.com/profile/elon-musk")response = app.query("what is the net worth of Elon Musk?")# {'answer': 'Elon Musk's net worth is $209.9 billion as of 6/9/24.',# 'usage': {'prompt_tokens': 1228,# 'completion_tokens': 21, # 'total_tokens': 1249, # 'total_cost': 0.001884, # 'cost_currency': 'USD'}# }response = app.chat("Which companies did Elon Musk found?")# {'answer': 'Elon Musk founded six companies, including Tesla, which is an electric car maker, SpaceX, a rocket producer, and the Boring Company, a tunneling startup.',# 'usage': {'prompt_tokens': 1616,# 'completion_tokens': 34,# 'total_tokens': 1650,# 'total_cost': 0.002492,# 'cost_currency': 'USD'}# }
If a model is missing and you’d like to add it to model_prices_and_context_window.json, please feel free to open a PR.
If you can't find the specific LLM you need, no need to fret. We're continuously expanding our support for additional LLMs, and you can help us prioritize by opening an issue on our GitHub or simply reaching out to us on our Slack or Discord community.