Files
geo/server/internal/shared/llm/client.go
T
root de30497f59 feat: add tenant and user management with migrations, handlers, and tests
- Implemented tenant and user management features including:
  - Tenant creation and management with associated migrations.
  - User creation and management with associated migrations.
  - Tenant membership management with associated migrations.
  - Platform user roles management with associated migrations.
  - Quota management with associated migrations.
  - Article and template management with associated migrations.
- Added HTTP handlers for templates and workspaces.
- Created tests for protected and public routes.
- Introduced a script to check tenant scope in SQL queries.
- Documented task plan for backend completion and frontend foundation.
2026-04-01 00:58:42 +08:00

54 lines
1.1 KiB
Go

package llm
import (
"context"
"errors"
"fmt"
"strings"
"github.com/geo-platform/tenant-api/internal/shared/config"
)
var ErrNotConfigured = errors.New("llm provider is not configured")
type GenerateRequest struct {
Prompt string
}
type GenerateResult struct {
Content string
Model string
}
type Client interface {
Validate() error
Generate(ctx context.Context, req GenerateRequest, onDelta func(string)) (*GenerateResult, error)
}
func New(cfg config.LLMConfig) Client {
provider := strings.ToLower(strings.TrimSpace(cfg.Provider))
switch provider {
case "", "disabled":
return disabledClient{reason: "llm provider is disabled"}
case "ark":
return NewArkClient(cfg)
default:
return disabledClient{reason: fmt.Sprintf("unsupported llm provider %q", cfg.Provider)}
}
}
type disabledClient struct {
reason string
}
func (c disabledClient) Validate() error {
if c.reason == "" {
c.reason = "missing LLM configuration"
}
return fmt.Errorf("%w: %s", ErrNotConfigured, c.reason)
}
func (c disabledClient) Generate(context.Context, GenerateRequest, func(string)) (*GenerateResult, error) {
return nil, c.Validate()
}