dylanshine / openai-kit

A community Swift package used to interact with the OpenAI API
https://platform.openai.com/docs/api-reference
MIT License
692 stars 107 forks source link

Expose content of Chat.Message #32

Closed sulsanaul closed 1 year ago

sulsanaul commented 1 year ago

This directly exposes the content string of the Message object, which makes handling the response from a call to the chat endpoint easier. Alternatively, Message could be a struct instead of an enum? Lmk what you think.

Example usage

let response = try await openAIClient.chats.create(
    model: Model.GPT3.gpt3_5Turbo,
    messages: [userMessage]
)

let message: Chat.Message = response.choices.first!.message 
// .assistant(content: "This is message content.")

let content: String = message.content 
// This is message content.
dylanshine commented 1 year ago

This is a good change, thank you for your contribution!

sulsanaul commented 1 year ago

yw – appreciate you making this package 🙂