Skip to content

Commit

Permalink
get openai client if it's not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Aug 15, 2024
1 parent 035a43c commit b428388
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion agency_swarm/util/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from typing import Callable
from pydantic import Field
from agency_swarm.tools import BaseTool
from agency_swarm.util.oai import get_openai_client

class Validator(BaseTool):
"""
Validate if an attribute is correct and if not,
return a new value with an error message
"""

is_valid: bool = Field(
default=True,
description="Whether the attribute is valid based on the requirements",
Expand Down Expand Up @@ -65,6 +65,9 @@ class User(BaseTool):
temperature (float): The temperature to use for the LLM (default: 0)
openai_client (OpenAI): The OpenAI client to use (default: None)
"""
if client is None:
client = get_openai_client()

def llm(v: str) -> str:
resp = client.beta.chat.completions.parse(
response_format=Validator,
Expand Down

0 comments on commit b428388

Please sign in to comment.