Skip to content

Commit

Permalink
update deprecated davinci model
Browse files Browse the repository at this point in the history
  • Loading branch information
maidi29 committed Dec 9, 2023
1 parent 589b9a8 commit fd07c8f
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 150 deletions.
15 changes: 7 additions & 8 deletions controllers/OpenAiController.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
const { Configuration, OpenAIApi } = require("openai");
import OpenAI from "openai";

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY, // This is also the default, can be omitted
});
const openai = new OpenAIApi(configuration);

module.exports.generate = async (
randomSongName: string,
moods: string,
name: string,
res
): Promise<{ diaryEntry: string; imageUrl: string }> => {
if (!configuration.apiKey) {
if (!openai.apiKey) {
res.status(500).json({
error: {
message: "OpenAI API key not configured.",
Expand All @@ -21,13 +20,13 @@ module.exports.generate = async (
}

try {
let diaryEntry = await openai.createCompletion({
model: "text-davinci-003",
const completion = await openai.completions.create({
model: "gpt-3.5-turbo-instruct",
prompt: generateDiaryEntryPrompt(moods),
temperature: 1,
max_tokens: 2048,
});
diaryEntry = diaryEntry.data.choices[0].text.replace(
let diaryEntry = completion.choices[0].text.replace(
/xxx/gi,
`${name.split(" ")[0]}`
);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Book.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export default {
width: 80%;
margin: 1.5rem auto;
font-family: theme.$font-family-hand;
font-size: 1.75rem;
word-wrap: break-word;
@media (max-width: 767px) {
margin-top: calc(var(--corner-size) / 2);
Expand Down
Loading

0 comments on commit fd07c8f

Please sign in to comment.