docs/examples/llm/groq.ipynb
<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/llm/groq.ipynb" target="_parent"></a>
Welcome to Groq! ๐ At Groq, we've developed the world's first Language Processing Unitโข, or LPU. The Groq LPU has a deterministic, single core streaming architecture that sets the standard for GenAI inference speed with predictable and repeatable performance for any given workload.
Beyond the architecture, our software is designed to empower developers like you with the tools you need to create innovative, powerful AI applications. With Groq as your engine, you can:
Want more Groq? Check out our website for more resources and join our Discord community to connect with our developers!
If you're opening this Notebook on colab, you will probably need to install LlamaIndex ๐ฆ.
% pip install llama-index-llms-groq
!pip install llama-index
from llama_index.llms.groq import Groq
Create an API key at the Groq console, then set it to the environment variable GROQ_API_KEY.
export GROQ_API_KEY=<your api key>
Alternatively, you can pass your API key to the LLM when you init it:
llm = Groq(model="llama3-70b-8192", api_key="your_api_key")
A list of available LLM models can be found here.
response = llm.complete("Explain the importance of low latency LLMs")
print(response)
chat with a list of messagesfrom llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.chat(messages)
print(resp)
Using stream_complete endpoint
response = llm.stream_complete("Explain the importance of low latency LLMs")
for r in response:
print(r.delta, end="")
Using stream_chat endpoint
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.stream_chat(messages)
for r in resp:
print(r.delta, end="")