Changeset 0.17.1 (#76)
This commit is contained in:
@@ -42,14 +42,6 @@ func (h *ModelHandler) ListEnabledModels(c *gin.Context) {
|
||||
}
|
||||
|
||||
// ResolveModelCaps is the canonical capability resolver for any model.
|
||||
// Priority chain:
|
||||
// 1. model_catalog DB — exact match (model_id + provider_config_id)
|
||||
// 2. model_catalog DB — any provider (same model, different config)
|
||||
// 3. Heuristic inference (name-based fallback)
|
||||
//
|
||||
// No hardcoded model table — the same model can have different capabilities
|
||||
// depending on the provider hosting it. The catalog is populated by provider
|
||||
// API sync (auto-fetch on create, manual refresh).
|
||||
func ResolveModelCaps(c *gin.Context, modelID, configID string) models.ModelCapabilities {
|
||||
// 1. Exact match: model_id + provider_config_id
|
||||
if configID != "" {
|
||||
@@ -82,15 +74,15 @@ func capsFromCatalog(modelID, configID string) (models.ModelCapabilities, bool)
|
||||
var capsJSON []byte
|
||||
var err error
|
||||
if configID != "" {
|
||||
err = database.DB.QueryRow(`
|
||||
err = database.DB.QueryRow(database.Q(`
|
||||
SELECT capabilities FROM model_catalog
|
||||
WHERE model_id = $1 AND provider_config_id = $2
|
||||
`, modelID, configID).Scan(&capsJSON)
|
||||
`), modelID, configID).Scan(&capsJSON)
|
||||
} else {
|
||||
err = database.DB.QueryRow(`
|
||||
err = database.DB.QueryRow(database.Q(`
|
||||
SELECT capabilities FROM model_catalog
|
||||
WHERE model_id = $1 ORDER BY last_synced_at DESC NULLS LAST LIMIT 1
|
||||
`, modelID).Scan(&capsJSON)
|
||||
WHERE model_id = $1 ORDER BY last_synced_at DESC LIMIT 1
|
||||
`), modelID).Scan(&capsJSON)
|
||||
}
|
||||
if err != nil || len(capsJSON) == 0 {
|
||||
return models.ModelCapabilities{}, false
|
||||
@@ -115,10 +107,10 @@ func liveQueryModelCaps(c *gin.Context, configID, modelID string) (models.ModelC
|
||||
var providerID, endpoint string
|
||||
var apiKey *string
|
||||
var headersJSON []byte
|
||||
err := database.DB.QueryRow(`
|
||||
err := database.DB.QueryRow(database.Q(`
|
||||
SELECT provider, endpoint, api_key_enc, headers
|
||||
FROM provider_configs WHERE id = $1 AND is_active = true
|
||||
`, configID).Scan(&providerID, &endpoint, &apiKey, &headersJSON)
|
||||
`), configID).Scan(&providerID, &endpoint, &apiKey, &headersJSON)
|
||||
if err != nil {
|
||||
return models.ModelCapabilities{}, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user