fix: resolve mypy errors from openai 2.x type changes

This commit is contained in:
Greyson LaLonde
2026-04-04 23:00:49 +08:00
parent 6e7afb732f
commit 055d1469a0
2 changed files with 19 additions and 7 deletions

View File

@@ -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:

View File

@@ -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