@@ -146,21 +146,12 @@ def update_title(self, request, pk=None):
146146 )
147147
148148 def get_chatgpt_response (self , conversation , user_message , page_context = None ):
149- < << << << HEAD
150149 messages = [
151150 {
152151 "role" : "system" ,
153152 "content" : PromptTemplates .get_conversation_system_prompt (),
154153 }
155154 ]
156- == == == =
157- client = OpenAI (api_key = os .environ ["OPENAI_API_KEY" ])
158- messages = [{
159- "role" : "system" ,
160- "content" : "You are a knowledgeable assistant. Balancer is a powerful tool for selecting bipolar medication for patients. We are open-source and available for free use. Your primary role is to assist licensed clinical professionals with information related to Balancer and bipolar medication selection. If applicable, use the supplied tools to assist the professional."
161- }]
162- >> >> >> > listOfMed
163-
164155 if page_context :
165156 context_message = PromptTemplates .get_conversation_page_context_prompt (
166157 page_context
@@ -181,7 +172,6 @@ def get_chatgpt_response(self, conversation, user_message, page_context=None):
181172 )
182173
183174 response_message = response .choices [0 ].message
184- << << << < HEAD
185175 tool_calls = response_message .get ("tool_calls" , [])
186176
187177 if not tool_calls :
@@ -204,35 +194,10 @@ def get_chatgpt_response(self, conversation, user_message, page_context=None):
204194 tool_arguments = json .loads (
205195 tool_call ["function" ].get ("arguments" , "{}" )
206196 )
207- == == == =
208- tool_calls = getattr (response_message , "tool_calls" , [])
209-
210- tool_calls = response_message .model_dump ().get ("tool_calls" , [])
211-
212- if not tool_calls :
213- return response_message ['content' ]
214-
215- # Handle tool calls
216- # Add the assistant's message with tool calls to the conversation
217- messages .append ({
218- "role" : "assistant" ,
219- "content" : response_message .content or "" ,
220- "tool_calls" : tool_calls
221- })
222-
223- # Process each tool call
224- for tool_call in tool_calls :
225- tool_call_id = tool_call ['id' ]
226- tool_function_name = tool_call ['function' ]['name' ]
227- tool_arguments = json .loads (
228- tool_call ['function' ].get ('arguments' , '{}' ))
229- > >> >> >> listOfMed
230-
231197 # Execute the tool
232198 results = execute_tool (tool_function_name , tool_arguments )
233199
234200 # Add the tool response message
235- < << << << HEAD
236201 messages .append (
237202 {
238203 "role" : "tool" ,
@@ -247,21 +212,6 @@ def get_chatgpt_response(self, conversation, user_message, page_context=None):
247212 )
248213 return final_response .choices [0 ].message ["content" ]
249214 except openai .error .OpenAIError as e :
250- == == == =
251- messages .append ({
252- "role" : "tool" ,
253- "content" : str (results ), # Convert results to string
254- "tool_call_id" : tool_call_id
255- })
256-
257- # Final API call with tool results
258- final_response = client .chat .completions .create (
259- model = "gpt-3.5-turbo" ,
260- messages = messages
261- )
262- return final_response .choices [0 ].message .content
263- except OpenAI .error .OpenAIError as e :
264- >> >> >> > listOfMed
265215 logging .error ("OpenAI API Error: %s" , str (e ))
266216 raise OpenAIAPIException (detail = str (e ))
267217 except Exception as e :
@@ -285,8 +235,4 @@ def generate_title(self, conversation):
285235 ],
286236 )
287237
288- < << << << HEAD
289238 return response .choices [0 ].message ["content" ].strip ()
290- == == == =
291- return response .choices [0 ].message .content .strip ()
292- >> >> >> > listOfMed
0 commit comments