Use macros to automatically serialise Swift functions into OpenAI functions
A very recent feature added to the library are functions which are passed to the chat request as an array of ChatFunctionDeclaration. The problem is that it's very tedious to write those and then convert them back into real function calls. Maybe it would be possible to use macros to automatically serialise a Swift function into ChatFunctionDeclaration and then call a function automatically upon receiving a ChatFunctionCall.
Not sure if its possible and how would that work since I didn't use macros yet, but would be cool!
@pgorzelany , did you get this to work?
@Krivoblotsky , I am trying to do something like this, but the chat demo never returns the function, and then I found that this is because the choice.delta.role is wrong, and prints "assistant" when its actually a "function"
let message = Message(
id: partialChatResult.id,
role: choice.delta.role ?? .assistant,
content: messageText,
createdAt: Date(timeIntervalSince1970: TimeInterval(partialChatResult.created))
)
print("message role is \"\(message.role)\"")
@alelordelo , share your code?