From 4a04033a73f62ab1e98c62de7e2b99a28be33019 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 16 Mar 2023 17:13:39 -0400 Subject: [PATCH 01/33] Set up basic chat endpoint --- lib/galaxy/schema/schema.py | 6 ++++ lib/galaxy/webapps/galaxy/api/chat.py | 50 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 lib/galaxy/webapps/galaxy/api/chat.py diff --git a/lib/galaxy/schema/schema.py b/lib/galaxy/schema/schema.py index 077dc8e29bb7..182ff1e4d464 100644 --- a/lib/galaxy/schema/schema.py +++ b/lib/galaxy/schema/schema.py @@ -3706,6 +3706,12 @@ class MaterializeDatasetInstanceAPIRequest(Model): class MaterializeDatasetInstanceRequest(MaterializeDatasetInstanceAPIRequest): history_id: DecodedDatabaseIdField +class ChatPayload(Model): + query: str = Field( + ..., + title="Message", + description="The message to be sent to the chat.", + ) class CreatePagePayload(PageSummaryBase): content_format: PageContentFormat = ContentFormatField diff --git a/lib/galaxy/webapps/galaxy/api/chat.py b/lib/galaxy/webapps/galaxy/api/chat.py new file mode 100644 index 000000000000..94e6e1e8cd30 --- /dev/null +++ b/lib/galaxy/webapps/galaxy/api/chat.py @@ -0,0 +1,50 @@ +""" +API Controller providing Chat functionality +""" +import logging + +from . import ( + Router, +) + +import openai + +from galaxy.schema.schema import ChatPayload + +log = logging.getLogger(__name__) + +router = Router(tags=["chat"]) + +prompt = """ +I am a highly intelligent question answering agent, expert on Galaxy and in the fields of computer science, bioinformatics, and genomics. +If you ask me a question that I confidently know the answer to, I will give you the answer. +If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with "Unknown". + +An example question is here: + +Q: What is the Galaxy Project? +A: The Galaxy Project is an open, web-based platform for accessible, reproducible, and transparent computational biomedical research. + +Q: ${query} +""" + + +@router.cbv +class FastAPIChat: + @router.post("/api/chat") + def query(self, query: ChatPayload) -> str: + """We're off to ask the wizard""" + + openai.api_key = "NOPE" + + response = openai.Completion.create( + model="text-davinci-003", + prompt=prompt.format(query=query.query), + temperature=0, + max_tokens=400, + frequency_penalty=0.0, + presence_penalty=0.0, + stop=["\n"], + ) + answer = response.choices[0].text.strip() + return answer From 944ac9c786f6d5dd3508aba5eafd932e4b19e895 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 17 Mar 2023 08:34:16 -0400 Subject: [PATCH 02/33] Make openai key configurable --- doc/source/admin/galaxy_options.rst | 11 +++++++++++ lib/galaxy/config/sample/galaxy.yml.sample | 4 ++++ lib/galaxy/config/schemas/config_schema.yml | 6 ++++++ lib/galaxy/schema/schema.py | 2 ++ lib/galaxy/webapps/galaxy/api/chat.py | 18 ++++++++++++------ 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/doc/source/admin/galaxy_options.rst b/doc/source/admin/galaxy_options.rst index cb2d4c979d2b..e30d8254f254 100644 --- a/doc/source/admin/galaxy_options.rst +++ b/doc/source/admin/galaxy_options.rst @@ -5366,6 +5366,17 @@ :Type: int +~~~~~~~~~~~~~~~~~~ +``openai_api_key`` +~~~~~~~~~~~~~~~~~~ + +:Description: + API key for OpenAI (https://openai.com/) to enable the wizard (or + more?) +:Default: ``None`` +:Type: str + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``enable_tool_recommendations`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/galaxy/config/sample/galaxy.yml.sample b/lib/galaxy/config/sample/galaxy.yml.sample index fa14f2238763..bbce0a77f214 100644 --- a/lib/galaxy/config/sample/galaxy.yml.sample +++ b/lib/galaxy/config/sample/galaxy.yml.sample @@ -2882,6 +2882,10 @@ galaxy: # as threshold (above threshold: regular select fields will be used) #select_type_workflow_threshold: -1 + # API key for OpenAI (https://openai.com/) to enable the wizard (or + # more?) + #openai_api_key: null + # Allow the display of tool recommendations in workflow editor and # after tool execution. If it is enabled and set to true, please # enable 'tool_recommendation_model_path' as well diff --git a/lib/galaxy/config/schemas/config_schema.yml b/lib/galaxy/config/schemas/config_schema.yml index f0ee832e34ec..64ba9871bca4 100644 --- a/lib/galaxy/config/schemas/config_schema.yml +++ b/lib/galaxy/config/schemas/config_schema.yml @@ -3923,6 +3923,12 @@ mapping: use -1 (default) in order to always use the regular select fields, use any other positive number as threshold (above threshold: regular select fields will be used) + openai_api_key: + type: str + required: false + desc: | + API key for OpenAI (https://openai.com/) to enable the wizard (or more?) + enable_tool_recommendations: type: bool default: false diff --git a/lib/galaxy/schema/schema.py b/lib/galaxy/schema/schema.py index 182ff1e4d464..45e6d98e82bf 100644 --- a/lib/galaxy/schema/schema.py +++ b/lib/galaxy/schema/schema.py @@ -3706,6 +3706,7 @@ class MaterializeDatasetInstanceAPIRequest(Model): class MaterializeDatasetInstanceRequest(MaterializeDatasetInstanceAPIRequest): history_id: DecodedDatabaseIdField + class ChatPayload(Model): query: str = Field( ..., @@ -3713,6 +3714,7 @@ class ChatPayload(Model): description="The message to be sent to the chat.", ) + class CreatePagePayload(PageSummaryBase): content_format: PageContentFormat = ContentFormatField content: Optional[str] = ContentField diff --git a/lib/galaxy/webapps/galaxy/api/chat.py b/lib/galaxy/webapps/galaxy/api/chat.py index 94e6e1e8cd30..b918cc88d3a4 100644 --- a/lib/galaxy/webapps/galaxy/api/chat.py +++ b/lib/galaxy/webapps/galaxy/api/chat.py @@ -3,13 +3,14 @@ """ import logging -from . import ( - Router, -) - import openai +from galaxy.config import GalaxyAppConfiguration from galaxy.schema.schema import ChatPayload +from . import ( + depends, + Router, +) log = logging.getLogger(__name__) @@ -30,12 +31,17 @@ @router.cbv -class FastAPIChat: +class ChatAPI: + config: GalaxyAppConfiguration = depends(GalaxyAppConfiguration) + @router.post("/api/chat") def query(self, query: ChatPayload) -> str: """We're off to ask the wizard""" - openai.api_key = "NOPE" + if self.config.openai_api_key is None: + return "OpenAI is not configured for this instance." + else: + openai.api_key = self.config.openai_api_key response = openai.Completion.create( model="text-davinci-003", From 075b4ca770a849cbc2edcae0dea09d6b746e2621 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Tue, 21 Mar 2023 11:20:35 -0400 Subject: [PATCH 03/33] Basic wizard interface --- client/src/components/GalaxyWizard.vue | 42 ++++++++++++++++++++++++++ client/src/entry/analysis/router.js | 6 ++++ lib/galaxy/webapps/galaxy/buildapp.py | 1 + 3 files changed, 49 insertions(+) create mode 100644 client/src/components/GalaxyWizard.vue diff --git a/client/src/components/GalaxyWizard.vue b/client/src/components/GalaxyWizard.vue new file mode 100644 index 000000000000..ce196d5b604d --- /dev/null +++ b/client/src/components/GalaxyWizard.vue @@ -0,0 +1,42 @@ + +