Skip to content

Commit

Permalink
Merge pull request #959 from jboolean/upgrade-openai-model
Browse files Browse the repository at this point in the history
Convert from deprecated completions to new chat completions api
  • Loading branch information
jboolean authored Jan 10, 2024
2 parents 85a3ac6 + 08f3e07 commit 63a253f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 23 deletions.
4 changes: 2 additions & 2 deletions backend/src/business/ai/AiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const openai = new OpenAI({
});

export async function suggestStoryTitle(storyContent: string): Promise<string> {
const response = await openai.completions.create(
const response = await openai.chat.completions.create(
createStoryTitlePrompt(storyContent)
);

return response.choices[0].text?.trim() ?? '';
return response.choices[0].message.content?.trim() ?? '';
}
71 changes: 50 additions & 21 deletions backend/src/business/ai/createStoryTitlePrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,59 @@ import OpenAI from 'openai';

export default function createStoryTitlePrompt(
storyContent: string
): OpenAI.CompletionCreateParamsNonStreaming {
): OpenAI.ChatCompletionCreateParamsNonStreaming {
return {
model: 'text-davinci-003',
prompt: `Create a very short caption for each story
Story: I lived in the building with the peak from my birth in 1948 until I was 13 in 1961, with my parents and siblings. The 3 windows right above the Bohack sign were in my parents bedroom. My fathers parents and my aunts and uncles lived on Grattan St in various apartments over the years. Those are the buildings to the left of my house. Very sad to see it now.
Caption: My childhood home
Story: The Tepedino's, Michael and Angelina. ITALIAN immigrants from the Salerno area of Italy raised 3 children in this home.
Caption: Italian immigrants raised family
Story: The plaza hotel
Caption: Plaza Hotel
Story: That's old man Saso sitting on the stoop of 35 Snediker ave. He sat there every day for years.
Caption: Man sat daily on stoop
Story: ${storyContent.replaceAll('\n', ' ').trim()}
Caption:`,
temperature: 0.1,
max_tokens: 11,
model: 'gpt-4',
messages: [
{
role: 'system',
content:
'You turn stories into captions. User input is a story about an old photo of a building in NYC. You respond with no more than 6 words to caption the story or label the map marker for the place. Personality: charming, curious, catchy, succinct. \nRespond with NO surrounding quotes.',
},
{
role: 'user',
content:
'I lived in the building with the peak from my birth in 1948 until I was 13 in 1961, with my parents and siblings. The 3 windows right above the Bohack sign were in my parents bedroom. My fathers parents and my aunts and uncles lived on Grattan St in various apartments over the years. Those are the buildings to the left of my house. Very sad to see it now.',
},
{
role: 'assistant',
content: 'My childhood home',
},
{
role: 'user',
content:
"The Tepedino's, Michael and Angelina. ITALIAN immigrants from the Salerno area of Italy raised 3 children in this home.",
},
{
role: 'assistant',
content: 'Italian immigrants raised family',
},
{
role: 'user',
content: 'The plaza hotel',
},
{
role: 'assistant',
content: 'Plaza Hotel',
},
{
role: 'user',
content:
"That's old man Saso sitting on the stoop of 35 Snediker ave. He sat there every day for years.",
},
{
role: 'assistant',
content: 'Man sat daily on stoop',
},
{
role: 'user',
content: storyContent,
},
],
temperature: 0.2,
max_tokens: 15,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
stop: ['\n'],
};
}

0 comments on commit 63a253f

Please sign in to comment.