Json object modeled class and inheritance when using Structured Outputs #300
Unanswered
HunterProduction
asked this question in
Q&A
Replies: 1 comment 1 reply
-
An update with the work I proceeded today. The solution I found for now is to make the properties in BaseStructuredResponse abstract too. The child class simply implement them with an override without changing anything, just to be sure the properties are explicitely declared inside the class used for the Structured Output: public class CodeResponse : BaseStructuredResponse
{
public override string RawResponse { get; protected set; }
public override string Answer { get; protected set; }
public override IReadOnlyList<string> ToolCallResults { get; protected set; }
/// <summary>
/// Part of the response that contains any code provided by the chat response.
/// </summary>
[JsonProperty("code_block")]
[Description("Part of the response that contains any code provided by the chat response.")]
public string CodeBlock { get; private set; }
} It's not the most elegant or scalable approach but for now it works. Do you have any answer on why the previous solution wasn't working properly? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
Thanks for the splendid work on this repo. I was trying to upgrade my code to implement Structured Outputs from chat completions.
I created one class called BaseStructuredResponse which I want to be used as a base for other possible wanted response formats in future
Then I wrote for example a child class CodeResponse which adds another field code_block:
In my components, I wrote a generic method to perform chat completion:
The problem is that the chat response doesn't seem to be aware of the Json properties declared in the base class, but populates only the CodeBlock field. I'm quite sure of this because I tried to write the Answer field directly in the CodeResponse class, and the chat completion splitted the two sections correctly.
Is this inheritance architecture actually supported? Or do I have to give up on this road?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions