Changeset 0.8.6 (#49)
This commit is contained in:
@@ -146,7 +146,7 @@ func (h *CompletionHandler) Complete(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Resolve capabilities for this model — auto-set defaults
|
||||
caps := h.getModelCapabilities(model, configID)
|
||||
caps := h.getModelCapabilities(c, model, configID)
|
||||
|
||||
if req.MaxTokens > 0 {
|
||||
provReq.MaxTokens = req.MaxTokens
|
||||
@@ -479,32 +479,8 @@ func escapeJSON(s string) string {
|
||||
|
||||
// getModelCapabilities looks up capabilities from model_configs DB,
|
||||
// then overlays with known model defaults and heuristic detection.
|
||||
func (h *CompletionHandler) getModelCapabilities(model, apiConfigID string) providers.ModelCapabilities {
|
||||
// Start with known table or heuristic
|
||||
// Start with known model table or heuristics
|
||||
caps, found := providers.LookupKnownModel(model)
|
||||
if !found {
|
||||
caps = providers.InferCapabilities(model)
|
||||
}
|
||||
|
||||
// Overlay with DB-stored capabilities (from provider sync or admin edit — authoritative)
|
||||
var capsJSON []byte
|
||||
err := database.DB.QueryRow(`
|
||||
SELECT capabilities FROM model_configs
|
||||
WHERE model_id = $1 AND api_config_id = $2
|
||||
`, model, apiConfigID).Scan(&capsJSON)
|
||||
|
||||
if err == nil && capsJSON != nil {
|
||||
var dbCaps providers.ModelCapabilities
|
||||
if err := json.Unmarshal(capsJSON, &dbCaps); err == nil {
|
||||
if dbCaps.HasProviderData() {
|
||||
// DB has real provider data — use as authoritative, fill gaps
|
||||
caps = providers.MergeCapabilities(dbCaps, model)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return caps
|
||||
func (h *CompletionHandler) getModelCapabilities(c *gin.Context, model, apiConfigID string) providers.ModelCapabilities {
|
||||
return ResolveModelCaps(c, model, apiConfigID)
|
||||
}
|
||||
|
||||
// ── Config Resolution ───────────────────────
|
||||
@@ -529,11 +505,11 @@ func (h *CompletionHandler) resolveConfig(userID string, channelID string, req c
|
||||
}
|
||||
}
|
||||
|
||||
// 3. User's first active config (personal first, then global)
|
||||
// 3. User's first active config (personal first, then global — excludes team providers)
|
||||
if configID == "" {
|
||||
err := database.DB.QueryRow(`
|
||||
SELECT id FROM api_configs
|
||||
WHERE (user_id = $1 OR is_global = true OR user_id IS NULL) AND is_active = true
|
||||
WHERE (user_id = $1 OR is_global = true) AND is_active = true AND team_id IS NULL
|
||||
ORDER BY user_id NULLS LAST, created_at ASC
|
||||
LIMIT 1
|
||||
`, userID).Scan(&configID)
|
||||
@@ -542,14 +518,16 @@ func (h *CompletionHandler) resolveConfig(userID string, channelID string, req c
|
||||
}
|
||||
}
|
||||
|
||||
// Load the config including custom headers and provider settings
|
||||
// Load the config — allow personal, global, OR team configs the user belongs to
|
||||
var providerID, endpoint string
|
||||
var apiKey, modelDefault *string
|
||||
var customHeadersJSON, providerSettingsJSON []byte
|
||||
err := database.DB.QueryRow(`
|
||||
SELECT provider, endpoint, api_key_encrypted, model_default, custom_headers, provider_settings
|
||||
FROM api_configs
|
||||
WHERE id = $1 AND (user_id = $2 OR is_global = true OR user_id IS NULL) AND is_active = true
|
||||
WHERE id = $1 AND is_active = true
|
||||
AND (user_id = $2 OR is_global = true
|
||||
OR team_id IN (SELECT team_id FROM team_members WHERE user_id = $2))
|
||||
`, configID, userID).Scan(&providerID, &endpoint, &apiKey, &modelDefault, &customHeadersJSON, &providerSettingsJSON)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
|
||||
Reference in New Issue
Block a user