This commit is contained in:
hailin 2025-05-28 10:42:01 +08:00
parent adceadc16c
commit b7e53489d2
3 changed files with 34 additions and 15 deletions

View File

@ -1,4 +1,5 @@
import { generateLocalEmbedding } from "@/lib/generate-local-embedding"
import { generateBgeM3Embedding } from "@lib/generate-bgem3-embedding"
import {
processCSV,
processJSON,
@ -138,9 +139,17 @@ export async function POST(req: Request) {
embeddings = await Promise.all(embeddingPromises)
} else if (embeddingsProvider === "bge-m3"){
// 示例:调用你自己的 BGE-M3 API 或本地函数
const embeddingPromises = chunks.map(async chunk => {
try {
return await generateBgeM3Embedding(chunk.content)
} catch (error) {
console.error(`Error generating BGE-M3 embedding for chunk: ${chunk}`, error)
return null
}
})
embeddings = await Promise.all(embeddingPromises)
}
const file_items = chunks.map((chunk, index) => ({
file_id,
user_id: profile.user_id,
@ -154,7 +163,11 @@ export async function POST(req: Request) {
embeddingsProvider === "local"
? ((embeddings[index] || null) as any)
: null
}))
bge_m3_embedding:
embeddingsProvider === "bge-m3"
? (embeddings[index] || null) as any)
: null
})
await supabaseAdmin.from("file_items").upsert(file_items)

View File

@ -0,0 +1,19 @@
async function generateBgeM3Embedding(text: string): Promise<number[] | null> {
try {
const response = await fetch("http://localhost:8000/embedding", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ input: text })
})
if (!response.ok) {
throw new Error(`Failed to fetch BGE-M3 embedding: ${response.status}`)
}
const result = await response.json()
return result.embedding as number[]
} catch (err) {
console.error("Error in generateBgeM3Embedding:", err)
return null
}
}

View File

@ -7,19 +7,6 @@ import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
export async function getServerProfile() {
// const cookieStore = cookies()
// const supabase = createServerClient<Database>(
// getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
// process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
// {
// cookies: {
// get(name: string) {
// return cookieStore.get(name)?.value
// }
// }
// }
// )
const supabase = getSupabaseServerClient()
const user = (await supabase.auth.getUser()).data.user