mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
feat: search provider
This commit is contained in:
@@ -14,6 +14,7 @@ DROP TABLE IF EXISTS bot_members;
|
||||
DROP TABLE IF EXISTS bots;
|
||||
DROP TABLE IF EXISTS model_variants;
|
||||
DROP TABLE IF EXISTS models;
|
||||
DROP TABLE IF EXISTS search_providers;
|
||||
DROP TABLE IF EXISTS llm_providers;
|
||||
DROP TABLE IF EXISTS user_channel_bindings;
|
||||
DROP TABLE IF EXISTS channel_identities;
|
||||
|
||||
@@ -69,6 +69,17 @@ CREATE TABLE IF NOT EXISTS llm_providers (
|
||||
CONSTRAINT llm_providers_client_type_check CHECK (client_type IN ('openai', 'openai-compat', 'anthropic', 'google', 'azure', 'bedrock', 'mistral', 'xai', 'ollama', 'dashscope'))
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS search_providers (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL,
|
||||
provider TEXT NOT NULL,
|
||||
config JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
CONSTRAINT search_providers_name_unique UNIQUE (name),
|
||||
CONSTRAINT search_providers_provider_check CHECK (provider IN ('brave'))
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS models (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
model_id TEXT NOT NULL,
|
||||
@@ -111,6 +122,7 @@ CREATE TABLE IF NOT EXISTS bots (
|
||||
chat_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
|
||||
memory_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
|
||||
embedding_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
|
||||
search_provider_id UUID REFERENCES search_providers(id) ON DELETE SET NULL,
|
||||
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
|
||||
+6
-6
@@ -1,21 +1,21 @@
|
||||
-- name: CreateBot :one
|
||||
INSERT INTO bots (owner_user_id, type, display_name, avatar_url, is_active, metadata, status)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, metadata, created_at, updated_at;
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at;
|
||||
|
||||
-- name: GetBotByID :one
|
||||
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, metadata, created_at, updated_at
|
||||
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
|
||||
FROM bots
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListBotsByOwner :many
|
||||
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, metadata, created_at, updated_at
|
||||
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
|
||||
FROM bots
|
||||
WHERE owner_user_id = $1
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: ListBotsByMember :many
|
||||
SELECT b.id, b.owner_user_id, b.type, b.display_name, b.avatar_url, b.is_active, b.status, b.max_context_load_time, b.language, b.allow_guest, b.chat_model_id, b.memory_model_id, b.embedding_model_id, b.metadata, b.created_at, b.updated_at
|
||||
SELECT b.id, b.owner_user_id, b.type, b.display_name, b.avatar_url, b.is_active, b.status, b.max_context_load_time, b.language, b.allow_guest, b.chat_model_id, b.memory_model_id, b.embedding_model_id, b.search_provider_id, b.metadata, b.created_at, b.updated_at
|
||||
FROM bots b
|
||||
JOIN bot_members m ON m.bot_id = b.id
|
||||
WHERE m.user_id = $1
|
||||
@@ -29,14 +29,14 @@ SET display_name = $2,
|
||||
metadata = $5,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, metadata, created_at, updated_at;
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at;
|
||||
|
||||
-- name: UpdateBotOwner :one
|
||||
UPDATE bots
|
||||
SET owner_user_id = $2,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, metadata, created_at, updated_at;
|
||||
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at;
|
||||
|
||||
-- name: UpdateBotStatus :exec
|
||||
UPDATE bots
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
-- name: CreateSearchProvider :one
|
||||
INSERT INTO search_providers (name, provider, config)
|
||||
VALUES (
|
||||
sqlc.arg(name),
|
||||
sqlc.arg(provider),
|
||||
sqlc.arg(config)
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetSearchProviderByID :one
|
||||
SELECT * FROM search_providers WHERE id = sqlc.arg(id);
|
||||
|
||||
-- name: GetSearchProviderByName :one
|
||||
SELECT * FROM search_providers WHERE name = sqlc.arg(name);
|
||||
|
||||
-- name: ListSearchProviders :many
|
||||
SELECT * FROM search_providers
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: ListSearchProvidersByProvider :many
|
||||
SELECT * FROM search_providers
|
||||
WHERE provider = sqlc.arg(provider)
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: UpdateSearchProvider :one
|
||||
UPDATE search_providers
|
||||
SET
|
||||
name = sqlc.arg(name),
|
||||
provider = sqlc.arg(provider),
|
||||
config = sqlc.arg(config),
|
||||
updated_at = now()
|
||||
WHERE id = sqlc.arg(id)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteSearchProvider :exec
|
||||
DELETE FROM search_providers WHERE id = sqlc.arg(id);
|
||||
+10
-4
@@ -6,11 +6,13 @@ SELECT
|
||||
bots.allow_guest,
|
||||
chat_models.model_id AS chat_model_id,
|
||||
memory_models.model_id AS memory_model_id,
|
||||
embedding_models.model_id AS embedding_model_id
|
||||
embedding_models.model_id AS embedding_model_id,
|
||||
search_providers.id::text AS search_provider_id
|
||||
FROM bots
|
||||
LEFT JOIN models AS chat_models ON chat_models.id = bots.chat_model_id
|
||||
LEFT JOIN models AS memory_models ON memory_models.id = bots.memory_model_id
|
||||
LEFT JOIN models AS embedding_models ON embedding_models.id = bots.embedding_model_id
|
||||
LEFT JOIN search_providers ON search_providers.id = bots.search_provider_id
|
||||
WHERE bots.id = $1;
|
||||
|
||||
-- name: UpsertBotSettings :one
|
||||
@@ -22,9 +24,10 @@ WITH updated AS (
|
||||
chat_model_id = COALESCE(sqlc.narg(chat_model_id)::uuid, bots.chat_model_id),
|
||||
memory_model_id = COALESCE(sqlc.narg(memory_model_id)::uuid, bots.memory_model_id),
|
||||
embedding_model_id = COALESCE(sqlc.narg(embedding_model_id)::uuid, bots.embedding_model_id),
|
||||
search_provider_id = COALESCE(sqlc.narg(search_provider_id)::uuid, bots.search_provider_id),
|
||||
updated_at = now()
|
||||
WHERE bots.id = sqlc.arg(id)
|
||||
RETURNING bots.id, bots.max_context_load_time, bots.language, bots.allow_guest, bots.chat_model_id, bots.memory_model_id, bots.embedding_model_id
|
||||
RETURNING bots.id, bots.max_context_load_time, bots.language, bots.allow_guest, bots.chat_model_id, bots.memory_model_id, bots.embedding_model_id, bots.search_provider_id
|
||||
)
|
||||
SELECT
|
||||
updated.id AS bot_id,
|
||||
@@ -33,11 +36,13 @@ SELECT
|
||||
updated.allow_guest,
|
||||
chat_models.model_id AS chat_model_id,
|
||||
memory_models.model_id AS memory_model_id,
|
||||
embedding_models.model_id AS embedding_model_id
|
||||
embedding_models.model_id AS embedding_model_id,
|
||||
search_providers.id::text AS search_provider_id
|
||||
FROM updated
|
||||
LEFT JOIN models AS chat_models ON chat_models.id = updated.chat_model_id
|
||||
LEFT JOIN models AS memory_models ON memory_models.id = updated.memory_model_id
|
||||
LEFT JOIN models AS embedding_models ON embedding_models.id = updated.embedding_model_id;
|
||||
LEFT JOIN models AS embedding_models ON embedding_models.id = updated.embedding_model_id
|
||||
LEFT JOIN search_providers ON search_providers.id = updated.search_provider_id;
|
||||
|
||||
-- name: DeleteSettingsByBotID :exec
|
||||
UPDATE bots
|
||||
@@ -47,5 +52,6 @@ SET max_context_load_time = 1440,
|
||||
chat_model_id = NULL,
|
||||
memory_model_id = NULL,
|
||||
embedding_model_id = NULL,
|
||||
search_provider_id = NULL,
|
||||
updated_at = now()
|
||||
WHERE id = $1;
|
||||
|
||||
Reference in New Issue
Block a user