Chat sends a conversation with tool definitions to the configured AI provider and returns the response.
(ctx context.Context, req *connect.Request[v1pb.AIChatRequest])
| 35 | |
| 36 | // Chat sends a conversation with tool definitions to the configured AI provider and returns the response. |
| 37 | func (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 |
nothing calls this directly
no test coverage detected