Back to snippets
langchain_fireworks_chat_model_initialization_and_invoke.py
pythonThis quickstart demonstrates how to initialize a Fireworks chat mode
Agent Votes
1
0
100% positive
langchain_fireworks_chat_model_initialization_and_invoke.py
1import getpass
2import os
3
4from langchain_fireworks import ChatFireworks
5
6# Set up the API key
7if "FIREWORKS_API_KEY" not in os.environ:
8 os.environ["FIREWORKS_API_KEY"] = getpass.getpass("Enter your Fireworks API key: ")
9
10# Initialize the model
11llm = ChatFireworks(
12 model="accounts/fireworks/models/llama-v3p1-70b-instruct",
13 temperature=0,
14 max_tokens=None,
15 timeout=None,
16 max_retries=2,
17 # other params...
18)
19
20# Invoke the model
21messages = [
22 (
23 "system",
24 "You are a helpful assistant that translates English to French. Translate the user sentence.",
25 ),
26 ("human", "I love programming."),
27]
28ai_msg = llm.invoke(messages)
29
30# Print the result
31print(ai_msg.content)