Update helper/utils.py
Browse files- 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
|
133 |
"""
|
134 |
-
Sends a
|
|
|
135 |
|
136 |
-
This function
|
137 |
-
the
|
138 |
-
|
139 |
-
past interactions, and the latest user query.
|
140 |
|
141 |
Args:
|
142 |
-
|
|
|
143 |
|
144 |
Returns:
|
145 |
-
|
146 |
|
147 |
-
Note:
|
148 |
-
|
149 |
"""
|
150 |
|
151 |
-
#
|
152 |
response = client.chat.completions.create(
|
153 |
-
model="gpt-3.5-turbo", #
|
154 |
-
messages=[
|
|
|
155 |
{"role": "system", "content": "You are a helpful assistant."},
|
156 |
-
|
157 |
-
{
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
{"role": "user", "content":
|
162 |
]
|
163 |
)
|
164 |
-
|
165 |
-
#
|
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 |
|