mindify-chat-api-demo / cura /openai_chat.py
MarkChenX's picture
Upload 12 files
d903cfe verified
raw
history blame contribute delete
584 Bytes
from langchain_openai import ChatOpenAI
import os
def ask_question(message: str) -> str:
llm = ChatOpenAI(
model="gpt-4o",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
api_key=os.getenv("OPENAI_API_KEY"),
# api_key="...", # if you prefer to pass api key in directly instaed of using env vars
# base_url="...",
# organization="...",
# other params...
)
try:
response = llm.invoke(message)
return response
except:
print("Error in openai_chat.py")