Skip to content

Commit

Permalink
Merge pull request #38 from uktrade/bugfix/gadget_not_using_tool
Browse files Browse the repository at this point in the history
Fix gadget tool calls
  • Loading branch information
nora-errouhly authored Jan 23, 2025
2 parents f5dd657 + 2972365 commit 6a883bb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ EMBEDDING_BACKEND=amazon.titan-embed-text-v2:0
COLLECTION_ENDPOINT="http://admin:Opensearch2024^@opensearch:9200"
OPENSEARCH_INITIAL_ADMIN_PASSWORD = "Opensearch2024^"

REDBOX_API_URL = http://localhost:8080/api/v0/
REDBOX_API_KEY = myapi


# LOGIN_METHOD=sso

# AUTHBROKER_CLIENT_ID=REPLACE_WITH_GITLAB_SECRET
Expand Down
2 changes: 1 addition & 1 deletion redbox-core/redbox/chains/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def parse_partial_json(self, text: str):
text = self.extract_json(text)
return parse_json_markdown(text)
except json.JSONDecodeError:
return None
return ""

def _to_generation_chunk(self, chunk: Union[str, BaseMessage]):
chunk_gen: Union[GenerationChunk, ChatGenerationChunk]
Expand Down
42 changes: 38 additions & 4 deletions redbox-core/redbox/models/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,60 @@
"\n"
)

# AGENTIC_RETRIEVAL_SYSTEM_PROMPT = (
# "You are an advanced problem-solving assistant. Your primary goal is to carefully "
# "analyse and work through complex questions or problems. You will receive a collection "
# "of documents (all at once, without any information about their order or iteration) and "
# "a list of tool calls that have already been made (also without order or iteration "
# "information). Based on this data, you are expected to think critically about how to "
# "proceed.\n"
# "\n"
# "Objective:\n"
# "1. Examine the available documents and tool calls:\n"
# "- Evaluate whether the current information is sufficient to answer the question.\n"
# "- Consider the success or failure of previous tool calls based on the data they returned.\n"
# "- Hypothesise whether new tool calls might bring more valuable information.\n"
# "\n"
# "2. Decide whether you can answer this question:\n"
# "- If additional tool calls are likely to yield useful information, make those calls.\n"
# "- If the available documents are sufficient to proceed, provide an answer\n"
# "Your role is to think deeply before taking any action. Carefully weigh whether new "
# "information is necessary or helpful. Only take action (call tools or providing and answer) after "
# "thorough evaluation of the current documents and tool calls."
# )

AGENTIC_RETRIEVAL_SYSTEM_PROMPT = (
"You are an advanced problem-solving assistant. Your primary goal is to carefully "
"analyse and work through complex questions or problems. You will receive a collection "
"of documents (all at once, without any information about their order or iteration) and "
"a list of tool calls that have already been made (also without order or iteration "
"information). Based on this data, you are expected to think critically about how to "
"proceed.\n"
"\n"
"Objective:\n"
"1. Examine the available documents and tool calls:\n"
"1. Use available tools if required to complete the task, OR\n"
"2. Return a direct response in the specified JSON schema format\n\n"
"Important Guidelines:\n\n"
"1. Response Format:\n"
"When providing a direct answer (not using tools), ALWAYS use this exact JSON schema:\n"
"{format_instructions}"
"2. Tool Usage:\n"
"- Before responding, evaluate if you need any tools to complete the task\n"
"- If tools are needed, call them using the appropriate function calls\n"
"- After getting tool results, format your final response in the required JSON schema\n\n"
"3. Decision Making:\n"
"3.1. Examine the available documents and tool calls:\n"
"- Evaluate whether the current information is sufficient to answer the question.\n"
"- Consider the success or failure of previous tool calls based on the data they returned.\n"
"- Hypothesise whether new tool calls might bring more valuable information.\n"
"\n"
"2. Decide whether you can answer this question:\n"
"3.2. Decide whether you can answer this question:\n"
"- If additional tool calls are likely to yield useful information, make those calls.\n"
"- If the available documents are sufficient to proceed, provide an answer\n"
"Your role is to think deeply before taking any action. Carefully weigh whether new "
"information is necessary or helpful. Only take action (call tools or providing and answer) after "
"thorough evaluation of the current documents and tool calls."
"4. Error Handling:\n"
"- If a tool call fails, explain the error and try an alternative approach\n"
"- If no tools are suitable, explain why and provide the best possible direct response"
)


Expand Down
2 changes: 1 addition & 1 deletion redbox-core/redbox/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def to_request_metadata(obj: dict) -> RequestMetadata:
try:
output_tokens = len(tokeniser.encode(response))
except Exception:
output_tokens = len(response[0].get("text"))
output_tokens = len(response[0].get("text", []))

metadata_event = RequestMetadata(
llm_calls=[
Expand Down

0 comments on commit 6a883bb

Please sign in to comment.