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

Method AICompletion

backend/api/v1/sql_service_ai.go:101–121  ·  view source on GitHub ↗

AICompletion is the mixer for AI completion.

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

Source from the content-addressed store, hash-verified

99
100// AICompletion is the mixer for AI completion.
101func (s *SQLService) AICompletion(ctx context.Context, req *connect.Request[v1pb.AICompletionRequest]) (*connect.Response[v1pb.AICompletionResponse], error) {
102 request := req.Msg
103 aiSetting, err := s.store.GetAISetting(ctx, common.GetWorkspaceIDFromContext(ctx))
104 if err != nil {
105 return nil, err
106 }
107 if !aiSetting.Enabled {
108 return nil, connect.NewError(connect.CodeFailedPrecondition, errors.New("AI is not enabled"))
109 }
110
111 switch aiSetting.Provider {
112 case storepb.AISetting_OPEN_AI, storepb.AISetting_AZURE_OPENAI:
113 return callOpenAI(ctx, aiSetting, request)
114 case storepb.AISetting_GEMINI:
115 return callGemini(ctx, aiSetting, request)
116 case storepb.AISetting_CLAUDE:
117 return callClaude(ctx, aiSetting, request)
118 default:
119 return nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf("unsupported AI provider %s", aiSetting.Provider))
120 }
121}
122
123func callOpenAI(ctx context.Context, aiSetting *storepb.AISetting, request *v1pb.AICompletionRequest) (*connect.Response[v1pb.AICompletionResponse], error) {
124 payload := buildOpenAICompletionRequest(aiSetting.Model, request)

Callers

nothing calls this directly

Calls 6

callOpenAIFunction · 0.85
callGeminiFunction · 0.85
callClaudeFunction · 0.85
GetAISettingMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected