diff --git a/tests/rest/utils/extract_tools_from_system_prompt.py b/tests/rest/utils/extract_tools_from_system_prompt.py new file mode 100644 index 00000000..7d7aff3b --- /dev/null +++ b/tests/rest/utils/extract_tools_from_system_prompt.py @@ -0,0 +1,21 @@ +import json + + +def extract_tools(system_prompt): + l = system_prompt.rfind("") + r = system_prompt.rfind("") + + if l != -1 and r != -1: + tool_content = system_prompt[l + len("") : r] + print(tool_content.split("\n")) + tools = [json.loads(tool) for tool in tool_content.split("\n") if tool] + return tools + else: + raise ValueError("Invalid system prompt") + + +if __name__ == "__main__": + system_prompt = 'You are a helpful assistant designed to assist with the user query by making one or more function calls if needed.\n\nYou are provided with function signatures within XML tags:\n\n{"name": "verify_address", "description": "Verify the address", "parameters": {"type": "object", "property_address": {"type": "str", "description": "Complete address of the property", "format": "Street address, City, State Country"}, "required": ["property_address"]}}\n{"name": "track_shipment", "description": "Track the shipment", "parameters": {"type": "object", "properties": {"tracking_number": {"type": "str", "description": "The tracking number"}}, "required": ["tracking_number"]}}\n{"name": "generate_label", "description": "Generate the shipping label", "parameters": {"type": "object", "properties": {"sender": {"type": "str", "description": "The address to ship from"}, "recipient": {"type": "str", "description": "The address to ship to"}, "weight": {"type": "int", "description": "The weight of the package"}}, "required": ["sender", "recipient", "weight"]}}\n{"name": "calculate_shipping_rate", "description": "Calculate the shipping rate", "parameters": {"type": "object", "properties": {"sender": {"type": "str", "description": "The address to ship from"}, "recipient": {"type": "str", "description": "The address to ship to"}, "weight": {"type": "int", "description": "The weight of the package"}}, "required": ["sender", "recipient", "weight"]}}\n\n\nYour task is to decide which functions are needed and collect missing parameters if necessary.\n\nBased on your analysis, provide your response in one of the following JSON formats:\n1. If no functions are needed:\n```\n{"response": "Your response text here"}\n```\n2. If functions are needed but some required parameters are missing:\n```\n{"required_functions": ["func_name1", "func_name2", ...], "clarification": "Text asking for missing parameters"}\n```\n3. If functions are needed and all required parameters are available:\n```\n{"tool_calls": [{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},... (more tool calls as required)]}\n```' + + tools = extract_tools(system_prompt) + print(json.dumps(tools, indent=4)) diff --git a/tests/rest/generate_observations.py b/tests/rest/utils/generate_observations.py similarity index 100% rename from tests/rest/generate_observations.py rename to tests/rest/utils/generate_observations.py diff --git a/tests/rest/generate_random_system_prompt.py b/tests/rest/utils/generate_random_system_prompt.py similarity index 99% rename from tests/rest/generate_random_system_prompt.py rename to tests/rest/utils/generate_random_system_prompt.py index 75e685b4..0c0cb5df 100644 --- a/tests/rest/generate_random_system_prompt.py +++ b/tests/rest/utils/generate_random_system_prompt.py @@ -125,5 +125,6 @@ if __name__ == "__main__": print("\n" + "=" * 50 + " System Prompt " + "=" * 50) system_prompt = build_system_prompt(tools) + # print(repr(system_prompt.encode("unicode_escape").decode())) print(json.dumps(system_prompt)) diff --git a/tests/rest/generate_system_prompt.py b/tests/rest/utils/generate_system_prompt.py similarity index 78% rename from tests/rest/generate_system_prompt.py rename to tests/rest/utils/generate_system_prompt.py index 27a6c209..e96d9ea7 100644 --- a/tests/rest/generate_system_prompt.py +++ b/tests/rest/utils/generate_system_prompt.py @@ -28,17 +28,21 @@ Based on your analysis, provide your response in one of the following JSON forma tools = [ { "name": "get_weather", - "description": "Determine weather in my location", + "description": "Retrieves current weather for the given location.", "parameters": { "type": "object", "properties": { "location": { - "type": "string", - "description": "The city and state e.g. San Francisco, CA", + "type": "str", + "description": "City and country e.g. Bogotá, Colombia", + }, + "units": { + "type": "str", + "enum": ["celsius", "fahrenheit"], + "description": "Units the temperature will be returned in.", }, - "unit": {"type": "string", "enum": ["c", "f"]}, }, - "required": ["location", "unit"], + "required": ["location", "units"], }, }, { @@ -47,7 +51,7 @@ tools = [ "parameters": { "type": "object", "properties": { - "symbol": {"type": "string", "description": "The stock symbol"} + "symbol": {"type": "str", "description": "The stock symbol"} }, "required": ["symbol"], }, @@ -68,5 +72,6 @@ def build_system_prompt(tools: List[Dict[str, Any]]) -> str: if __name__ == "__main__": system_prompt = build_system_prompt(tools) + # print(repr(system_prompt.encode("unicode_escape").decode())) print(json.dumps(system_prompt))