mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 06:49:54 +08:00
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { apiUrl } from "@/lib/api";
|
|
import { invalidateClientCache, withClientCache } from "@/lib/client-cache";
|
|
|
|
const KNOWLEDGE_CACHE_PREFIX = "knowledge:";
|
|
|
|
export interface KnowledgeBaseSummary {
|
|
name: string;
|
|
is_default?: boolean;
|
|
status?: string;
|
|
progress?: Record<string, unknown>;
|
|
statistics?: Record<string, unknown>;
|
|
}
|
|
|
|
export interface RagProviderSummary {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
}
|
|
|
|
export async function listKnowledgeBases(options?: { force?: boolean }) {
|
|
return withClientCache<KnowledgeBaseSummary[]>(
|
|
`${KNOWLEDGE_CACHE_PREFIX}list`,
|
|
async () => {
|
|
const response = await fetch(apiUrl("/api/v1/knowledge/list"), {
|
|
cache: "no-store",
|
|
});
|
|
const data = await response.json();
|
|
return Array.isArray(data)
|
|
? data
|
|
: Array.isArray(data?.knowledge_bases)
|
|
? data.knowledge_bases
|
|
: [];
|
|
},
|
|
{
|
|
force: options?.force,
|
|
},
|
|
);
|
|
}
|
|
|
|
export async function listRagProviders(options?: { force?: boolean }) {
|
|
return withClientCache<RagProviderSummary[]>(
|
|
`${KNOWLEDGE_CACHE_PREFIX}providers`,
|
|
async () => {
|
|
const response = await fetch(apiUrl("/api/v1/knowledge/rag-providers"), {
|
|
cache: "no-store",
|
|
});
|
|
const data = await response.json();
|
|
return Array.isArray(data?.providers) ? data.providers : [];
|
|
},
|
|
{
|
|
force: options?.force,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function invalidateKnowledgeCaches() {
|
|
invalidateClientCache(KNOWLEDGE_CACHE_PREFIX);
|
|
}
|