From 64a9530e5dd51fd0d313b6d05164e9495d2fd24d Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 27 Jun 2024 11:51:02 +0200 Subject: [PATCH] openai library update, model swap --- lib/galaxy/webapps/galaxy/api/chat.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/chat.py b/lib/galaxy/webapps/galaxy/api/chat.py index c4a0b3663626..884a15d7cb3f 100644 --- a/lib/galaxy/webapps/galaxy/api/chat.py +++ b/lib/galaxy/webapps/galaxy/api/chat.py @@ -1,6 +1,7 @@ """ API Controller providing Chat functionality """ + import logging try: @@ -38,8 +39,9 @@ def query(self, query: ChatPayload, trans: ProvidesUserContext = DependsOnTrans) if openai is None or self.config.openai_api_key is None: raise ConfigurationError("OpenAI is not configured for this instance.") - else: - openai.api_key = self.config.openai_api_key + client = openai.OpenAI( + api_key=self.config.openai_api_key, + ) messages = [ {"role": "system", "content": PROMPT}, @@ -50,16 +52,10 @@ def query(self, query: ChatPayload, trans: ProvidesUserContext = DependsOnTrans) msg = "The user will provide you a Galaxy tool error, and you will try to explain the error and provide a solution." messages.append({"role": "system", "content": msg}) - client = OpenAI( - organization='org-gO14XNCI5fwciPOYeic5Kq14', - project='$PROJECT_ID', - ) - - - response = client.create_chat( + completion = client.chat.completions.create( model="gpt-4o", messages=messages, temperature=0, ) - answer = response["choices"][0]["message"]["content"] + answer = completion.choices[0].message.content return answer