celestial_gull_73347
08/06/2025, 9:55 AMVaibhav (BAML 🐑)
08/06/2025, 2:34 PMcelestial_gull_73347
08/07/2025, 3:33 AMVaibhav (BAML 🐑)
08/07/2025, 4:24 AM// Define your tool schema
class GitTool {
// Specify the tool name
action "list_git_tags"
// Add any parameters your tool needs
tags Tag[]
}
class Tag {
name string
commit string
date string
}
class Message {
role "user" | "assistant" | "tool"
content string?
tool_calls GitTool?
}
class Reply {
action "reply"
message string
}
function ChatWithTools(messages: Message[]) -> GitTool | Reply {
client "openai/gpt-4o"
prompt #"
You are a helpful assistant that can use tools.
{{ ctx.output_format }}
{% for m in messages %}
{{ _.role(m.role) }}
{{ m.content }}
{{ m.tool_calls }}
{% endfor %}
"#
}
You can then use this in your code to handle the conversation flow.Vaibhav (BAML 🐑)
08/07/2025, 4:26 AMpython
from baml_client import b
from baml_client.types import Message, GitTool
def handle_git_tool(tool: GitTool):
# Implement your git tool logic here
return {"tags": [{"name": "v1.2.3", "commit": "abc123", "date": "2024-03-15T10:00:00Z"}]}
def main():
messages = []
while True:
user_input = input("You: ")
if user_input.lower() == 'exit':
break
# Add user message
messages.append({"role": "user", "content": user_input})
# Get assistant response
response = b.ChatWithTools(messages)
# If tool was called, handle it
if isinstance(response, GitTool):
tool_result = handle_git_tool(response)
messages.append({"role": "tool", "tool_calls": response}) messages.append({"role": "tool", "content": str(tool_result)})
else:
messages.append({"role": "assistant", "content": response})
print(f"Assistant: {response}")
if __name__ == "__main__":
main()celestial_gull_73347
08/07/2025, 8:39 AM