import os from typing import List, Tuple import openai import streamlit as st openai_client = openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"]) def call_chatgpt(query: str, model: str = "gpt-3.5-turbo") -> str: """ Generates a response to a query using the specified language model. Args: query (str): The user's query that needs to be processed. model (str, optional): The language model to be used. Defaults to "gpt-3.5-turbo". Returns: str: The generated response to the query. """ # Prepare the conversation context with system and user messages. messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": f"Question: {query}."}, ] # Use the OpenAI client to generate a response based on the model and the conversation context. response = openai_client.chat.completions.create( model=model, messages=messages, ) # Extract the content of the response from the first choice. content: str = response.choices[0].message.content # Return the generated content. return content