Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let Devid use o1 model #176

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions agency_swarm/agents/Devid/tools/FileWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

history = [
{
"role": "system",
"role": "user",
"content": "As a top-tier software engineer focused on developing programs incrementally, you are entrusted with the creation or modification of files based on user requirements. It's imperative to operate under the assumption that all necessary dependencies are pre-installed and accessible, and the file in question will be deployed in an appropriate environment. Furthermore, it is presumed that all other modules or files upon which this file relies are accurate and error-free. Your output should be encapsulated within a code block, without specifying the programming language. Prior to embarking on the coding process, you must outline a methodical, step-by-step plan to precisely fulfill the requirements — no more, no less. It is crucial to ensure that the final code block is a complete file, without any truncation. This file should embody a flawless, fully operational program, inclusive of all requisite imports and functions, devoid of any placeholders, unless specified otherwise by the user.",
},
]
Expand Down Expand Up @@ -58,7 +58,7 @@ class FileWriter(BaseTool):
)

class ToolConfig:
one_call_at_a_time = True
one_call_at_a_time: bool = True

def run(self):
client = get_openai_client()
Expand All @@ -84,7 +84,7 @@ def run(self):
message += f"\nDocumentation: {self.documentation}"

if self.mode == "modify":
message += f"\nThe existing file content is as follows:"
message += "\nThe existing file content is as follows:"

try:
with open(self.file_path, "r") as file:
Expand All @@ -109,14 +109,14 @@ def run(self):
if self.mode == "modify":
resp = client.chat.completions.create(
messages=messages,
model="gpt-4o",
model="o1-mini",
temperature=0,
prediction={"type": "content", "content": file_content},
)
else:
resp = client.chat.completions.create(
messages=messages,
model="gpt-4o",
model="o1-mini",
temperature=0,
)

Expand Down Expand Up @@ -144,7 +144,7 @@ def run(self):
messages.append(
{
"role": "user",
"content": f"Error: Could not find the code block in the response. Please try again.",
"content": "Error: Could not find the code block in the response. Please try again.",
}
)

Expand Down Expand Up @@ -181,8 +181,7 @@ def validate_content(self, v):
llm_validator(
statement="Check if the code is bug-free. Code should be considered in isolation, with the understanding that it is part of a larger, fully developed program that strictly adheres to these standards of completeness and correctness. All files, elements, components, functions, or modules referenced within this snippet are assumed to exist in other parts of the project and are also devoid of any errors, ensuring a cohesive and error-free integration across the entire software solution. Certain placeholders may be present.",
client=client,
model="gpt-4o",
temperature=0,
model="o1-mini",
allow_override=False,
)(v)

Expand Down
24 changes: 12 additions & 12 deletions agency_swarm/util/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Validator(BaseModel):
Validate if an attribute is correct and if not,
return a new value with an error message
"""

reason: str = Field(
...,
description="Step-by-step reasoning why the attribute could be valid or not with a conclussion at the end.",
Expand Down Expand Up @@ -69,20 +68,21 @@ class User(BaseTool):
client = get_openai_client()

def llm(v: str) -> str:
system_content = "You are a world class validation model, capable to determine if the following value is valid or not for a given statement. Before providing a response, you must think step by step about the validation."
user_content = f"Does `{v}` follow the rules: {statement}"
messages = [
{"role": "system", "content": system_content},
{"role": "user", "content": user_content}
]

if model.startswith("o1"):
messages = [{"role": "user", "content": system_content + "\n\n" + user_content}]

resp = client.beta.chat.completions.parse(
response_format=Validator,
messages=[
{
"role": "system",
"content": "You are a world class validation model, capable to determine if the following value is valid or not for a given statement. Before providing a response, you must think step by step about the validation.",
},
{
"role": "user",
"content": f"Does `{v}` follow the rules: {statement}",
},
],
messages=messages,
model=model,
temperature=temperature,
temperature=None if model.startswith("o1") else temperature,
)

if resp.choices[0].message.refusal:
Expand Down
Loading