Skip to content

Commit

Permalink
Improve tool selection in Hal9 app (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisGuillen03 authored Nov 21, 2024
1 parent 1b5f1a6 commit e83d93a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
6 changes: 4 additions & 2 deletions apps/hal9/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
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,
messages = messages,
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)

Expand Down
3 changes: 2 additions & 1 deletion apps/hal9/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
replicate==1.0.3
replicate==1.0.3
groq==0.12.0
6 changes: 3 additions & 3 deletions apps/hal9/tools/calculator.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions apps/hal9/tools/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions apps/hal9/tools/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])
Expand Down
6 changes: 3 additions & 3 deletions apps/hal9/tools/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down

0 comments on commit e83d93a

Please sign in to comment.