V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
cgsv

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

  •  
  •   cgsv · Mar 11, 2023 · 1661 views
    This topic created in 1151 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   ·   2483 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 15:40 · PVG 23:40 · LAX 08:40 · JFK 11:40
    ♥ Do have faith in what you're doing.