Stevenic / alphawave

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

[Fix] Functions without parameters #12

Closed rmolinamir closed 1 year ago

rmolinamir commented 1 year ago

Hey @Stevenic, hope all is well! Was on a trip so it took me a while to work on this. I thought I was going to have more time to code while traveling, hehe.

The problem is that AlphaWave would attempt to repair the response after JSONResponseValidator returns a false negative after parsing the parameters due to this check parsed.length == 0, because parsed is an empty array if the parameters property is an empty object.

The most notable changes are the following:

  1. Changed the type of ChatCompletionFunction in packages/alphawave/src/types.ts. I decided to make the parameters property required based on the documentation of the function's parameters. Since the only PromptCompletionModel so far is the OpenAIModel I decided to go ahead, but it could backfire later.
  2. If the arguments are an empty object string '{}', the FunctionResponseValidator sets the content as null.
  3. If the message content is null in the JSONResponseValidator, then I'm returning a valid validation result to avoid looping during the response repair flow until the max attempts are reached. null was the most straightforward way to think of something that would make sense and be backward compatible, but there might be better solutions!

Let me know what you think.

rmolinamir commented 1 year ago

Referencing #11

Stevenic commented 1 year ago

Sorry for the @rmolinamir I've been out of town as well and then I got Covid. Starting to feel better so just now diving into this.

It's interesting that the docs show parameters as being required. I was going off the code in their node library which had it marked as optional. Makes sense to follow the docs though. Let me look through your PR. Again, sorry for the delay.

rmolinamir commented 1 year ago

Hey, @Stevenic! No need to apologize at all, glad to hear you're better now, COVID sucks. I was also puzzled a little bit when I read their docs and their TypeScript client but decided to go ahead with the docs as the source of truth, but I wonder now If their other clients like the Python SDK are the same. Do you need help with the other open issues?