From cc0a493c869bc64ec5438643edc574d9d04fb733 Mon Sep 17 00:00:00 2001 From: Nick Bobrowski <39348559+bonk1t@users.noreply.github.com> Date: Tue, 8 Oct 2024 00:42:21 +0100 Subject: [PATCH] Minor fixes --- agency_swarm/agents/Devid/tools/FileWriter.py | 2 +- agency_swarm/util/validators.py | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/agency_swarm/agents/Devid/tools/FileWriter.py b/agency_swarm/agents/Devid/tools/FileWriter.py index 92cf2853..633c251e 100644 --- a/agency_swarm/agents/Devid/tools/FileWriter.py +++ b/agency_swarm/agents/Devid/tools/FileWriter.py @@ -2,7 +2,7 @@ import os -from instructor import llm_validator +from agency_swarm.util.validators import llm_validator from agency_swarm import get_openai_client from agency_swarm.tools import BaseTool diff --git a/agency_swarm/util/validators.py b/agency_swarm/util/validators.py index 85ce7b4e..3f9d7627 100644 --- a/agency_swarm/util/validators.py +++ b/agency_swarm/util/validators.py @@ -8,7 +8,7 @@ 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.") + reason: str = Field(..., description="Step-by-step reasoning why the attribute could be valid or not with a conclusion at the end.") is_valid: bool = Field(..., description="Whether the attribute is valid based on the requirements.") fixed_value: str = Field(..., description="If the attribute is not valid, suggest a new value for the attribute. Otherwise, leave it empty.") @@ -56,20 +56,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: