Changeset 0.5.0 (#35)
This commit is contained in:
@@ -116,6 +116,9 @@ func (p *OpenAIProvider) ListModels(ctx context.Context, cfg ProviderConfig) ([]
|
||||
if cfg.APIKey != "" {
|
||||
httpReq.Header.Set("Authorization", "Bearer "+cfg.APIKey)
|
||||
}
|
||||
for k, v := range cfg.CustomHeaders {
|
||||
httpReq.Header.Set(k, v)
|
||||
}
|
||||
|
||||
resp, err := http.DefaultClient.Do(httpReq)
|
||||
if err != nil {
|
||||
@@ -135,9 +138,20 @@ func (p *OpenAIProvider) ListModels(ctx context.Context, cfg ProviderConfig) ([]
|
||||
|
||||
models := make([]Model, 0, len(result.Data))
|
||||
for _, m := range result.Data {
|
||||
// Try known table first, then heuristic
|
||||
caps, found := LookupKnownModel(m.ID)
|
||||
if !found {
|
||||
caps = InferCapabilities(m.ID)
|
||||
}
|
||||
// Use context_length from API if available and we don't have it
|
||||
if m.ContextLength > 0 && caps.MaxContext == 0 {
|
||||
caps.MaxContext = m.ContextLength
|
||||
}
|
||||
|
||||
models = append(models, Model{
|
||||
ID: m.ID,
|
||||
OwnedBy: m.OwnedBy,
|
||||
ID: m.ID,
|
||||
OwnedBy: m.OwnedBy,
|
||||
Capabilities: caps,
|
||||
})
|
||||
}
|
||||
return models, nil
|
||||
@@ -184,6 +198,10 @@ func (p *OpenAIProvider) doRequest(ctx context.Context, cfg ProviderConfig, req
|
||||
if cfg.APIKey != "" {
|
||||
httpReq.Header.Set("Authorization", "Bearer "+cfg.APIKey)
|
||||
}
|
||||
// Inject provider-level custom headers (OpenRouter, Venice, etc.)
|
||||
for k, v := range cfg.CustomHeaders {
|
||||
httpReq.Header.Set(k, v)
|
||||
}
|
||||
|
||||
resp, err := http.DefaultClient.Do(httpReq)
|
||||
if err != nil {
|
||||
@@ -239,7 +257,8 @@ type openaiStreamChunk struct {
|
||||
|
||||
type openaiModelsResponse struct {
|
||||
Data []struct {
|
||||
ID string `json:"id"`
|
||||
OwnedBy string `json:"owned_by"`
|
||||
ID string `json:"id"`
|
||||
OwnedBy string `json:"owned_by"`
|
||||
ContextLength int `json:"context_length,omitempty"` // Ollama, OpenRouter
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user