Skip to content
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

AssistantDeltaObject deserialization error if Annotation contains file citations #87

Closed
dotchcz opened this issue Apr 10, 2024 · 4 comments
Assignees

Comments

@dotchcz
Copy link

dotchcz commented Apr 10, 2024

AssistantDeltaObject deserialization error if Annotation contains file citations. For OpenAi Assistants with Retrieval property set on and using files, there is an issue during deserialization delta object AssistantDeltaObject. I have a fix, pull request on its way.

@higty higty self-assigned this Apr 10, 2024
@higty
Copy link
Owner

higty commented Apr 10, 2024

@dotchcz
Hi. Thank you for reporting bug and provide bug fix.
I'll patch it if you send me it.

regards.

@dotchcz
Copy link
Author

dotchcz commented Apr 10, 2024

@higty
Hi, thank you for you quick reply! I cannot push any change to any branch :) so the class is attached, if it's okay for you.

@dotchcz
Copy link
Author

dotchcz commented Apr 10, 2024

using System.Text;
using Newtonsoft.Json;

namespace HigLabo.OpenAI
{
public class AssistantDeltaObject
{
public string Id { get; set; } = "";
public string Object { get; set; } = "";
public AssistantDelta Delta { get; set; } = new();

    public class AssistantDelta
    {
        public string Role { get; set; } = "";
        public List<Message> Content { get; set; } = new();
        public List<string>? FileId { get; set; }
        public RunStep? Step_Details { get; set; } 
    }
    public class Message
    {
        public int Index { get; set; }
        public string Type { get; set; } = "";
        public MessageText Text { get; set; } = new();
    }
    public class MessageText
    {
        public string Value { get; set; } = "";
        public Annotation[]? Annotations { get; set; }

        public override string ToString()
        {
            return this.Value;
        }
    }

    public class Annotation
    {
        public int Index { get; set; }
        public string Type { get; set; } = "";
        public string Text { get; set; } = "";
        public string Start_Index { get; set; } = "";
        public string End_Index { get; set; } = "";
        public FileCitation File_Citation { get; set; } = new();
    }

    public class FileCitation
    {
        public string File_Id { get; set; } = "";
        public string Quote { get; set; } = "";
    }

    public class RunStep
    {
        public string Type { get; set; } = "";
        public MessageCreation? Message_Creation { get; set; }
        public List<ToolCall>? Tool_Calls { get; set; }
    }
    public class MessageCreation
    {
        public string Message_Id { get; set; } = "";

    }
    public class ToolCall
    {
        public int Index { get; set; }
        public string Id { get; set; } = "";
        public string Type { get; set; } = "";
        public CodeInterpreter? Code_Interpreter { get; set; } 
    }
    public class CodeInterpreter
    {
        public string Input { get; set; } = "";
        public List<string>? Outputs { get; set; }
    }

    public override string ToString()
    {
        return this.Delta?.Content.FirstOrDefault()?.Text.Value ?? this.Id;
    }
}

}

@higty
Copy link
Owner

higty commented Apr 12, 2024

I fixed it just now.
And I upload it to Nuget as HigLabo.OpenAI 8.5.0.0.

Thank you for your feedback!

@higty higty closed this as completed Apr 12, 2024
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

No branches or pull requests

2 participants