Stevenic / alphawave

AlphaWave is a very opinionated client for interfacing with Large Language Models.
MIT License
98 stars 9 forks source link

Use JSONValidator with a class #15

Open Godrules500 opened 9 months ago

Godrules500 commented 9 months ago

Is it possible to use a JSON validator with a class? So instead of manually typing out the properties and required values, and adding "return using this json structure", we'd use a class. That way it's all in one spot? Thanks again!

        const validator = new JSONResponseValidator({
            type: 'object',
            properties: {
                answer: { type: 'string' },
                sentiment: {
                    type: 'string',
                    enum: ['positive', 'neutral', 'negative']
                }
            },
            required: ['answer', 'sentiment']
        });
                new SystemMessage(
                    [
                        `Return your answer using this JSON structure:`,
                        `{"answer":"<answer>","sentiment":"positive|neutral|negative"}`
                    ].join('\n')
Stevenic commented 9 months ago

I've been thinking about that... Generating the JSON Scheme is a bit of a Burdon. There are projects out there that will convert typescript interfaces to JSON Schema so it seems like it would be possible.

Not sure when I'll have time to dig into that TBH as I'm swamped in my day job but if someone to add that feature I would definitely take the PR. I'll keep this post open and mark it as an enhancement.

0xifis commented 1 month ago

Hey guys, I think this is something that is bugging me as well.

@Godrules500 @Stevenic , let me know if either of you made any progress on this since. If not, I will send something through in the next couple weeks