mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 07:13:00 +00:00
fix: resolve mypy errors from openai 2.x type changes
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user