You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
989 B
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { Configuration, OpenAIApi } from "openai";
const params = {
organization: "org-ew4m4pHcq5yYaTGF4VtbSMGH",
apiKey: "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",
// organization: "YOUR OWN ORGANIZATION HERE",
// apiKey: "YOUR OWN APIKEY HERE",
};
export const OpenAIService = async () => {
const config = new Configuration(params);
const openai = new OpenAIApi(config);
return {
openai,
getPrompts: async (keywords: string[]) => {
const resp = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{
role: "user",
content: `我想用NovelAI生成一张${keywords.join(
","
)}画像请为我生成不少于20个提示词请使用英文表示。`,
},
],
});
const content = resp.data.choices[0].message?.content;
const prompts = content?.replace(/\d|\./g, "").split("\n");
return prompts;
},
};
};