Skip to content

Commit

Permalink
Merge pull request #344 from MikelCalvo/feature/openai_migration_to_v4
Browse files Browse the repository at this point in the history
Migrated openai to v4
  • Loading branch information
MikelCalvo authored Aug 1, 2024
2 parents 8a2faa0 + 0c2660d commit 0e0d2ec
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
50 changes: 44 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"fetch-blob": "^4.0.0",
"ffmpeg": "^0.0.4",
"langchain": "^0.0.156",
"openai": "^3.3.0",
"openai": "^4.52.1",
"picocolors": "^1.0.0",
"qrcode": "^1.5.3",
"whatsapp-web.js": "https://github.com/Julzk/whatsapp-web.js/tarball/jkr_hotfix_7"
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/dalle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MessageMedia } from "whatsapp-web.js";
import { openai } from "../providers/openai";
import { aiConfig } from "../handlers/ai-config";
import { CreateImageRequestSizeEnum } from "openai";
import OpenAI from "openai";
import config from "../config";
import * as cli from "../cli/ui";

Expand All @@ -25,7 +25,7 @@ const handleMessageDALLE = async (message: any, prompt: any) => {
}

// Send the prompt to the API
const response = await openai.createImage({
const response = await openai.images.generate({
prompt: prompt,
n: 1,
size: aiConfig.dalle.size as CreateImageRequestSizeEnum,
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { openai } from "../providers/openai";
*/
const moderateIncomingPrompt = async (prompt: string) => {
cli.print("[MODERATION] Checking user prompt...");
const moderationResponse = await openai.createModeration({
const moderationResponse = await openai.moderations.create({
input: prompt
});

Expand Down
10 changes: 5 additions & 5 deletions src/providers/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from "os";
import path from "path";
import { randomUUID } from "crypto";
import { ChatGPTAPI } from "chatgpt";
import { Configuration, OpenAIApi } from "openai";
import OpenAI from "openai";

import ffmpeg from "fluent-ffmpeg";
import { blobFromSync, File } from "fetch-blob/from.js";
Expand All @@ -13,7 +13,7 @@ import { getConfig } from "../handlers/ai-config";
export let chatgpt: ChatGPTAPI;

// OpenAI Client (DALL-E)
export let openai: OpenAIApi;
export let openai: OpenAI;

export function initOpenAI() {
chatgpt = new ChatGPTAPI({
Expand All @@ -26,10 +26,10 @@ export function initOpenAI() {
}
});

openai = new OpenAIApi(
new Configuration({
openai = new OpenAI(
{
apiKey: getConfig("gpt", "apiKey")
})
}
);
}

Expand Down

0 comments on commit 0e0d2ec

Please sign in to comment.