StreamingChatbot / config.py
Kelechi Osuji
Fixed more deprecation error
c7e445e
raw
history blame contribute delete
843 Bytes
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
)