Spaces:
Sleeping
Sleeping
File size: 843 Bytes
68df5c7 c7e445e 816a73b 68df5c7 816a73b 68df5c7 816a73b 68df5c7 816a73b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import os
from langchain_openai import ChatOpenAI
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
# Load API keys from environment variables
openai_api_key = os.getenv("OPENAI_API_KEY")
weather_api_key = os.getenv("WEATHER_API_KEY")
# Validate that the keys exist
if not openai_api_key:
raise ValueError("Missing OpenAI API Key. Please add OPENAI_API_KEY as a secret.")
if not weather_api_key:
raise ValueError("Missing Weather API Key. Please add WEATHER_API_KEY as a secret.")
def get_chat_model():
"""Returns a configured ChatOpenAI model instance."""
return ChatOpenAI(
temperature=0.7, # Adjust as needed
model="gpt-4o-mini",
streaming=True,
callbacks=[StreamingStdOutCallbackHandler()], # Streams to stdout
openai_api_key=openai_api_key
)
|