forked from ChatGPTNextWeb/NextChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: close ChatGPTNextWeb#2 add check account balance
- Loading branch information
Showing
14 changed files
with
245 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NextRequest } from "next/server"; | ||
|
||
const OPENAI_URL = "api.openai.com"; | ||
const DEFAULT_PROTOCOL = "https"; | ||
const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL; | ||
const BASE_URL = process.env.BASE_URL ?? OPENAI_URL; | ||
|
||
export async function requestOpenai(req: NextRequest) { | ||
const apiKey = req.headers.get("token"); | ||
const openaiPath = req.headers.get("path"); | ||
|
||
console.log("[Proxy] ", openaiPath); | ||
|
||
return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
method: req.method, | ||
body: req.body, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { requestOpenai } from "../common"; | ||
|
||
async function makeRequest(req: NextRequest) { | ||
try { | ||
const res = await requestOpenai(req); | ||
return new Response(res.body); | ||
} catch (e) { | ||
console.error("[OpenAI] ", req.body, e); | ||
return NextResponse.json( | ||
{ | ||
error: true, | ||
msg: JSON.stringify(e), | ||
}, | ||
{ | ||
status: 500, | ||
}, | ||
); | ||
} | ||
} | ||
|
||
export async function POST(req: NextRequest) { | ||
return makeRequest(req); | ||
} | ||
|
||
export async function GET(req: NextRequest) { | ||
return makeRequest(req); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.