feat: add get models by provider

This commit is contained in:
Acbox
2026-02-02 13:48:22 +08:00
parent c10fbfee23
commit 3f0a0f8499
10 changed files with 330 additions and 38 deletions
-19
View File
@@ -8,25 +8,6 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
type ChannelConfig struct {
ID pgtype.UUID `json:"id"`
ChannelType string `json:"channel_type"`
Config []byte `json:"config"`
UserID pgtype.UUID `json:"user_id"`
IsGlobal bool `json:"is_global"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type ChannelUserConfig struct {
ID pgtype.UUID `json:"id"`
ChannelType string `json:"channel_type"`
UserID pgtype.UUID `json:"user_id"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type Container struct {
ID pgtype.UUID `json:"id"`
UserID pgtype.UUID `json:"user_id"`
+78
View File
@@ -527,6 +527,84 @@ func (q *Queries) ListModelsByClientType(ctx context.Context, clientType string)
return items, nil
}
const listModelsByProviderID = `-- name: ListModelsByProviderID :many
SELECT id, model_id, name, llm_provider_id, dimensions, is_multimodal, type, created_at, updated_at FROM models
WHERE llm_provider_id = $1
ORDER BY created_at DESC
`
func (q *Queries) ListModelsByProviderID(ctx context.Context, llmProviderID pgtype.UUID) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderID, llmProviderID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.Dimensions,
&i.IsMultimodal,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByProviderIDAndType = `-- name: ListModelsByProviderIDAndType :many
SELECT id, model_id, name, llm_provider_id, dimensions, is_multimodal, type, created_at, updated_at FROM models
WHERE llm_provider_id = $1
AND type = $2
ORDER BY created_at DESC
`
type ListModelsByProviderIDAndTypeParams struct {
LlmProviderID pgtype.UUID `json:"llm_provider_id"`
Type string `json:"type"`
}
func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListModelsByProviderIDAndTypeParams) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderIDAndType, arg.LlmProviderID, arg.Type)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.Dimensions,
&i.IsMultimodal,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByType = `-- name: ListModelsByType :many
SELECT id, model_id, name, llm_provider_id, dimensions, is_multimodal, type, created_at, updated_at FROM models
WHERE type = $1