Closed MikP0 closed 1 year ago
You should be able to narrow the type further by checking of the object has a key. I'm away from my computer at the moment but something like
if ("function_call" in completionMessage) {
}
We should probably export the types anyways though.
That's a great point, thanks @lino-levan ! I have created a Pull Request with the exports - if you're interested https://github.com/load1n9/openai/pull/25
When passing
function
andfunction_call
to thecreateChatCompletion()
we should expect to havefunction_call
object insidecontent
of a message, however it's impossible to determine whether the openAI response isAssistantCompletionMessage
orFunctionAwareAssistantCompletionMessage
as both share the samerole
:And it seems impossible to narrow the type from that point, so properties
name
fromAssistantCompletionMessage
and propertyfunction_call
fromFunctionAwareAssistantCompletionMessage
can't be accessed.Moreover, those types are not exported, so you can't really create a Type Guard yourself.