Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit codable implementation to ChatMessage and new OpenAIEndpointModelType #107

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

marcoboerner
Copy link

@marcoboerner marcoboerner commented Jul 31, 2023

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.

Fixes adamrushy#100 `sendChat is failing because ChatMessage has extra property`
@simonmitchell
Copy link

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

The current 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. https://platform.openai.com/docs/models/model-endpoint-compatibility
@marcoboerner marcoboerner changed the title Add explicit codable implementation to ChatMessage Add explicit codable implementation to ChatMessage and new OpenAIEndpointModelType Sep 1, 2023
case content
}

public init(from decoder: Decoder) throws {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcoboerner I may be missing something, but I don't think this is needed. Specifying CodingKeys should be sufficient. I have a fork with a commit here that fixes this issue.

(Same goes for encode() method below.)

For what it's worth I'll open up a PR with the "one line" solution that only solves the reported problem (maybe that'll get merged sooner?).

That said the other changes you made are also useful...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...nevermind, I won't open a PR because I see there are several already. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sendChat is failing because ChatMessage has extra property
3 participants