MCPcopy Create free account
hub / github.com/bytebase/bytebase / Chat

Method Chat

backend/api/v1/ai_service.go:37–56  ·  view source on GitHub ↗

Chat sends a conversation with tool definitions to the configured AI provider and returns the response.

(ctx context.Context, req *connect.Request[v1pb.AIChatRequest])

Source from the content-addressed store, hash-verified

35
36// Chat sends a conversation with tool definitions to the configured AI provider and returns the response.
37func (s *AIService) Chat(ctx context.Context, req *connect.Request[v1pb.AIChatRequest]) (*connect.Response[v1pb.AIChatResponse], error) {
38 aiSetting, err := s.store.GetAISetting(ctx, common.GetWorkspaceIDFromContext(ctx))
39 if err != nil {
40 return nil, err
41 }
42 if !aiSetting.Enabled {
43 return nil, connect.NewError(connect.CodeFailedPrecondition, errors.New("AI is not enabled"))
44 }
45
46 switch aiSetting.Provider {
47 case storepb.AISetting_OPEN_AI, storepb.AISetting_AZURE_OPENAI:
48 return s.chatOpenAI(ctx, aiSetting, req.Msg)
49 case storepb.AISetting_GEMINI:
50 return s.chatGemini(ctx, aiSetting, req.Msg)
51 case storepb.AISetting_CLAUDE:
52 return s.chatClaude(ctx, aiSetting, req.Msg)
53 default:
54 return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("unsupported AI provider %s", aiSetting.Provider))
55 }
56}
57
58// OpenAI chat types with tool-calling support.
59

Callers

nothing calls this directly

Calls 6

chatOpenAIMethod · 0.95
chatGeminiMethod · 0.95
chatClaudeMethod · 0.95
GetAISettingMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected