openweb-ui配置Rag后无法上传文件,好像是反代的问题

openweb-ui上传文件求助
配置了rag模型就无法读取文件,一直转圈
上传文件无法解析


看后台报

INFO:     x.x.x.x:0 - "POST /api/v1/files/ HTTP/1.1" 422 Unprocessable Entity
14 个赞

我用官方key 没问题

没遇到这个问题

我使用了这个佬友的反代,就会出现这个问题,用CF进行反代也不会出现这个问题

重新写了一个,你拿去试试。

import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";

const DEFAULT_PORT = 8080;
const TARGET_HOST = "open-webui-open-webui.hf.space";

function log(message: string) {
  console.log(`[${new Date().toISOString()}] ${message}`);
}

function getDefaultUserAgent(isMobile: boolean = false): string {
  if (isMobile) {
    return "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36";
  } else {
    return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
  }
}

function transformHeaders(headers: Headers): Headers {
  const isMobile = headers.get("sec-ch-ua-mobile") === "?1";
  const newHeaders = new Headers();

  for (const [key, value] of headers.entries()) {
    newHeaders.set(key, value);
  }

  newHeaders.set("User-Agent", getDefaultUserAgent(isMobile));
  newHeaders.set("Host", TARGET_HOST);
  newHeaders.set("Origin", `https://${TARGET_HOST}`);

  return newHeaders;
}

async function handleRequest(req: Request): Promise<Response> {
  try {
    const url = new URL(req.url);
    const targetUrl = `https://${TARGET_HOST}${url.pathname}${url.search}`;
    log(`Proxying request: ${targetUrl}`);

    const proxyReq = new Request(targetUrl, {
      method: req.method,
      headers: transformHeaders(req.headers),
      body: req.body,
      redirect: "follow",
    });

    const response = await fetch(proxyReq);

    const responseHeaders = new Headers(response.headers);
    responseHeaders.set("Access-Control-Allow-Origin", "*");

    return new Response(response.body, {
      status: response.status,
      headers: responseHeaders,
    });
  } catch (error) {
    log(`Error: ${error.message}`);
    return new Response(`Proxy Error: ${error.message}`, { status: 500 });
  }
}

async function startServer(port: number) {
  log(`Starting proxy server on port ${port}`);

  await serve(handleRequest, {
    port,
    onListen: () => {
      log(`Listening on http://localhost:${port}`);
    },
  });
}

if (import.meta.main) {
  const { args } = Deno;
  const parsedArgs = parse(args);

  const port = parsedArgs.port ? Number(parsedArgs.port) : DEFAULT_PORT;

  startServer(port);
}
4 个赞

要是还有问题,请把日志贴出来,我会继续改进。

1 个赞

感谢大佬,解决了