load1n9 / openai

Unofficial Deno wrapper for the Open Ai api
MIT License
73 stars 23 forks source link

Export ChatCompletionMessage types #30

Closed alexewerlof closed 1 year ago

alexewerlof commented 1 year ago

Currently only ChatCompletionMessage is exported.

I need its variations to write guard type guards:

  1. Would you be open to a PR that addresses that?
  2. Would you like me to also submit the guard functions (they help when going through the array of messages trying to identify what type each message has. e.g. a function_call and regular content both can have role: 'assistant, so one needs to look inside the object)?
lino-levan commented 1 year ago

Would be more than willing to accept the first one, the second one would be interesting, but I'd need to see more. I'd open these as two seperate PRs.

alexewerlof commented 1 year ago

25 did 1. But it's not released yet. Could we release it please?

I can propose a PR for the second one but it's going to add a bit of code for type checking the JSON. I have created JTY for cases like this, but I don't want to add a dependency just for that. So before spending further time into a PR, I have a few questions:

  1. Is it valuable to add type-guards to this lib? My use case is that as I go through the array of messages, I'd like to know which type each element is, and using type guards in Deno makes it easier to work in an IDE for example. Not sure how many others need this functionality.
  2. If the answer is positive, do you have a special preference for how to check the shape of the JSON elements? I am new to Deno (but not new to TS/JS). I can't see a similar functionality in STD which makes me think we either have to write the basic type checking functionality in this module or use a dependency.
alexewerlof commented 1 year ago

Closing this as it duplicates #24.

Opened a new issue for the type guard part: #32