-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcot-agents-batch.py
More file actions
73 lines (64 loc) · 2.44 KB
/
cot-agents-batch.py
File metadata and controls
73 lines (64 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from praisonaiagents import Agent, Task, PraisonAIAgents
from praisonaiagents.tools import cot_save, cot_upload_to_huggingface
# Create a COT agent for generating and managing chain of thought solutions
cot_agent = Agent(
name="COTGenerator",
role="Chain of Thought Specialist",
goal="Generate and manage chain of thought solutions for Q&A pairs",
backstory="Expert in breaking down problems and generating detailed solution steps",
tools=[cot_save],
llm="gpt-4o-mini", # Using recommended model
)
save_to_huggingface_agent = Agent(
name="SaveToHuggingface",
role="Save to Huggingface",
goal="Save the generated chain of thought solutions to a Huggingface dataset",
backstory="Expert in saving data to Huggingface",
tools=[cot_upload_to_huggingface],
llm="gpt-4o-mini", # Using recommended model
)
# Define question-answer pairs to process in batches
qa_pairs = [
{
"question": "What is the sum of numbers from 1 to 10?",
"answer": "55"
},
{
"question": "Calculate the area of a circle with radius 5",
"answer": "78.54"
}
]
# Process qa_pairs in batches
batch_size = 2
for i in range(0, len(qa_pairs), batch_size):
batch_qa = qa_pairs[i:i + batch_size]
# Create task for current batch
qa_text = "\n".join(
f"- Q: {qa['question']}\n A: {qa['answer']}"
for qa in batch_qa
)
cot_task = Task(
description=(
"For each Q&A pair:\n"
"1. Use the tool cot_save to generate a chain of thought solution\n"
"2. Save to CSV file with filename 'cot_dataset.csv'\n\n"
f"Q&A Pairs:\n{qa_text}"
),
expected_output="Chain of thought solutions saved to CSV",
agent=cot_agent,
name=f"generate_cot_solutions_batch_{i//batch_size + 1}"
)
save_to_huggingface_task = Task(
description="Save to Huggingface dataset at mervinpraison/cot-dataset , cot_dataset.csv",
expected_output="Chain of thought solutions saved to Huggingface",
agent=save_to_huggingface_agent,
name=f"save_to_huggingface_batch_{i//batch_size + 1}"
)
# Initialize and run the agent
agents = PraisonAIAgents(
agents=[cot_agent, save_to_huggingface_agent],
tasks=[cot_task, save_to_huggingface_task]
)
# Execute current batch
result = agents.start()
print(f"\nBatch {i//batch_size + 1} completed. Solutions appended to CSV file.")