-
-
Notifications
You must be signed in to change notification settings - Fork 86
feat(providers): add Chutes AI support #667
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
153ee15
feat(providers): add Chutes AI support
SantiagoDePolonia 829102a
fix(chutes): address provider review feedback
SantiagoDePolonia a7c34ff
test(chutes): cover provider integration branches
SantiagoDePolonia d0dc943
test(chutes): strengthen request contract assertions
SantiagoDePolonia a5a661d
feat(chutes): enable passthrough by default
SantiagoDePolonia 9d421be
fix(chutes): require passthrough opt-in
SantiagoDePolonia 85c5bcb
test(dashboard): cover all provider types
SantiagoDePolonia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // Package chutes provides Chutes AI integration for the LLM gateway. | ||
| package chutes | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
| "net/http" | ||
|
|
||
| "github.com/enterpilot/gomodel/internal/core" | ||
| "github.com/enterpilot/gomodel/internal/llmclient" | ||
| "github.com/enterpilot/gomodel/internal/providers" | ||
| "github.com/enterpilot/gomodel/internal/providers/openai" | ||
| ) | ||
|
|
||
| const defaultBaseURL = "https://llm.chutes.ai/v1" | ||
|
|
||
| // Registration provides factory registration for the Chutes AI provider. | ||
| var Registration = providers.Registration{ | ||
| Type: "chutes", | ||
| New: New, | ||
| Discovery: providers.DiscoveryConfig{ | ||
| DefaultBaseURL: defaultBaseURL, | ||
| }, | ||
| } | ||
|
|
||
| // Provider implements Chutes' OpenAI-compatible chat surface. Chutes does not | ||
| // expose native Responses or embeddings endpoints, so Responses requests are | ||
| // translated through chat completions and embeddings fail locally. | ||
| type Provider struct { | ||
| compat *openai.CompatibleProvider | ||
| } | ||
|
|
||
| var _ core.Provider = (*Provider)(nil) | ||
| var _ core.PassthroughProvider = (*Provider)(nil) | ||
|
|
||
| // New creates a new Chutes AI provider. | ||
| func New(cfg providers.ProviderConfig, opts providers.ProviderOptions) core.Provider { | ||
| return &Provider{compat: openai.NewCompatibleProvider(cfg.APIKey, opts, compatibleConfig( | ||
| providers.ResolveBaseURL(cfg.BaseURL, defaultBaseURL), | ||
| ))} | ||
| } | ||
|
|
||
| // NewWithHTTPClient creates a new Chutes AI provider with a custom HTTP client. | ||
| // If httpClient is nil, http.DefaultClient is used. | ||
| func NewWithHTTPClient(apiKey string, baseURL string, httpClient *http.Client, hooks llmclient.Hooks) *Provider { | ||
| return &Provider{compat: openai.NewCompatibleProviderWithHTTPClient(apiKey, httpClient, hooks, compatibleConfig( | ||
| providers.ResolveBaseURL(baseURL, defaultBaseURL), | ||
| ))} | ||
| } | ||
|
|
||
| // compatibleConfig returns the shared OpenAI-compatible transport settings for Chutes. | ||
| func compatibleConfig(baseURL string) openai.CompatibleProviderConfig { | ||
| return openai.CompatibleProviderConfig{ | ||
| ProviderName: "chutes", | ||
| BaseURL: baseURL, | ||
| SetHeaders: setHeaders, | ||
| } | ||
| } | ||
|
|
||
| // setHeaders applies Chutes' bearer-token authentication. | ||
| func setHeaders(req *http.Request, apiKey string) { | ||
| providers.SetAuthHeaders(req, apiKey, providers.AuthHeaderConfig{AuthScheme: "Bearer "}) | ||
| } | ||
|
|
||
| // SetBaseURL changes the Chutes API base URL. | ||
| func (p *Provider) SetBaseURL(baseURL string) { | ||
| p.compat.SetBaseURL(baseURL) | ||
| } | ||
|
|
||
| // ChatCompletion sends a chat completion request to Chutes. | ||
| func (p *Provider) ChatCompletion(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error) { | ||
| return p.compat.ChatCompletion(ctx, req) | ||
| } | ||
|
|
||
| // StreamChatCompletion sends a streaming chat completion request to Chutes. | ||
| func (p *Provider) StreamChatCompletion(ctx context.Context, req *core.ChatRequest) (io.ReadCloser, error) { | ||
| return p.compat.StreamChatCompletion(ctx, req) | ||
| } | ||
|
|
||
| // Responses translates an OpenAI Responses request through Chutes chat completions. | ||
| func (p *Provider) Responses(ctx context.Context, req *core.ResponsesRequest) (*core.ResponsesResponse, error) { | ||
| return providers.ResponsesViaChat(ctx, p, req) | ||
| } | ||
|
|
||
| // StreamResponses translates a streaming Responses request through Chutes chat completions. | ||
| func (p *Provider) StreamResponses(ctx context.Context, req *core.ResponsesRequest) (io.ReadCloser, error) { | ||
| return providers.StreamResponsesViaChat(ctx, p, req, "chutes") | ||
| } | ||
|
|
||
| // Embeddings returns an error because the shared Chutes LLM endpoint does not | ||
| // expose an OpenAI-compatible embeddings route. | ||
| func (p *Provider) Embeddings(_ context.Context, _ *core.EmbeddingRequest) (*core.EmbeddingResponse, error) { | ||
| return nil, core.NewInvalidRequestError("chutes does not support embeddings", nil) | ||
| } | ||
|
|
||
| // Passthrough forwards an opaque request to Chutes. | ||
| func (p *Provider) Passthrough(ctx context.Context, req *core.PassthroughRequest) (*core.PassthroughResponse, error) { | ||
| return p.compat.Passthrough(ctx, req) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.