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

👽 (Compatability) Make model optional to allow using TogetherAI endpoint #177

Closed
wants to merge 7 commits into from

Conversation

djmango
Copy link

@djmango djmango commented Feb 20, 2024

What

TogetherAI's API mocks OpenAI's, however the model is not returned in chat stream responses, thus it must be made optional in order to proceed without erroring.

Simply added a ? flag to make model optional.

Enables you to use the TogetherAI API like so:

let configuration = OpenAI.Configuration(token: "NOTYOURTOKEN", host: "api.together.xyz", timeoutInterval: 10)
let ai = OpenAI(configuration: configuration)

Affected Areas

ChatStreamResponse.swift

James J Kalafus and others added 2 commits February 16, 2024 15:35
TogetherAI's API mocks OpenAI's, however the model is not returned in chat stream responses, thus it must be made optional in order to proceed without erroring.
@kalafus
Copy link
Contributor

kalafus commented Feb 21, 2024

Does this fall under this scope-creep? This project specifically implements the OpenAI API.

@djmango
Copy link
Author

djmango commented Feb 21, 2024

It's an extremely minor change, and most of the inference providers intentionally clone the OpenAI API in order to be compatible with project such as this. I have submitted a ticket to them regarding this issue as well, but this solution will be more robust.

Copy link
Contributor

@kalafus kalafus left a comment

Choose a reason for hiding this comment

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

maintainers will most likely ask for a cleaner pull.

is it just the streaming version of this one endpoint that you're interested in compatibility for?

@@ -124,7 +121,7 @@ public struct ChatStreamResult: Codable, Equatable {
/// Each chunk has the same timestamp.
public let created: TimeInterval
/// The model to generate the completion.
public let model: String
public let model: String?
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the only change relevant to the intent of the pull

@djmango
Copy link
Author

djmango commented Feb 26, 2024

I've now added support for paths in the model host config, enabling Groq API support (api.groq.com/openai)

extension OpenAI {
    func buildURL(path: String) -> URL {
        var components = URLComponents()
        components.scheme = "https"

        // Check if host contains a path component
        let hostParts = configuration.host.split(separator: "/", maxSplits: 1, omittingEmptySubsequences: true)
        if hostParts.count > 1 {
            // Host contains a path component
            components.host = String(hostParts[0])
            let hostPath = "/" + hostParts[1]
            components.path = hostPath + path
        } else {
            // Host does not contain a path component
            components.host = configuration.host
            components.path = path
        }

        guard let url = components.url else {
            fatalError("Unable to construct URL from components.")
        }

        return url
    }
}

Copy link

sonarcloud bot commented Mar 4, 2024

Quality Gate Passed Quality Gate passed

Issues
2 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@DanielhCarranza
Copy link

Any update on this I'm interested in this because many models can be use this way, Grow, TogetherAI, Huggingface, Azure, etc

@djmango
Copy link
Author

djmango commented May 4, 2024 via email

Copy link

sonarcloud bot commented May 26, 2024

Quality Gate Passed Quality Gate passed

Issues
8 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@djmango
Copy link
Author

djmango commented May 28, 2024

branching far away from the original scope of this project now

@djmango djmango closed this May 28, 2024
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.

None yet

3 participants