2025-03-17 15:27:47 -07:00
import json
from typing import Any , Dict , List
ARCH_FUNCTION_TOOL_PROMPT = (
" You are a helpful assistant designed to assist with the user query by making one or more function calls if needed. "
2025-03-28 15:20:41 -07:00
" \n \n You are provided with function signatures within <tools></tools> XML tags: \n <tools> \n {tools} \n </tools> "
" \n \n Your task is to decide which functions are needed and collect missing parameters if necessary. "
2025-03-17 15:27:47 -07:00
)
2025-03-28 15:20:41 -07:00
ARCH_FUNCTION_FORMAT_PROMPT = (
" \n \n Based on your analysis, provide your response in one of the following JSON formats: "
' \n 1. If no functions are needed: \n ```json \n { " response " : " Your response text here " } \n ``` '
' \n 2. If functions are needed but some required parameters are missing: \n ```json \n { " required_functions " : [ " func_name1 " , " func_name2 " , ...], " clarification " : " Text asking for missing parameters " } \n ``` '
' \n 3. If functions are needed and all required parameters are available: \n ```json \n { " tool_calls " : [ { " name " : " func_name1 " , " arguments " : { " argument1 " : " value1 " , " argument2 " : " value2 " }},... (more tool calls as required)]} \n ``` '
)
2025-03-17 15:27:47 -07:00
tools = [
{
" name " : " get_weather " ,
2025-03-21 09:37:56 -07:00
" description " : " Retrieves current weather for the given location. " ,
2025-03-17 15:27:47 -07:00
" parameters " : {
" type " : " object " ,
" properties " : {
" location " : {
2025-03-21 09:37:56 -07:00
" type " : " str " ,
2025-03-21 09:49:22 -07:00
" description " : " City and State e.g. New York, NY " ,
2025-03-21 09:37:56 -07:00
} ,
" units " : {
" type " : " str " ,
" enum " : [ " celsius " , " fahrenheit " ] ,
" description " : " Units the temperature will be returned in. " ,
2025-03-17 15:27:47 -07:00
} ,
} ,
2025-03-21 09:37:56 -07:00
" required " : [ " location " , " units " ] ,
2025-03-17 15:27:47 -07:00
} ,
} ,
{
" name " : " get_stock_price " ,
" description " : " Get the current stock price " ,
" parameters " : {
" type " : " object " ,
" properties " : {
2025-03-21 09:37:56 -07:00
" symbol " : { " type " : " str " , " description " : " The stock symbol " }
2025-03-17 15:27:47 -07:00
} ,
" required " : [ " symbol " ] ,
} ,
} ,
]
def build_system_prompt ( tools : List [ Dict [ str , Any ] ] ) - > str :
tool_text = " "
for tool in tools :
tool_text + = " \n " + json . dumps ( tool )
return (
ARCH_FUNCTION_TOOL_PROMPT . format ( tool_text = tool_text )
+ ARCH_FUNCTION_FORMAT_PROMPT
)
if __name__ == " __main__ " :
system_prompt = build_system_prompt ( tools )
2025-03-21 09:37:56 -07:00
2025-03-17 15:27:47 -07:00
# print(repr(system_prompt.encode("unicode_escape").decode()))
print ( json . dumps ( system_prompt ) )