Skip to content

FileSearchToolCall.file_search has empty results #1966

Open
@dominpm

Description

@dominpm

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Continuing from issue : #1938

The error seems to be fixed with openai==1.58.1 (it does not return a 400 error anymore). However if we capture the output of the stream with a custom class inheriting from AssistantEventHandler the results of the fileSearch tool are not available:

@override
def on_tool_call_done(self, tool_call: ToolCall):
    print(tool_call)

Of which the results are:

FileSearchToolCall(id='call_ID', file_search=FileSearch(ranking_options=FileSearchRankingOptions(ranker='default_2024_08_21', score_threshold=0.0), results=[]), type='file_search', index=0)

where following from openai.types.beta.threads.runs.file_search_tool_call.py it supposed to show:

class FileSearch(BaseModel):
    ranking_options: Optional[FileSearchRankingOptions] = None
    """The ranking options for the file search."""

    results: Optional[List[FileSearchResult]] = None
    """The results of the file search."""

when creating the run as follows:

  with client.beta.threads.runs.stream(
      thread_id=thread.id,
      assistant_id=ass_id,
      event_handler=CustomEventHandler(),
      include=["step_details.tool_calls[*].file_search.results[*].content"]
      ) as stream:
      # Wait for the stream to complete
      stream.until_done()

To Reproduce

  1. Run this with the id of an assistant connected to a vector store and the file search enabled (for simplicity do such thing through platform.openai.com)
from typing import override
from openai import AssistantEventHandler
from openai import OpenAI
from openai.types.beta.threads.runs.tool_call import ToolCall

client = OpenAI()
messages = [
    {
        "content": <QUESTION_TO_THE_ASSISTANT>,
    }
]

# Create a new thread for the assistant
thread = client.beta.threads.create()
client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content=messages[-1]["content"]
)


class CustomEventHandler(AssistantEventHandler):
    @override
    def on_tool_call_done(self, tool_call: ToolCall):
        print(tool_call)

# Stream the assistant's response
with client.beta.threads.runs.stream(
    thread_id=thread.id,
    assistant_id=<ASSISTANT_ID>,
    event_handler=CustomEventHandler(),
    include=["step_details.tool_calls[*].file_search.results[*].content"]
    ) as stream:
    # Wait for the stream to complete
    stream.until_done()

Code snippets

No response

OS

Windows

Python version

Python 3.11.10

Library version

openai 1.58.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions