This commit is contained in:
Brandon Hancock
2025-02-04 11:18:17 -05:00
parent ea4feb7b2e
commit fc2bcc292f

View File

@@ -183,7 +183,6 @@ class LLM:
tools: Optional[List[dict]] = None, tools: Optional[List[dict]] = None,
callbacks: Optional[List[Any]] = None, callbacks: Optional[List[Any]] = None,
available_functions: Optional[Dict[str, Any]] = None, available_functions: Optional[Dict[str, Any]] = None,
response_format: Optional[BaseModel] = None,
) -> str: ) -> str:
""" """
High-level LLM call method that handles: High-level LLM call method that handles:
@@ -280,7 +279,8 @@ class LLM:
params = {k: v for k, v in params.items() if v is not None} params = {k: v for k, v in params.items() if v is not None}
# --- Direct structured response if no tools are provided. # --- Direct structured response if no tools are provided.
if response_format is not None and (tools is None or len(tools) == 0): if self.response_format is not None and (tools is None or len(tools) == 0):
print("Direct structured response")
try: try:
# Cast messages to required type and remove model param # Cast messages to required type and remove model param
params["messages"] = cast( params["messages"] = cast(
@@ -297,6 +297,7 @@ class LLM:
# --- Standard flow with potential tool calls. # --- Standard flow with potential tool calls.
try: try:
print("NOT DIRECT STRUCTURED RESPONSE")
response = litellm.completion(**params) response = litellm.completion(**params)
response_message = cast(Choices, cast(ModelResponse, response).choices)[ response_message = cast(Choices, cast(ModelResponse, response).choices)[
0 0
@@ -341,7 +342,7 @@ class LLM:
return text_response return text_response
# If a structured response is requested, perform a secondary call using the tool result. # If a structured response is requested, perform a secondary call using the tool result.
if response_format is not None: if self.response_format is not None:
new_params = dict(params) new_params = dict(params)
# Cast tool result message to required type # Cast tool result message to required type
new_params["messages"] = cast( new_params["messages"] = cast(