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

Hacky temporary migration to GPT 4O-Mini #820

Merged
merged 7 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
60 changes: 8 additions & 52 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"node-os-utils": "^1.3.7",
"objection": "^3.1.3",
"octokit": "^3.1.2",
"openai": "^4.25.0",
"openai": "^4.53.2",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency update -
PR updated From 4.25 to 4.53

"rollbar": "^2.26.2",
"rss-parser": "^3.13.0",
"source-map-support": "^0.5.21",
Expand Down Expand Up @@ -130,4 +130,4 @@
"tsc-watch": "^6.0.4",
"typescript": "^5.3.3"
}
}
}
6 changes: 3 additions & 3 deletions src/discord/commands/global/d.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const tripbotUAT = '@TripBot UAT (Moonbear)';

// Costs per 1k tokens
const aiCosts = {
GPT_3_5_TURBO: {
input: 0.0005,
output: 0.0015,
GPT_3_5_TURBO: { // LAZY TEMP FIX - CHANGE NAME THESE PRICES ARE FOR 4o MINI NOW
input: 0.0015,
output: 0.0060,
},
// GPT_3_5_TURBO_1106: {
// input: 0.001,
Expand Down
21 changes: 11 additions & 10 deletions src/global/commands/g.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import OpenAI from 'openai';
import { ai_personas } from '@prisma/client';
import { ImagesResponse, ModerationCreateResponse } from 'openai/resources';
import { Assistant } from 'openai/resources/beta/assistants/assistants';
import { Assistant } from 'openai/resources/beta/assistants';
import { ThreadDeleted } from 'openai/resources/beta/threads/threads';
import { MessageContentText } from 'openai/resources/beta/threads/messages/messages';
import { TextContentBlock } from 'openai/resources/beta/threads/messages';
import {
GoogleGenerativeAI, HarmCategory, HarmBlockThreshold, GenerationConfig, SafetySetting, Part, InputContent,
GenerateContentResult,
Expand Down Expand Up @@ -99,7 +99,7 @@ const aiFunctions = [
},
},
},
] as Assistant.Function[];
];

export async function aiModerateReport(
message: string,
Expand Down Expand Up @@ -139,8 +139,9 @@ export async function getAssistant(name: string):Promise<Assistant> {
name,
},
});

const modelName = personaData.ai_model.toLowerCase() === 'gpt_3_5_turbo' ? 'gpt-3.5-turbo-1106' : 'gpt-4-turbo-preview';
// LAZY TEMP FIX
// eslint-disable-next-line sonarjs/no-all-duplicated-branches
const modelName = personaData.ai_model.toLowerCase() === 'gpt-3.5-turbo-1106' ? 'gpt-4o-mini' : 'gpt-4o-mini';

// Upload a file with an "assistants" purpose
// const combinedDb = await openAi.files.create({
Expand All @@ -153,13 +154,13 @@ export async function getAssistant(name: string):Promise<Assistant> {
model: modelName,
name: personaData.name,
description: personaData.description,
instructions: `${objectiveTruths}\n${personaData.prompt}`,
instructions: `${objectiveTruths}\n${personaData.prompt}`, // LAZY TEMP FIX. https://platform.openai.com/docs/assistants/migration/what-has-changed - UPDATE to version 4.52.7 in package.json
tools: [
// { type: 'code_interpreter' },
// { type: 'retrieval' },
// ...aiFunctions,
],
file_ids: [],
// file_ids: [],
metadata: {},
} as Omit<Assistant, 'id' | 'created_at' | 'object'>;

Expand Down Expand Up @@ -536,7 +537,7 @@ async function openAiWaitForRun(
await openAi.beta.threads.messages.list(thread.id, { limit: 1 })
).data[0].content[0];
// log.debug(F, `messageContent: ${JSON.stringify(messageContent, null, 2)}`);
return { response: (messageContent as MessageContentText).text.value.slice(0, 2000), promptTokens, completionTokens };
return { response: (messageContent as TextContentBlock).text.value.slice(0, 2000), promptTokens, completionTokens };
}
case 'requires_action': {
log.debug(F, 'requires_action');
Expand Down Expand Up @@ -757,7 +758,7 @@ async function openAiChat(
let model = aiPersona.ai_model.toLowerCase();
// Convert ai models into proper names
if (aiPersona.ai_model === 'GPT_3_5_TURBO') {
model = 'gpt-3.5-turbo-1106';
model = 'gpt-4o-mini'; // LAZY TEMP FIX
}

// This message list is sent to the API
Expand Down Expand Up @@ -906,7 +907,7 @@ export async function aiFlairMod(
let model = aiPersona.ai_model.toLowerCase();
// Convert ai models into proper names
if (aiPersona.ai_model === 'GPT_3_5_TURBO') {
model = 'gpt-3.5-turbo-1106';
model = 'gpt-4o-mini'; // LAZY TEMP FIX
}
// This message list is sent to the API
const chatCompletionMessages = [{
Expand Down
Loading