adamrushy / OpenAISwift

This is a wrapper library around the ChatGPT and OpenAI HTTP API
MIT License
1.6k stars 242 forks source link

Add explicit codable implementation to ChatMessage and new OpenAIEndpointModelType #107

Open marcoboerner opened 11 months ago

marcoboerner commented 11 months ago

Fixes #100 Add explicit codable implementation to ChatMessage without removing the Identifiable conformance by implementing an explicit codable implementation that ignores the id property when encoding, and creates a new UUID when decoding.

This should fix the regular chat and streaming chat as both have not been working with the encoded id.

I've also added a new OpenAIEndpointModelType with the currently available OpenAI models, to replace the OpenAIModelType. The current OpenAIModelType model enum and methods that have models as parameters could easily cause errors as any model could be chosen for any of those methods. By adding the new OpenAIEndpointModel type that corresponds to the compatibility list in the OpenAI docs, it’s much easier to select the fitting model. The new type does contain duplicate model strings, which is intended to make it easier to maintain.

Backward compatibility is assured by marking the previous methods as deprecated. and using the old methods as wrappers around the new methods.

simonmitchell commented 11 months ago

@adamrushy any idea when you may get the opportunity to review and merge this? 😄