Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update openai.ts #885

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const configuration = new Configuration({
basePath: config.api,
});
const openai = new OpenAIApi(configuration);

console.log("结构判断0");
/**
* Get completion from OpenAI
* @param username
* @param message
*/
async function chatgpt(username:string,message: string): Promise<string> {
// 先将用户输入的消息添加到数据库中
console.log("结构判断1");
DBUtils.addUserMessage(username, message);
const messages = DBUtils.getChatMessage(username);
const response = await openai.createChatCompletion({
Expand Down Expand Up @@ -49,7 +50,8 @@ async function chatgpt(username:string,message: string): Promise<string> {
* @param prompt
*/
async function dalle(username:string,prompt: string) {
const response = await openai.createImage({
console.log("结构判断2");
const response = awai openai.createImage({
prompt: prompt,
n:1,
size: CreateImageRequestSizeEnum._256x256,
Expand All @@ -69,6 +71,7 @@ async function dalle(username:string,prompt: string) {
* @param videoPath
*/
async function whisper(username:string,videoPath: string): Promise<string> {
console.log("结构判断3");
const file:any= fs.createReadStream(videoPath);
const response = await openai.createTranscription(file,"whisper-1")
.then((res) => res.data).catch((err) => console.log(err));
Expand All @@ -79,4 +82,4 @@ async function whisper(username:string,videoPath: string): Promise<string> {
}
}

export {chatgpt,dalle,whisper};
export {chatgpt,dalle,whisper};