diff --git a/lib/crewai/src/crewai/llms/providers/openai/completion.py b/lib/crewai/src/crewai/llms/providers/openai/completion.py index 804ce2927..89edf7ab3 100644 --- a/lib/crewai/src/crewai/llms/providers/openai/completion.py +++ b/lib/crewai/src/crewai/llms/providers/openai/completion.py @@ -10,7 +10,11 @@ from typing import TYPE_CHECKING, Any, ClassVar, Literal, TypedDict import httpx from openai import APIConnectionError, AsyncOpenAI, NotFoundError, OpenAI, Stream from openai.lib.streaming.chat import ChatCompletionStream -from openai.types.chat import ChatCompletion, ChatCompletionChunk +from openai.types.chat import ( + ChatCompletion, + ChatCompletionChunk, + ChatCompletionMessageFunctionToolCall, +) from openai.types.chat.chat_completion import Choice from openai.types.chat.chat_completion_chunk import ChoiceDelta from openai.types.responses import Response @@ -1359,11 +1363,11 @@ class OpenAICompletion(BaseLLM): file_results: list[FileSearchResultItem] = ( [ FileSearchResultItem( - file_id=r.file_id, # type: ignore[union-attr] - filename=r.filename, # type: ignore[union-attr] - text=r.text, # type: ignore[union-attr] - score=r.score, # type: ignore[union-attr] - attributes=r.attributes, # type: ignore[union-attr] + file_id=r.file_id, + filename=r.filename, + text=r.text, + score=r.score, + attributes=r.attributes, ) for r in item.results # type: ignore[union-attr] ] @@ -1625,6 +1629,8 @@ class OpenAICompletion(BaseLLM): # If there are tool_calls and available_functions, execute the tools if message.tool_calls and available_functions: tool_call = message.tool_calls[0] + if not isinstance(tool_call, ChatCompletionMessageFunctionToolCall): + return message.content function_name = tool_call.function.name try: @@ -2009,7 +2015,13 @@ class OpenAICompletion(BaseLLM): # If there are tool_calls and available_functions, execute the tools if message.tool_calls and available_functions: + from openai.types.chat.chat_completion_message_function_tool_call import ( + ChatCompletionMessageFunctionToolCall, + ) + tool_call = message.tool_calls[0] + if not isinstance(tool_call, ChatCompletionMessageFunctionToolCall): + return message.content function_name = tool_call.function.name try: diff --git a/lib/crewai/src/crewai/utilities/internal_instructor.py b/lib/crewai/src/crewai/utilities/internal_instructor.py index 06a95d234..86517c1ce 100644 --- a/lib/crewai/src/crewai/utilities/internal_instructor.py +++ b/lib/crewai/src/crewai/utilities/internal_instructor.py @@ -60,7 +60,7 @@ class InternalInstructor(Generic[T]): self.llm = llm or (agent.function_calling_llm or agent.llm if agent else None) with suppress_warnings(): - import instructor # type: ignore[import-untyped] + import instructor if ( self.llm is not None