#!/usr/bin/env python3

# dummy harness code snippet
# illustrating tool definition and execution

def get_weather(city: str, moon: bool = False) -> str:
    """Dummy function defining a tool.
       Would return the current weather for a 
       city, e.g., as obtained from a weather API.
    """
    myString = f"The weather in {city} is sunny."
    if moon:
       myString += f" Rising moon."
    return myString


# tool description (OpenAI-style) sent to the LLM, 
# together with chat history
# :: nested dictionaries
 
WT_properties = { "city": { "type": "string",
                     "description": "The city to check."},
                  "moon": { "type": "boolean",
                     "description": "If true, returns also the moon phase.",
                         "default": False },
                }
#
WT_parameters = { "type"      : "object",
                  "properties": WT_properties,
                  "required"  : ["city"]
                }
#
WT_function   = { "name"       : "get_weather",
                  "description": "Get the current weather for a city.",
                  "parameters" : WT_parameters
                }
#
weather_tool  = { "type"    : 'function',          # function wrapper not
                  "function": WT_function          # needed for Anthropic
                }

# dictionary of all tools,
# used by the harness
ALL_TOOLS = {"get_weather": get_weather
            }


if __name__ == '__main__':

# say, the LLM asks the harness to execute a tool,
# the LLM would then return a JSON string containing
  tool_name = "get_weather"
  arguments = {"city": "Berlin", 
             "moon": True}
# arguments = {"city": "Berlin"}

# tool execution by the harness  
# ** unpacks a dictionary into keyword arguments
  result = ALL_TOOLS[tool_name](**arguments)

  print(result)
