This commit is contained in:
parent
adceadc16c
commit
b7e53489d2
|
|
@ -1,4 +1,5 @@
|
||||||
import { generateLocalEmbedding } from "@/lib/generate-local-embedding"
|
import { generateLocalEmbedding } from "@/lib/generate-local-embedding"
|
||||||
|
import { generateBgeM3Embedding } from "@lib/generate-bgem3-embedding"
|
||||||
import {
|
import {
|
||||||
processCSV,
|
processCSV,
|
||||||
processJSON,
|
processJSON,
|
||||||
|
|
@ -138,9 +139,17 @@ export async function POST(req: Request) {
|
||||||
embeddings = await Promise.all(embeddingPromises)
|
embeddings = await Promise.all(embeddingPromises)
|
||||||
} else if (embeddingsProvider === "bge-m3"){
|
} else if (embeddingsProvider === "bge-m3"){
|
||||||
// 示例:调用你自己的 BGE-M3 API 或本地函数
|
// 示例:调用你自己的 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) => ({
|
const file_items = chunks.map((chunk, index) => ({
|
||||||
file_id,
|
file_id,
|
||||||
user_id: profile.user_id,
|
user_id: profile.user_id,
|
||||||
|
|
@ -154,7 +163,11 @@ export async function POST(req: Request) {
|
||||||
embeddingsProvider === "local"
|
embeddingsProvider === "local"
|
||||||
? ((embeddings[index] || null) as any)
|
? ((embeddings[index] || null) as any)
|
||||||
: null
|
: null
|
||||||
}))
|
bge_m3_embedding:
|
||||||
|
embeddingsProvider === "bge-m3"
|
||||||
|
? (embeddings[index] || null) as any)
|
||||||
|
: null
|
||||||
|
})
|
||||||
|
|
||||||
await supabaseAdmin.from("file_items").upsert(file_items)
|
await supabaseAdmin.from("file_items").upsert(file_items)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,19 +7,6 @@ import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
|
||||||
|
|
||||||
export async function getServerProfile() {
|
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 supabase = getSupabaseServerClient()
|
||||||
|
|
||||||
const user = (await supabase.auth.getUser()).data.user
|
const user = (await supabase.auth.getUser()).data.user
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue