这是indexloc提供的服务,不要输入任何密码
Skip to content

add ToolCallFileSearch class to hold the file search results #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

nobodyiam
Copy link
Contributor

What's the purpose of this PR

The assistant streaming feature may encounter a JSON parser exception when parsing RunStepDelta for the file search tool.

        switch (result.getEvent()) { // result is AssistantSSE
            case THREAD_RUN_STEP_DELTA:
                RunStepDelta runStep = objectMapper.readValue(data, RunStepDelta.class);

The error occurred:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: (String)"{"id":"step_xxx","object":"thread.run.step.delta","delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"id":"call_xxx","type":"file_search","file_search":{"ranking_options":{"ranker":"default_2024_08_21","score_threshold":0.0},"results":[]}}]}}}"; line: 1, column: 233] (through reference chain: com.theokanning.openai.assistants.run_step.RunStepDelta["delta"]->com.theokanning.openai.assistants.run_step.Delta["step_details"]->com.theokanning.openai.assistants.run_step.StepDetails["tool_calls"]->java.util.ArrayList[0]->com.theokanning.openai.assistants.run.ToolCall["file_search"]->java.util.LinkedHashMap["ranking_options"])

The main issue is that the file search in ToolCall.java is defined as a map while it should be an object.

/**
* For now, this is always going to be an empty object.
*/
@JsonProperty("file_search")
Map<String, String> fileSearch;

Sample data for thread.run.step.delta:

{
    "id": "step_xxx",
    "object": "thread.run.step.delta",
    "delta": {
        "step_details": {
            "type": "tool_calls",
            "tool_calls": [
                {
                    "index": 0,
                    "id": "call_xxx",
                    "type": "file_search",
                    "file_search": {
                        "ranking_options": {
                            "ranker": "default_2024_08_21",
                            "score_threshold": 0
                        },
                        "results": []
                    }
                }
            ]
        }
    }
}

Sample data for thread.run.step:

{
    "id": "step_xxx",
    "object": "thread.run.step",
    "created_at": 1728264590,
    "run_id": "run_xxx",
    "assistant_id": "asst_xxx",
    "thread_id": "thread_xxx",
    "type": "tool_calls",
    "status": "completed",
    "cancelled_at": null,
    "completed_at": 1728264592,
    "expires_at": 1728265189,
    "failed_at": null,
    "last_error": null,
    "step_details": {
        "type": "tool_calls",
        "tool_calls": [
            {
                "id": "call_xxx",
                "type": "file_search",
                "file_search": {
                    "ranking_options": {
                        "ranker": "default_2024_08_21",
                        "score_threshold": 0
                    },
                    "results": [
                        {
                            "file_id": "file-xxx",
                            "file_name": "xxx.md",
                            "score": 0.36565948875785104
                        },
                        {
                            "file_id": "file-xxx",
                            "file_name": "yyy.md",
                            "score": 0.03818400468604836
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "prompt_tokens": 765,
        "completion_tokens": 30,
        "total_tokens": 795
    }
}

This pull request adds the missing class definition based on the documentation and the Python reference implementation to resolve the issue.

Which issue(s) this PR fixes:

Fixes #61

Brief changelog

  • Added the ToolCallFileSearch, ToolCallFileSearchResult and ToolCallFileSearchResultContent classes

@Lambdua
Copy link
Owner

Lambdua commented Oct 8, 2024

thanks

@nobodyiam nobodyiam deleted the fix-tool-call-file-search-issue branch February 17, 2025 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FileSearchTool deserialization exception: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT)
2 participants