eagle0504 commited on
Commit
ce4d370
·
verified ·
1 Parent(s): b7de3e2

Update helper/utils.py

Browse files
Files changed (1) hide show
  1. helper/utils.py +23 -21
helper/utils.py CHANGED
@@ -129,40 +129,42 @@ def list_to_nums(sentences: List[str]) -> List[List[float]]:
129
  return embeddings
130
 
131
 
132
- def call_gpt4(prompt: str) -> str:
133
  """
134
- Sends a prompt to the GPT-4 model and retrieves a response.
 
135
 
136
- This function interacts with the OpenAI API, specifically using
137
- the gpt-3.5-turbo model to generate a conversational response.
138
- It simulates a conversation by providing system messages,
139
- past interactions, and the latest user query.
140
 
141
  Args:
142
- - prompt (str): The message from the user for which the GPT model will generate a response.
 
143
 
144
  Returns:
145
- - str: The content of the message generated by the GPT model in response to the prompt.
146
 
147
- Note: This function assumes that 'client' is an instance of OpenAI's client object
148
- that has been properly authenticated and initialized elsewhere in your code.
149
  """
150
 
151
- # Interact with the OpenAI API to get a response for the prompt provided
152
  response = client.chat.completions.create(
153
- model="gpt-3.5-turbo", # Specifies the AI model to use for the response
154
- messages=[ # Constructs the context and the prompt for the AI
 
155
  {"role": "system", "content": "You are a helpful assistant."},
156
- {"role": "user", "content": "Who won the world series in 2020?"},
157
- {
158
- "role": "assistant",
159
- "content": "The Los Angeles Dodgers won the World Series in 2020."
160
- },
161
- {"role": "user", "content": "Where was it played?"}
162
  ]
163
  )
164
-
165
- # Return the AI's response to the user's most recent prompt
166
  return response.choices[0].message.content
167
 
168
 
 
129
  return embeddings
130
 
131
 
132
+ def call_gpt(prompt: str, content: str) -> str:
133
  """
134
+ Sends a structured conversation context including a system prompt, user prompt,
135
+ and additional background content to the GPT-3.5-turbo model for a response.
136
 
137
+ This function is responsible for generating an AI-powered response by interacting
138
+ with the OpenAI API. It puts together a preset system message, a formatted user query,
139
+ and additional background information before requesting the completion from the model.
 
140
 
141
  Args:
142
+ prompt (str): The main question or topic that the user wants to address.
143
+ content (str): Additional background information or details relevant to the prompt.
144
 
145
  Returns:
146
+ str: The generated response from the GPT model based on the given prompts and content.
147
 
148
+ Note: 'client' is assumed to be an already created and authenticated instance of the OpenAI
149
+ client, which should be set up prior to calling this function.
150
  """
151
 
152
+ # Generates a response from the model based on the interactive messages provided
153
  response = client.chat.completions.create(
154
+ model="gpt-3.5-turbo", # The AI model being queried for a response
155
+ messages=[
156
+ # System message defining the assistant's role
157
  {"role": "system", "content": "You are a helpful assistant."},
158
+ # User message containing the prompt
159
+ {"role": "user", "content": f"I want to ask you a question: {prompt}"},
160
+ # Assistant message asking for background content
161
+ {"role": "assistant", "content": "What is the background content?"},
162
+ # User providing the background content
163
+ {"role": "user", "content": content},
164
  ]
165
  )
166
+
167
+ # Extracts and returns the response content from the model's completion
168
  return response.choices[0].message.content
169
 
170