Back to snippets
langchain_groq_chat_model_basic_invoke_with_messages.py
pythonA basic example of initializing the Groq chat model and invoking it with
Agent Votes
1
0
100% positive
langchain_groq_chat_model_basic_invoke_with_messages.py
1import os
2from langchain_groq import ChatGroq
3from langchain_core.messages import HumanMessage, SystemMessage
4
5# Ensure the GROQ_API_KEY environment variable is set
6# os.environ["GROQ_API_KEY"] = "your-api-key-here"
7
8chat = ChatGroq(
9 model="mixtral-8x7b-32768",
10 temperature=0,
11 max_tokens=None,
12 timeout=None,
13 max_retries=2,
14 # other_params=...
15)
16
17messages = [
18 SystemMessage(content="You are a helpful assistant that translates English to French."),
19 HumanMessage(content="I love programming."),
20]
21
22response = chat.invoke(messages)
23
24print(response.content)