mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Fixing ChatCompletionsClinet call (#3910)
* Fixing ChatCompletionsClinet call * Moving from json-object -> JsonSchemaFormat * Regex handling * Adding additionalProperties explicitly * fix: ensure additionalProperties is recursive --------- Co-authored-by: Greyson LaLonde <greyson.r.lalonde@gmail.com> Co-authored-by: Lorenze Jay <63378463+lorenzejay@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Any
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from crewai.utilities.agent_utils import is_context_length_exceeded
|
from crewai.utilities.agent_utils import is_context_length_exceeded
|
||||||
|
from crewai.utilities.converter import generate_model_description
|
||||||
from crewai.utilities.exceptions.context_window_exceeding_exception import (
|
from crewai.utilities.exceptions.context_window_exceeding_exception import (
|
||||||
LLMContextLengthExceededError,
|
LLMContextLengthExceededError,
|
||||||
)
|
)
|
||||||
@@ -26,6 +27,7 @@ try:
|
|||||||
from azure.ai.inference.models import (
|
from azure.ai.inference.models import (
|
||||||
ChatCompletions,
|
ChatCompletions,
|
||||||
ChatCompletionsToolCall,
|
ChatCompletionsToolCall,
|
||||||
|
JsonSchemaFormat,
|
||||||
StreamingChatCompletionsUpdate,
|
StreamingChatCompletionsUpdate,
|
||||||
)
|
)
|
||||||
from azure.core.credentials import (
|
from azure.core.credentials import (
|
||||||
@@ -278,13 +280,16 @@ class AzureCompletion(BaseLLM):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response_model and self.is_openai_model:
|
if response_model and self.is_openai_model:
|
||||||
params["response_format"] = {
|
model_description = generate_model_description(response_model)
|
||||||
"type": "json_schema",
|
json_schema_info = model_description["json_schema"]
|
||||||
"json_schema": {
|
json_schema_name = json_schema_info["name"]
|
||||||
"name": response_model.__name__,
|
|
||||||
"schema": response_model.model_json_schema(),
|
params["response_format"] = JsonSchemaFormat(
|
||||||
},
|
name=json_schema_name,
|
||||||
}
|
schema=json_schema_info["schema"],
|
||||||
|
description=f"Schema for {json_schema_name}",
|
||||||
|
strict=json_schema_info["strict"],
|
||||||
|
)
|
||||||
|
|
||||||
# Only include model parameter for non-Azure OpenAI endpoints
|
# Only include model parameter for non-Azure OpenAI endpoints
|
||||||
# Azure OpenAI endpoints have the deployment name in the URL
|
# Azure OpenAI endpoints have the deployment name in the URL
|
||||||
@@ -311,8 +316,8 @@ class AzureCompletion(BaseLLM):
|
|||||||
params["tool_choice"] = "auto"
|
params["tool_choice"] = "auto"
|
||||||
|
|
||||||
additional_params = self.additional_params
|
additional_params = self.additional_params
|
||||||
additional_drop_params = additional_params.get('additional_drop_params')
|
additional_drop_params = additional_params.get("additional_drop_params")
|
||||||
drop_params = additional_params.get('drop_params')
|
drop_params = additional_params.get("drop_params")
|
||||||
|
|
||||||
if drop_params and isinstance(additional_drop_params, list):
|
if drop_params and isinstance(additional_drop_params, list):
|
||||||
for drop_param in additional_drop_params:
|
for drop_param in additional_drop_params:
|
||||||
|
|||||||
Reference in New Issue
Block a user