mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
438f764c7a
* fix(providers): support per-model request_timeout in model_list * fix(lint): format provider constructors for golines * refactor(providers): adopt functional options and preserve timeout migration * docs(readme): sync request_timeout guidance across translated docs --------- Co-authored-by: Yiliu <yiliu@affiliate-guide.com>
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
// PicoClaw - Ultra-lightweight personal AI agent
|
|
// Inspired by and based on nanobot: https://github.com/HKUDS/nanobot
|
|
// License: MIT
|
|
//
|
|
// Copyright (c) 2026 PicoClaw contributors
|
|
|
|
package providers
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/providers/openai_compat"
|
|
)
|
|
|
|
type HTTPProvider struct {
|
|
delegate *openai_compat.Provider
|
|
}
|
|
|
|
func NewHTTPProvider(apiKey, apiBase, proxy string) *HTTPProvider {
|
|
return &HTTPProvider{
|
|
delegate: openai_compat.NewProvider(apiKey, apiBase, proxy),
|
|
}
|
|
}
|
|
|
|
func NewHTTPProviderWithMaxTokensField(apiKey, apiBase, proxy, maxTokensField string) *HTTPProvider {
|
|
return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout(apiKey, apiBase, proxy, maxTokensField, 0)
|
|
}
|
|
|
|
func NewHTTPProviderWithMaxTokensFieldAndRequestTimeout(
|
|
apiKey, apiBase, proxy, maxTokensField string,
|
|
requestTimeoutSeconds int,
|
|
) *HTTPProvider {
|
|
return &HTTPProvider{
|
|
delegate: openai_compat.NewProvider(
|
|
apiKey,
|
|
apiBase,
|
|
proxy,
|
|
openai_compat.WithMaxTokensField(maxTokensField),
|
|
openai_compat.WithRequestTimeout(time.Duration(requestTimeoutSeconds)*time.Second),
|
|
),
|
|
}
|
|
}
|
|
|
|
func (p *HTTPProvider) Chat(
|
|
ctx context.Context,
|
|
messages []Message,
|
|
tools []ToolDefinition,
|
|
model string,
|
|
options map[string]any,
|
|
) (*LLMResponse, error) {
|
|
return p.delegate.Chat(ctx, messages, tools, model, options)
|
|
}
|
|
|
|
func (p *HTTPProvider) GetDefaultModel() string {
|
|
return ""
|
|
}
|