Changeset 0.5.0 (#35)
This commit is contained in:
@@ -525,7 +525,7 @@ func (h *AdminHandler) ListModelConfigs(c *gin.Context) {
|
||||
func (h *AdminHandler) FetchModels(c *gin.Context) {
|
||||
// Load all global api_configs
|
||||
rows, err := database.DB.Query(`
|
||||
SELECT id, provider, endpoint, api_key_encrypted
|
||||
SELECT id, provider, endpoint, api_key_encrypted, custom_headers
|
||||
FROM api_configs
|
||||
WHERE user_id IS NULL AND is_active = true
|
||||
`)
|
||||
@@ -539,6 +539,7 @@ func (h *AdminHandler) FetchModels(c *gin.Context) {
|
||||
ConfigID string `json:"config_id"`
|
||||
Provider string `json:"provider"`
|
||||
Added int `json:"added"`
|
||||
Updated int `json:"updated"`
|
||||
Skipped int `json:"skipped"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
@@ -548,7 +549,8 @@ func (h *AdminHandler) FetchModels(c *gin.Context) {
|
||||
for rows.Next() {
|
||||
var cfgID, providerID, endpoint string
|
||||
var apiKey *string
|
||||
if err := rows.Scan(&cfgID, &providerID, &endpoint, &apiKey); err != nil {
|
||||
var customHeadersJSON []byte
|
||||
if err := rows.Scan(&cfgID, &providerID, &endpoint, &apiKey, &customHeadersJSON); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -563,9 +565,15 @@ func (h *AdminHandler) FetchModels(c *gin.Context) {
|
||||
key = *apiKey
|
||||
}
|
||||
|
||||
customHeaders := make(map[string]string)
|
||||
if customHeadersJSON != nil {
|
||||
_ = json.Unmarshal(customHeadersJSON, &customHeaders)
|
||||
}
|
||||
|
||||
models, err := prov.ListModels(c.Request.Context(), providers.ProviderConfig{
|
||||
Endpoint: endpoint,
|
||||
APIKey: key,
|
||||
Endpoint: endpoint,
|
||||
APIKey: key,
|
||||
CustomHeaders: customHeaders,
|
||||
})
|
||||
if err != nil {
|
||||
results = append(results, fetchResult{ConfigID: cfgID, Provider: providerID, Error: err.Error()})
|
||||
@@ -574,11 +582,18 @@ func (h *AdminHandler) FetchModels(c *gin.Context) {
|
||||
|
||||
fr := fetchResult{ConfigID: cfgID, Provider: providerID}
|
||||
for _, m := range models {
|
||||
// Serialize capabilities to JSONB
|
||||
capsJSON, _ := json.Marshal(m.Capabilities)
|
||||
|
||||
result, err := database.DB.Exec(`
|
||||
INSERT INTO model_configs (api_config_id, model_id, display_name)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (api_config_id, model_id) DO NOTHING
|
||||
`, cfgID, m.ID, m.Name)
|
||||
INSERT INTO model_configs (api_config_id, model_id, display_name, capabilities)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (api_config_id, model_id)
|
||||
DO UPDATE SET
|
||||
display_name = COALESCE(NULLIF(model_configs.display_name, ''), EXCLUDED.display_name),
|
||||
capabilities = EXCLUDED.capabilities,
|
||||
updated_at = NOW()
|
||||
`, cfgID, m.ID, m.Name, capsJSON)
|
||||
if err != nil {
|
||||
fr.Skipped++
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user