From e83d93ab8139dce8df9aab6124e7efb86a2087bd Mon Sep 17 00:00:00 2001 From: Luis Guillen <81443577+LuisGuillen03@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:51:51 -0600 Subject: [PATCH] Improve tool selection in Hal9 app (#454) --- apps/hal9/app.py | 6 ++++-- apps/hal9/requirements.txt | 3 ++- apps/hal9/tools/calculator.py | 6 +++--- apps/hal9/tools/game.py | 6 +++--- apps/hal9/tools/generic.py | 6 +++--- apps/hal9/tools/streamlit.py | 6 +++--- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/hal9/app.py b/apps/hal9/app.py index 28265a00..e0418802 100644 --- a/apps/hal9/app.py +++ b/apps/hal9/app.py @@ -14,7 +14,7 @@ from tools.document import document_reply from tools.csv import csv_reply -MODEL = "llama3-70b-8192" +MODEL = "llama3-groq-70b-8192-tool-use-preview" def run(messages, tools): return Groq().chat.completions.create( model = MODEL, @@ -22,12 +22,14 @@ def run(messages, tools): temperature = 0, seed = 1, tools=tools, - tool_choice="auto") + tool_choice = "required",) prompt = input("") h9.event('prompt', prompt) messages = h9.load("messages", []) +if len(messages) <= 0: + messages.append({"role": "system", "content": "You are Hal9, a helpful and highly capable AI assistant. Your primary responsibility is to analyze user questions and select the most appropriate tool to provide precise, relevant, and actionable responses. Always prioritize using the right tool to ensure efficiency and clarity in your answers."}) messages.append({"role": "user", "content": prompt}) h9.save("messages", messages, hidden=True) diff --git a/apps/hal9/requirements.txt b/apps/hal9/requirements.txt index e5283f9b..e88981a4 100644 --- a/apps/hal9/requirements.txt +++ b/apps/hal9/requirements.txt @@ -1 +1,2 @@ -replicate==1.0.3 \ No newline at end of file +replicate==1.0.3 +groq==0.12.0 \ No newline at end of file diff --git a/apps/hal9/tools/calculator.py b/apps/hal9/tools/calculator.py index dfc6b3a9..6a4e2ed1 100644 --- a/apps/hal9/tools/calculator.py +++ b/apps/hal9/tools/calculator.py @@ -1,7 +1,7 @@ def calculate(expression): - """ - Performs aritmetic operations for numerical questions. - 'expression' is the aritmetic operations to evaluate, needs conversion to proper Python syntax. + """Use this tool to provide a solution to mathematical problems with a expression using Python code +Parameters: + 'expression' = is the aritmetic operations to evaluate, needs conversion to proper Python syntax. """ result = eval(expression) print(result) diff --git a/apps/hal9/tools/game.py b/apps/hal9/tools/game.py index 588f89fd..89d04ca6 100644 --- a/apps/hal9/tools/game.py +++ b/apps/hal9/tools/game.py @@ -11,9 +11,9 @@ ) def build_game(user_game_request): - """ - Build a complex video game from a short text description. - 'user_game_request' is the requested user game to build. + """Use this tool when a user explicitly requests to build a video game or provides a brief description resembling a video game concept. +Parameters: + 'user_game_request' = is the requested user game to build. """ number_of_steps = 3 diff --git a/apps/hal9/tools/generic.py b/apps/hal9/tools/generic.py index d9135c02..569c27ba 100644 --- a/apps/hal9/tools/generic.py +++ b/apps/hal9/tools/generic.py @@ -4,9 +4,9 @@ import json def generic_reply(prompt): - """ - Reply to anything that other tools do not support. - 'prompt' to respond to. + """Use this tool for general knowledge questions. If unsure which tool to select, default to this one. +Parameters: + 'prompt' = user input """ messages = h9.load("messages", []) diff --git a/apps/hal9/tools/streamlit.py b/apps/hal9/tools/streamlit.py index 06ffb2d4..4ed2e9bc 100644 --- a/apps/hal9/tools/streamlit.py +++ b/apps/hal9/tools/streamlit.py @@ -4,9 +4,9 @@ import json def build_streamlit(prompt): - """ - Builds or modifies a streamlit application ideal to solve problems with Python that require data analysis - 'prompt' with user change or requirements + """Use this tool when a user requests a Streamlit app or asks to modify a previously generated one. +Parameters: + 'prompt' = with user change or requirements """ client = openai.AzureOpenAI( azure_endpoint = 'https://openai-hal9.openai.azure.com/',