fix: handle ignored errors in GitHub Copilot provider
Co-authored-by: Argobell <183611258+Argobell@users.noreply.github.com>
This commit is contained in:
parent
db1eb1e6b1
commit
48bcfce023
1 changed files with 17 additions and 7 deletions
|
|
@ -23,22 +23,26 @@ func NewGitHubCopilotProvider(uri string, connectMode string, model string) (*Gi
|
||||||
switch connectMode {
|
switch connectMode {
|
||||||
|
|
||||||
case "stdio":
|
case "stdio":
|
||||||
// todo
|
return nil, fmt.Errorf("stdio connect mode is not yet supported for GitHub Copilot provider")
|
||||||
case "grpc":
|
case "grpc":
|
||||||
client := copilot.NewClient(&copilot.ClientOptions{
|
client := copilot.NewClient(&copilot.ClientOptions{
|
||||||
CLIUrl: uri,
|
CLIUrl: uri,
|
||||||
})
|
})
|
||||||
if err := client.Start(context.Background()); err != nil {
|
if err := client.Start(context.Background()); err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("can't connect to GitHub Copilot (see https://github.com/github/copilot-sdk/blob/main/docs/getting-started.md#connecting-to-an-external-cli-server): %w", err)
|
||||||
"Can't connect to Github Copilot, https://github.com/github/copilot-sdk/blob/main/docs/getting-started.md#connecting-to-an-external-cli-server for details",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
defer client.Stop()
|
defer client.Stop()
|
||||||
session, _ = client.CreateSession(context.Background(), &copilot.SessionConfig{
|
var err error
|
||||||
|
session, err = client.CreateSession(context.Background(), &copilot.SessionConfig{
|
||||||
Model: model,
|
Model: model,
|
||||||
Hooks: &copilot.SessionHooks{},
|
Hooks: &copilot.SessionHooks{},
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create GitHub Copilot session: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported connect mode %q for GitHub Copilot provider (supported: grpc)", connectMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &GitHubCopilotProvider{
|
return &GitHubCopilotProvider{
|
||||||
|
|
@ -65,11 +69,17 @@ func (p *GitHubCopilotProvider) Chat(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fullcontent, _ := json.Marshal(out)
|
fullcontent, err := json.Marshal(out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to marshal messages: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
content, _ := p.session.Send(ctx, copilot.MessageOptions{
|
content, err := p.session.Send(ctx, copilot.MessageOptions{
|
||||||
Prompt: string(fullcontent),
|
Prompt: string(fullcontent),
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("GitHub Copilot request failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return &LLMResponse{
|
return &LLMResponse{
|
||||||
FinishReason: "stop",
|
FinishReason: "stop",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue