forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
051c5ab
commit fc3928e
Showing
12 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<script setup lang="ts"> | ||
import axios from "axios"; | ||
import { ref } from "vue"; | ||
import Heading from "./Common/Heading.vue"; | ||
import LoadingSpan from "./LoadingSpan.vue"; | ||
const props = defineProps({ | ||
view: { | ||
type: String, | ||
default: "wizard", | ||
}, | ||
query: { | ||
type: String, | ||
default: "", | ||
}, | ||
context: { | ||
type: String, | ||
default: "", | ||
}, | ||
}); | ||
const query = ref(props.query); | ||
const queryResponse = ref(""); | ||
const busy = ref(false); | ||
// on submit, query the server and put response in display box | ||
function submitQuery() { | ||
busy.value = true; | ||
queryResponse.value = ""; | ||
const context = props.context || "username"; | ||
axios | ||
.post("/api/chat", { | ||
query: query.value, | ||
context: context, | ||
}) | ||
.then(function (response) { | ||
console.log(response); | ||
queryResponse.value = response.data; | ||
}) | ||
.catch(function (error) { | ||
console.error(error); | ||
}) | ||
.finally(() => { | ||
busy.value = false; | ||
}); | ||
} | ||
</script> | ||
<template> | ||
<div> | ||
<!-- input text, full width top of page --> | ||
<Heading v-if="props.view == 'wizard'" inline h2>Ask the wizard</Heading> | ||
<div :class="props.view == 'wizard' && 'mt-2'"> | ||
<b-input | ||
v-if="props.query == ''" | ||
id="wizardinput" | ||
v-model="query" | ||
style="width: 100%" | ||
placeholder="What's the difference in fasta and fastq files?" | ||
@keyup.enter="submitQuery" /> | ||
<b-button | ||
v-else-if="!queryResponse" | ||
variant="info" | ||
:disabled="busy" | ||
@click="submitQuery"> | ||
<span v-if="!busy"> | ||
Let our Help Wizard Figure it out! | ||
</span> | ||
<LoadingSpan v-else message="Thinking..." /> | ||
</b-button> | ||
</div> | ||
<!-- spinner when busy --> | ||
<div :class="props.view == 'wizard' && 'mt-4'"> | ||
<div v-if="busy"> | ||
<b-skeleton animation="wave" width="85%"></b-skeleton> | ||
<b-skeleton animation="wave" width="55%"></b-skeleton> | ||
<b-skeleton animation="wave" width="70%"></b-skeleton> | ||
</div> | ||
<div v-else class="chatResponse">{{ queryResponse }}</div> | ||
</div> | ||
</div> | ||
</template> | ||
<style lang="scss" scoped> | ||
.chatResponse { | ||
white-space: pre-wrap; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
API Controller providing Chat functionality | ||
""" | ||
import logging | ||
|
||
try: | ||
import openai | ||
except ImportError: | ||
openai = None | ||
|
||
from galaxy.config import GalaxyAppConfiguration | ||
from galaxy.managers.context import ProvidesUserContext | ||
from galaxy.webapps.galaxy.api import ( | ||
depends, | ||
DependsOnTrans, | ||
) | ||
from galaxy.exceptions import ConfigurationError | ||
from galaxy.schema.schema import ChatPayload | ||
from . import ( | ||
depends, | ||
Router, | ||
) | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
router = Router(tags=["chat"]) | ||
|
||
PROMPT = """ | ||
You are a highly intelligent question answering agent, expert on the Galaxy analysis platform and in the fields of computer science, bioinformatics, and genomics. | ||
You will try to answer questions about Galaxy, and if you don't know the answer, you will ask the user to rephrase the question. | ||
""" | ||
|
||
|
||
@router.cbv | ||
class ChatAPI: | ||
config: GalaxyAppConfiguration = depends(GalaxyAppConfiguration) | ||
|
||
@router.post("/api/chat") | ||
def query(self, query: ChatPayload, trans: ProvidesUserContext = DependsOnTrans) -> str: | ||
"""We're off to ask the wizard""" | ||
|
||
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 | ||
|
||
messages=[ | ||
{"role": "system", "content": PROMPT}, | ||
{"role": "user", "content": query.query}, | ||
] | ||
|
||
if query.context == "username": | ||
user = trans.user | ||
if user is not None: | ||
log.debug(f"CHATGPTuser: {user.username}") | ||
msg = f"You will address the user as {user.username}" | ||
else: | ||
msg = f"You will address the user as Anonymous User" | ||
messages.append({"role": "system", "content": msg}) | ||
elif query.context == "tool_error": | ||
msg = "The user will provide you a Galaxy tool error, and you will try to debug and explain what happened" | ||
messages.append({"role": "system", "content": msg}) | ||
|
||
log.debug(f"CHATGPTmessages: {messages}") | ||
|
||
response = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo", | ||
messages=messages, | ||
temperature=0, | ||
) | ||
|
||
answer = response["choices"][0]["message"]["content"] | ||
return answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters