This commit is contained in:
parent
10fa1637ea
commit
b1ce04b5d6
|
|
@ -16,6 +16,7 @@ import OpenAI from "openai"
|
||||||
import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
|
import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
|
console.log("......[process] Starting file processing request")
|
||||||
try {
|
try {
|
||||||
const supabaseAdmin = createClient<Database>(
|
const supabaseAdmin = createClient<Database>(
|
||||||
getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
|
getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
|
||||||
|
|
@ -88,6 +89,7 @@ export async function POST(req: Request) {
|
||||||
chunks = await processMarkdown(blob)
|
chunks = await processMarkdown(blob)
|
||||||
break
|
break
|
||||||
case "pdf":
|
case "pdf":
|
||||||
|
console.log("......[process] Processing PDF...")
|
||||||
chunks = await processPdf(blob)
|
chunks = await processPdf(blob)
|
||||||
break
|
break
|
||||||
case "txt":
|
case "txt":
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ export const createFile = async (
|
||||||
} else {
|
} else {
|
||||||
fileRecord.name = baseName + "." + extension
|
fileRecord.name = baseName + "." + extension
|
||||||
}
|
}
|
||||||
|
console.log("......[createFile] Inserting file record:", fileRecord);
|
||||||
const { data: createdFile, error } = await supabase
|
const { data: createdFile, error } = await supabase
|
||||||
.from("files")
|
.from("files")
|
||||||
.insert([fileRecord])
|
.insert([fileRecord])
|
||||||
|
|
@ -119,7 +119,7 @@ export const createFile = async (
|
||||||
file_id: createdFile.id,
|
file_id: createdFile.id,
|
||||||
workspace_id
|
workspace_id
|
||||||
})
|
})
|
||||||
|
console.log("......[createFile] Uploading file to storage:", createdFile.name);
|
||||||
const filePath = await uploadFile(file, {
|
const filePath = await uploadFile(file, {
|
||||||
name: createdFile.name,
|
name: createdFile.name,
|
||||||
user_id: createdFile.user_id,
|
user_id: createdFile.user_id,
|
||||||
|
|
@ -134,11 +134,20 @@ export const createFile = async (
|
||||||
formData.append("file_id", createdFile.id)
|
formData.append("file_id", createdFile.id)
|
||||||
formData.append("embeddingsProvider", embeddingsProvider)
|
formData.append("embeddingsProvider", embeddingsProvider)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`......[createFile] Sending process request for file ${createdFile.id}, provider: ${embeddingsProvider}`
|
||||||
|
);
|
||||||
|
|
||||||
const response = await fetch("/api/retrieval/process", {
|
const response = await fetch("/api/retrieval/process", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`......[createFile] /api/retrieval/process responded status=${response.status}`
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const jsonText = await response.text()
|
const jsonText = await response.text()
|
||||||
const json = JSON.parse(jsonText)
|
const json = JSON.parse(jsonText)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ export async function generateBgeM3Embedding(text: string): Promise<number[] | n
|
||||||
const { protocol, host } = window.location;
|
const { protocol, host } = window.location;
|
||||||
const hostname = host.split(":")[0];
|
const hostname = host.split(":")[0];
|
||||||
const apiUrl = `${protocol}//${hostname}:8001/v1/embeddings`;
|
const apiUrl = `${protocol}//${hostname}:8001/v1/embeddings`;
|
||||||
|
console.log("......generateBgeM3Embedding", apiUrl);
|
||||||
const response = await fetch(apiUrl, {
|
const response = await fetch(apiUrl, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue