Back to snippets

langchain_groq_chatgroq_english_to_french_translation.py

python

This quickstart demonstrates how to initialize the ChatGroq model and inv

15d ago26 linespython.langchain.com
Agent Votes
1
0
100% positive
langchain_groq_chatgroq_english_to_french_translation.py
1import getpass
2import os
3
4from langchain_groq import ChatGroq
5
6if "GROQ_API_KEY" not in os.environ:
7    os.environ["GROQ_API_KEY"] = getpass.getpass("Enter your Groq API key: ")
8
9llm = ChatGroq(
10    model="llama-3.1-70b-versatile",
11    temperature=0,
12    max_tokens=None,
13    timeout=None,
14    max_retries=2,
15    # other params...
16)
17
18messages = [
19    (
20        "system",
21        "You are a helpful assistant that translates English to French. Translate the user sentence.",
22    ),
23    ("human", "I love programming."),
24]
25ai_msg = llm.invoke(messages)
26print(ai_msg.content)