-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: activate licenseKey after used
- Loading branch information
Showing
4 changed files
with
42 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function formatResult(result: any) { | ||
const answer = result.choices[0].message?.content || ""; | ||
if (answer.startsWith("\n\n")) { | ||
return answer.substring(2); | ||
} | ||
return answer; | ||
} |
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,23 @@ | ||
import { activateLicenseKey } from "~/lib/lemon"; | ||
import { checkOpenaiApiKeys } from "~/lib/openai/openai"; | ||
import { sample } from "~/utils/fp"; | ||
|
||
export async function selectApiKey(apiKey: string | undefined) { | ||
if (apiKey) { | ||
if (checkOpenaiApiKeys(apiKey)) { | ||
const userApiKeys = apiKey.split(","); | ||
return sample(userApiKeys); | ||
} | ||
|
||
// user is using validated licenseKey | ||
const activated = await activateLicenseKey(apiKey); | ||
if (!activated) { | ||
throw new Error("licenseKey is not validated!"); | ||
} | ||
} | ||
|
||
// don't need to validate anymore, already verified in middleware? | ||
const myApiKeyList = process.env.OPENAI_API_KEY; | ||
const luckyApiKey = sample(myApiKeyList?.split(",")); | ||
return luckyApiKey || ""; | ||
} |
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
682d0c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
chat-bilibili-video – ./
chat-bilibili-video.vercel.app
chat-bilibili-video-git-main-jimmylv.vercel.app
b.jimmylv.cn
chat-bilibili-video-jimmylv.vercel.app
m.bilibili.jimmylv.cn
bilibili.jimmylv.cn
www.bilibili.jimmylv.cn