This commit is contained in:
hailin 2025-05-28 22:22:18 +08:00
parent 285ac31ceb
commit 467884c0df
1 changed files with 10 additions and 5 deletions

View File

@ -1,10 +1,15 @@
import { getRuntimeEnv } from "@/lib/ipconfig"
export async function generateBgeM3Embedding(text: string): Promise<number[] | null> {
try {
// 动态获取当前协议和主机(不含端口),然后指定后端端口 8001
const { protocol, host } = window.location;
const hostname = host.split(":")[0];
const apiUrl = `${protocol}//${hostname}:8001/v1/embeddings`;
console.log("......generateBgeM3Embedding", apiUrl);
// 取 Supabase URL 或本地默认
const supaUrl = getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000"
// 构造 Embedding 服务地址:同 host + 8001 端口
const urlObj = new URL(supaUrl)
urlObj.port = "8001" // 强制改成 8001
const apiUrl = `${urlObj.origin}/v1/embeddings`
console.debug("......[generateBgeM3Embedding] apiUrl =", apiUrl)
const response = await fetch(apiUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },