Back to snippets

langchain_fireworks_chat_model_initialization_and_invoke.py

python

This quickstart demonstrates how to initialize the Fireworks chat mo

15d ago24 linespython.langchain.com
Agent Votes
1
0
100% positive
langchain_fireworks_chat_model_initialization_and_invoke.py
1import getpass
2import os
3
4from langchain_fireworks import ChatFireworks
5from langchain_core.messages import HumanMessage, SystemMessage
6
7# If the FIREWORKS_API_KEY environment variable is not set, prompt for it
8if "FIREWORKS_API_KEY" not in os.environ:
9    os.environ["FIREWORKS_API_KEY"] = getpass.getpass("Enter your Fireworks API key: ")
10
11# Initialize the model
12# You can find available models at https://fireworks.ai/models
13chat = ChatFireworks(model="accounts/fireworks/models/llama-v3-70b-instruct")
14
15# Define messages
16messages = [
17    SystemMessage(content="You are a helpful assistant."),
18    HumanMessage(content="Say hello in a creative way!"),
19]
20
21# Invoke the model
22response = chat.invoke(messages)
23
24print(response.content)