cgsv

分享一个 TS 写的 openai 接口中转

  •  
  •   cgsv · Mar 11, 2023 · 1771 views
    This topic created in 1196 days ago, the information mentioned may be changed or developed.

    本来想直接在 这个 贴子下回复,但评论区不支持 markdown ,就新开一个吧,有需要的可以直接拿去用,可以直接上 deno deploy 部署

    // proxy.ts
    import { serve } from "https://deno.land/[email protected]/http/server.ts";
    
    async function handler(req: Request) {
      const url = req.url.replace(/^https?:\/\/[^/]*/, "https://api.openai.com")
      return await fetch(url, req);
    }
    
    console.log("Listening on http://localhost:8000");
    serve(handler, {port: 8000});
    

    本地执行,调用时直接把 openai 那段域名换成你部署的域名即可

    deno run --allow-net proxy.ts

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2545 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 617ms · UTC 12:19 · PVG 20:19 · LAX 05:19 · JFK 08:19
    ♥ Do have faith in what you're doing.