Views
No views yet
exec, eval and compile (see full list in Quickstart below). This enables the model to implement custom complex logic with conditionals and synchronous pipelines (using the output of one function in the next function's arguments) which would not be possible with the current JSON-based function calling methods (as far as we know).1import json
2from typing import Any, Dict, List
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5model_name = "driaforall/Dria-Agent-a-3B"
6model = AutoModelForCausalLM.from_pretrained(
7 model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True
8)
9tokenizer = AutoTokenizer.from_pretrained(model_name)
10
11# Please use our provided prompt for best performance
12SYSTEM_PROMPT = """
13You are an expert AI assistant that specializes in providing Python code to solve the task/problem at hand provided by the user.
14
15You can use Python code freely, including the following available functions:
16
17<|functions_schema|>
18{{functions_schema}}
19<|end_functions_schema|>
20
21The following dangerous builtins are restricted for security:
22- exec
23- eval
24- execfile
25- compile
26- importlib
27- input
28- exit
29
30Think step by step and provide your reasoning, outside of the function calls.
31You can write Python code and use the available functions. Provide all your python code in a SINGLE markdown code block like the following:
32
33```python
34result = example_function(arg1, "string")
35result2 = example_function2(result, arg2)
36```
37
38DO NOT use print() statements AT ALL. Avoid mutating variables whenever possible.
39""".strip()
40
41
42get_sample_data = """
43def check_availability(day: str, start_time: str, end_time: str) -> bool:
44 \"\"\"
45 Check if a time slot is available on a given day.
46
47 Args:
48 - day: The day to check in YYYY-MM-DD format
49 - start_time: Start time in HH:MM format
50 - end_time: End time in HH:MM format
51
52 Returns:
53 - True if slot is available, False otherwise
54 \"\"\"
55 pass
56
57def make_appointment(day: str, start_time: str, end_time: str) -> dict:
58 \"\"\"
59 Make an appointment for a given time slot.
60
61 Args:
62 - day: The day to make appointment in YYYY-MM-DD format
63 - start_time: Start time in HH:MM format
64 - end_time: End time in HH:MM format
65 - title: The title of the appointment
66
67 Returns:
68 - A dictionary with the appointment details and if it's made or not.
69 dict keys:
70 - day (str): The day the appointment is on, in YYYY-MM-DD format
71 - start_time (str): Start time in HH:MM format
72 - end_time (str): End time in HH:MM format
73 - appointment_made (bool): Whether the appointment is successfully made or not.
74 \"\"\"
75 pass
76
77def add_to_reminders(reminder_text: str) -> bool:
78 \"\"\"
79 Add a text to reminders.
80
81 Args:
82 - reminder_text: The text to add to reminders
83
84 Returns:
85 - Whether the reminder was successfully created or not.
86 \"\"\"
87 pass
88"""
89
90# Helper function to create the system prompt for our model
91def format_prompt(tools: str):
92 return SYSTEM_PROMPT.format(functions_schema=tools)
93
94system_prompt = SYSTEM_PROMPT.replace("{{functions_schema}}", get_sample_data)
95
96USER_QUERY = """
97Can you check if I have tomorrow 10:00-12:00 available and make an appointment for a meeting
98with my thesis supervisor if so? If you made the appointment, please add it to my reminders.
99"""
100
101messages = [
102 {"role": "system", "content": system_prompt},
103 {"role": "user", "content": USER_QUERY},
104]
105
106text = tokenizer.apply_chat_template(
107 messages,
108 tokenize=False,
109 add_generation_prompt=True
110)
111model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
112
113generated_ids = model.generate(
114 **model_inputs,
115 max_new_tokens=2048
116)
117generated_ids = [
118 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
119]
120
121response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
122print(response)# Get today's date and calculate tomorrow's date
from datetime import datetime, timedelta
today = datetime.now()
tomorrow = (today + timedelta(days=1)).strftime("%Y-%m-%d")
# Define the time slots
start_time = "10:00"
end_time = "12:00"
# Check availability first
is_available = check_availability(tomorrow, start_time, end_time)
# Only proceed with making the appointment if it's available
appointment_result = (
make_appointment(
day=tomorrow,
start_time=start_time,
end_time=end_time,
title="Meeting with Thesis Supervisor"
)
if is_available
else {"appointment_made": False}
)
# Add to reminders only if the appointment was made
if appointment_result["appointment_made"]:
add_to_reminders("Meeting with Thesis Supervisor scheduled for 10:00 AM tomorrow")
```
This code will:
1. Calculate tomorrow's date in YYYY-MM-DD format
2. Check if the 10:00-12:00 slot is available
3. If available, make the appointment with the specified details
4. If the appointment is successfully made, add a reminder to the system
The code handles all error cases implicitly through the boolean returns of the functions. If any step fails, the subsequent steps won't execute, preventing partial or invalid appointments.| Metric | Qwen/Qwen2.5-3B-Instruct | Dria-Agent-a-3B | gpt-4o-2024-11-20 (Prompt) |
|---|---|---|---|
| Non-Live Simple AST | 75.50% | 75.08% | 79.42% |
| Non-Live Multiple AST | 90.00% | 93.00% | 95.50% |
| Non-Live Parallel AST | 80.00% | 85.00% | 94.00% |
| Non-Live Parallel Multiple AST | 78.50% | 79.00% | 83.50% |
| Non-Live Simple Exec | 82.07% | 87.57% | 100.00% |
| Non-Live Multiple Exec | 86.00% | 85.14% | 94.00% |
| Non-Live Parallel Exec | 82.00% | 90.00% | 86.00% |
| Non-Live Parallel Multiple Exec | 80.00% | 88.00% | 77.50% |
| Live Simple AST | 68.22% | 70.16% | 83.72% |
| Live Multiple AST | 66.00% | 67.14% | 79.77% |
| Live Parallel AST | 62.50% | 50.00% | 87.50% |
| Live Parallel Multiple AST | 66.67% | 70.83% | 70.83% |
| Relevance Detection | 88.89% | 100.00% | 83.33% |
| Benchmark Name | Qwen2.5-Coder-3B-Instruct | Dria-Agent-α-3B |
|---|---|---|
| MMLU-Pro | 35.2 (Self Reported) | 29.8* |
| DPAB (Pythonic, Strict) | 26 | 72 |
@misc{Dria-Agent-a,
url={https://huggingface.co/blog/andthattoo/dria-agent-a},
title={Dria-Agent-a},
author={"andthattoo", "Atakan Tekparmak"}
}