make fmt
This commit is contained in:
@@ -157,30 +157,28 @@ type DevicesConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ProvidersConfig struct {
|
type ProvidersConfig struct {
|
||||||
Anthropic ProviderConfig `json:"anthropic"`
|
Anthropic ProviderConfig `json:"anthropic"`
|
||||||
OpenAI ProviderConfig `json:"openai"`
|
OpenAI ProviderConfig `json:"openai"`
|
||||||
OpenRouter ProviderConfig `json:"openrouter"`
|
OpenRouter ProviderConfig `json:"openrouter"`
|
||||||
Groq ProviderConfig `json:"groq"`
|
Groq ProviderConfig `json:"groq"`
|
||||||
Zhipu ProviderConfig `json:"zhipu"`
|
Zhipu ProviderConfig `json:"zhipu"`
|
||||||
VLLM ProviderConfig `json:"vllm"`
|
VLLM ProviderConfig `json:"vllm"`
|
||||||
Gemini ProviderConfig `json:"gemini"`
|
Gemini ProviderConfig `json:"gemini"`
|
||||||
Nvidia ProviderConfig `json:"nvidia"`
|
Nvidia ProviderConfig `json:"nvidia"`
|
||||||
Moonshot ProviderConfig `json:"moonshot"`
|
Moonshot ProviderConfig `json:"moonshot"`
|
||||||
ShengSuanYun ProviderConfig `json:"shengsuanyun"`
|
ShengSuanYun ProviderConfig `json:"shengsuanyun"`
|
||||||
DeepSeek ProviderConfig `json:"deepseek"`
|
DeepSeek ProviderConfig `json:"deepseek"`
|
||||||
GitHubCopilot ProviderConfig `json:"github_copilot"`
|
GitHubCopilot ProviderConfig `json:"github_copilot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProviderConfig struct {
|
type ProviderConfig struct {
|
||||||
APIKey string `json:"api_key" env:"PICOCLAW_PROVIDERS_{{.Name}}_API_KEY"`
|
APIKey string `json:"api_key" env:"PICOCLAW_PROVIDERS_{{.Name}}_API_KEY"`
|
||||||
APIBase string `json:"api_base" env:"PICOCLAW_PROVIDERS_{{.Name}}_API_BASE"`
|
APIBase string `json:"api_base" env:"PICOCLAW_PROVIDERS_{{.Name}}_API_BASE"`
|
||||||
Proxy string `json:"proxy,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_PROXY"`
|
Proxy string `json:"proxy,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_PROXY"`
|
||||||
AuthMethod string `json:"auth_method,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_AUTH_METHOD"`
|
AuthMethod string `json:"auth_method,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_AUTH_METHOD"`
|
||||||
ConnectMode string `json:"connect_mode,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_CONNECT_MODE"` //only for Github Copilot, `stdio` or `grpc`
|
ConnectMode string `json:"connect_mode,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_CONNECT_MODE"` //only for Github Copilot, `stdio` or `grpc`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type GatewayConfig struct {
|
type GatewayConfig struct {
|
||||||
Host string `json:"host" env:"PICOCLAW_GATEWAY_HOST"`
|
Host string `json:"host" env:"PICOCLAW_GATEWAY_HOST"`
|
||||||
Port int `json:"port" env:"PICOCLAW_GATEWAY_PORT"`
|
Port int `json:"port" env:"PICOCLAW_GATEWAY_PORT"`
|
||||||
|
|||||||
@@ -7,21 +7,20 @@ import (
|
|||||||
json "encoding/json"
|
json "encoding/json"
|
||||||
|
|
||||||
copilot "github.com/github/copilot-sdk/go"
|
copilot "github.com/github/copilot-sdk/go"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitHubCopilotProvider struct {
|
type GitHubCopilotProvider struct {
|
||||||
uri string
|
uri string
|
||||||
connectMode string // `stdio` or `grpc``
|
connectMode string // `stdio` or `grpc``
|
||||||
|
|
||||||
session *copilot.Session
|
session *copilot.Session
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGitHubCopilotProvider(uri string, connectMode string, model string) *GitHubCopilotProvider {
|
func NewGitHubCopilotProvider(uri string, connectMode string, model string) *GitHubCopilotProvider {
|
||||||
|
|
||||||
var session *copilot.Session
|
var session *copilot.Session
|
||||||
if connectMode == "" {
|
if connectMode == "" {
|
||||||
connectMode = "grpc"
|
connectMode = "grpc"
|
||||||
}
|
}
|
||||||
switch connectMode {
|
switch connectMode {
|
||||||
|
|
||||||
@@ -37,55 +36,48 @@ func NewGitHubCopilotProvider(uri string, connectMode string, model string) *Git
|
|||||||
defer client.Stop()
|
defer client.Stop()
|
||||||
session, _ = client.CreateSession(context.Background(), &copilot.SessionConfig{
|
session, _ = client.CreateSession(context.Background(), &copilot.SessionConfig{
|
||||||
Model: model,
|
Model: model,
|
||||||
Hooks: &copilot.SessionHooks{
|
Hooks: &copilot.SessionHooks{},
|
||||||
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &GitHubCopilotProvider{
|
return &GitHubCopilotProvider{
|
||||||
uri: uri,
|
uri: uri,
|
||||||
connectMode: connectMode,
|
connectMode: connectMode,
|
||||||
|
|
||||||
session: session,
|
session: session,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chat sends a chat request to GitHub Copilot
|
// Chat sends a chat request to GitHub Copilot
|
||||||
func (p *GitHubCopilotProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition, model string, options map[string]interface{}) (*LLMResponse, error) {
|
func (p *GitHubCopilotProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition, model string, options map[string]interface{}) (*LLMResponse, error) {
|
||||||
type tempMessage struct {
|
type tempMessage struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
out := make([]tempMessage, 0, len(messages))
|
out := make([]tempMessage, 0, len(messages))
|
||||||
|
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
out = append(out, tempMessage{
|
out = append(out, tempMessage{
|
||||||
Role: msg.Role,
|
Role: msg.Role,
|
||||||
Content: msg.Content,
|
Content: msg.Content,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fullcontent,_ := json.Marshal(out)
|
fullcontent, _ := json.Marshal(out)
|
||||||
|
|
||||||
|
|
||||||
|
content, _ := p.session.Send(ctx, copilot.MessageOptions{
|
||||||
|
Prompt: string(fullcontent),
|
||||||
|
})
|
||||||
|
|
||||||
|
return &LLMResponse{
|
||||||
|
FinishReason: "stop",
|
||||||
|
Content: content,
|
||||||
|
}, nil
|
||||||
|
|
||||||
|
|
||||||
content,_ := p.session.Send(ctx,copilot.MessageOptions{
|
|
||||||
Prompt: string(fullcontent),
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
return &LLMResponse{
|
|
||||||
FinishReason : "stop",
|
|
||||||
Content: content,
|
|
||||||
}, nil
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (p *GitHubCopilotProvider) GetDefaultModel() string {
|
func (p *GitHubCopilotProvider) GetDefaultModel() string {
|
||||||
|
|
||||||
return "gpt-4.1"
|
return "gpt-4.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -317,13 +317,12 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) {
|
|||||||
case "github_copilot", "copilot":
|
case "github_copilot", "copilot":
|
||||||
if cfg.Providers.GitHubCopilot.APIBase != "" {
|
if cfg.Providers.GitHubCopilot.APIBase != "" {
|
||||||
apiBase = cfg.Providers.GitHubCopilot.APIBase
|
apiBase = cfg.Providers.GitHubCopilot.APIBase
|
||||||
}else {
|
} else {
|
||||||
apiBase = "localhost:4321" // no `http://` beacause grpc mode`
|
apiBase = "localhost:4321" // no `http://` beacause grpc mode`
|
||||||
}
|
}
|
||||||
return NewGitHubCopilotProvider(apiBase, cfg.Providers.GitHubCopilot.ConnectMode, model), nil
|
return NewGitHubCopilotProvider(apiBase, cfg.Providers.GitHubCopilot.ConnectMode, model), nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user