Skip to content

[BUG] Unknown parameter: 'attachments[0].tools[0].file_search' when trying to attach a file to a message for the FileSearch tool. #552

@MickaelBNeron

Description

@MickaelBNeron

Describe the bug

My code (below) works for CodeInterpreter attachments, but gives the Unknown parameter: 'attachments[0].tools[0].file_search' error for FileSearch attachments. That should be incredibly easy to reproduce. My assistant is configured with both File Search and Code Interpreter enabled.

public async Task PostChat(
    string threadId,
    string model,
    string? instructions,
    bool webSearch,
    string prompt,
    List<(string FileName, Stream Stream)> fileSearch,
    List<(string FileName, Stream Stream)> codeInterpreter)
{
    var uploadFileSearchTasks = fileSearch.Select(async attachment => (
        File: await _fileClient.UploadFileAsync(attachment.Stream, attachment.FileName, FileUploadPurpose.Assistants),
        Tool: new List<ToolDefinition>() { ToolDefinition.CreateFileSearch() }
    ));

    var uploadCodeInterpreterTasks = codeInterpreter.Select(async attachment => (
        File: await _fileClient.UploadFileAsync(attachment.Stream, attachment.FileName, FileUploadPurpose.Assistants),
        Tool: new List<ToolDefinition>() { ToolDefinition.CreateCodeInterpreter() }
    ));

    var tasks = await Task.WhenAll(uploadFileSearchTasks.Concat(uploadCodeInterpreterTasks));

    var attachments = tasks.Select(x => new MessageCreationAttachment(x.File.Value.Id, x.Tool));

    var message = await _assistantClient.CreateMessageAsync(
        threadId,
        MessageRole.User,
        new[] {
            MessageContent.FromText(prompt.ToString()),
        },
        new MessageCreationOptions() {
            Attachments = new List<MessageCreationAttachment>(attachments),
        });

    var updates = _assistantClient.CreateRunStreamingAsync(threadId, _assistantId);
}

Steps to reproduce

  1. Upload a file:

var fileId = await openAIFileClient.UploadFileAsync(stream, fileName FileUploadPurpose.Assistants);

  1. Create an attachment with the Id of the uploaded file and the FileSearch tool:

var attachment = new MessageCreationAttachment(fileId, new List<ToolDefinition>() { ToolDefinition.CreateFileSearch() });

  1. Send a message with that attachment:
var message = await _assistantClient.CreateMessageAsync(
    threadId,
    MessageRole.User,
    new[] {
        MessageContent.FromText(message),
    },
    new MessageCreationOptions() {
        Attachments = new List<MessageCreationAttachment>(attachments),
    });

Code snippets

public async Task PostChat(
    string threadId,
    string model,
    string? instructions,
    bool webSearch,
    string prompt,
    List<(string FileName, Stream Stream)> fileSearch,
    List<(string FileName, Stream Stream)> codeInterpreter)
{
    var uploadFileSearchTasks = fileSearch.Select(async attachment => (
        File: await _fileClient.UploadFileAsync(attachment.Stream, attachment.FileName, FileUploadPurpose.Assistants),
        Tool: new List<ToolDefinition>() { ToolDefinition.CreateFileSearch() }
    ));

    var uploadCodeInterpreterTasks = codeInterpreter.Select(async attachment => (
        File: await _fileClient.UploadFileAsync(attachment.Stream, attachment.FileName, FileUploadPurpose.Assistants),
        Tool: new List<ToolDefinition>() { ToolDefinition.CreateCodeInterpreter() }
    ));

    var tasks = await Task.WhenAll(uploadFileSearchTasks.Concat(uploadCodeInterpreterTasks));

    var attachments = tasks.Select(x => new MessageCreationAttachment(x.File.Value.Id, x.Tool));

    var message = await _assistantClient.CreateMessageAsync(
        threadId,
        MessageRole.User,
        new[] {
            MessageContent.FromText(prompt.ToString()),
        },
        new MessageCreationOptions() {
            Attachments = new List<MessageCreationAttachment>(attachments),
        });

    var updates = _assistantClient.CreateRunStreamingAsync(threadId, _assistantId);
}

OS

Windows

.NET version

8.0

Library version

2.2.0

Metadata

Metadata

Assignees

Labels

bugCategory: Something isn't working and appears to be a defect in the client library.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions