diff options
Diffstat (limited to 'src/client/apis/gpt/GPT.ts')
-rw-r--r-- | src/client/apis/gpt/GPT.ts | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts index 7878e9bfe..af9cdd2d1 100644 --- a/src/client/apis/gpt/GPT.ts +++ b/src/client/apis/gpt/GPT.ts @@ -11,10 +11,12 @@ export enum GPTDocCommand { export const DescriptionSeperator = '======'; export const DocSeperator = '------'; +export const DataSeperator = '>>>>>>'; export enum TextClassifications { - Title = 'word', //a few words + Title = 'word', //a few words Caption = 'sentence', //few sentences - LengthyDescription = 'paragraphs' } + LengthyDescription = 'paragraphs', +} enum GPTCallType { SUMMARY = 'summary', @@ -38,11 +40,12 @@ enum GPTCallType { MAKERUBRIC = 'make_rubric', // create a definition rubric for a document to be used when quizzing the user COMMANDTYPE = 'command_type', // Determine the type of command being made (GPTQueryType - eg., AssignTags, Sort, Filter, DocInfo, GenInfo) and possibly some parameters (eg, Tag type for Tags) SUBSETDOCS = 'subset_docs', // select a subset of documents based on their descriptions + TAGDOCS = 'tag_docs', // choose a tags for each Doc DOCINFO = 'doc_info', // provide information about a document SORTDOCS = 'sort_docs', CLASSIFYTEXTMINIMAL = 'classify_text_minimal', // classify text into one of the three categories: title, caption, lengthy description CLASSIFYTEXTFULL = 'classify_text_full', //tags pdf content - GENERATESCRAPBOOK = 'generate_scrapbook' + GENERATESCRAPBOOK = 'generate_scrapbook', } type GPTCallOpts = { @@ -55,14 +58,12 @@ type GPTCallOpts = { const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = { // newest model: gpt-4 summary: { model: 'gpt-4-turbo', maxTokens: 256, temp: 0.5, prompt: 'Summarize the text given in simpler terms.' }, - - + sort_docs: { model: 'gpt-4o', maxTokens: 2048, temp: 0.25, - prompt: - `The user is going to give you a list of descriptions. + prompt: `The user is going to give you a list of descriptions. Each one is separated by '${DescriptionSeperator}' on either side. Descriptions will vary in length, so make sure to only separate when you see '${DescriptionSeperator}'. Sort them by the user's specifications. @@ -71,7 +72,6 @@ const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = { It is VERY important that you format it exactly as described, ensuring the proper number of '${DescriptionSeperator[0]}' and '${DocSeperator[0]}' (${DescriptionSeperator.length} of each) and NO commas`, }, - edit: { model: 'gpt-4-turbo', maxTokens: 256, temp: 0.5, prompt: 'Reword the text.' }, stack: { model: 'gpt-4o', @@ -100,7 +100,7 @@ const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = { temp: 0.25, prompt: `Based on the content of the the text, classify it into the most appropriate category: '${TextClassifications.Title}' if it is a few words, '${TextClassifications.Caption}' if it is a couple sentences or less, or '${TextClassifications.LengthyDescription}' if it is a lengthy description. Output exclusively the classification in your response. - ` + `, }, classify_text_full: { model: 'gpt-4o', @@ -109,7 +109,7 @@ const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = { prompt: `Based on the content of the the text, classify it into the most appropriate category: '${TextClassifications.Title}', '${TextClassifications.Caption}', or '${TextClassifications.LengthyDescription}'. Then provide five more descriptive tags (single words) separated by spaces. - Finally, include a more detailed summary phrase tag using underscores, for a total of seven tags.` + Finally, include a more detailed summary phrase tag using underscores, for a total of seven tags.`, }, describe: { model: 'gpt-4-vision-preview', maxTokens: 2048, temp: 0, prompt: 'Describe these images in 3-5 words' }, flashcard: { @@ -174,7 +174,7 @@ const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = { model: 'gpt-4o', maxTokens: 2048, temp: 0.5, - prompt: `Generate an aesthetically pleasing scrapbook layout preset based on these items. + prompt: `Generate an aesthetically pleasing scrapbook layout preset based on these items. Return your response as JSON in the format: [{ "type": rich text or image or pdf or video or collection @@ -191,22 +191,32 @@ const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = { tag: x: , y: , width: , height: } - ] ` - - }, + ] `, + }, command_type: { model: 'gpt-4-turbo', maxTokens: 1024, temp: 0, - prompt: `I'm going to provide you with a question. - Based on the question, is the user asking you to - ${GPTDocCommand.AssignTags}. Assigns docs with tags(like star / heart etc)/labels. + prompt: `Is the provided command/question asking you to: + ${GPTDocCommand.AssignTags}. Choose a descriptive tag/label. ${GPTDocCommand.GetInfo}. Provide information about a specific doc. ${GPTDocCommand.Filter}. Filter docs based on a question/information. ${GPTDocCommand.Sort}. Put docs in a specific order. - Answer with only the number for ${GPTDocCommand.GetInfo}-${GPTDocCommand.Sort}. - For number one, provide the number (${GPTDocCommand.AssignTags}) and the appropriate tag`, + Answer with only the number, do not add any other punctuation or formatting of any kind`, + }, + tag_docs: { + model: 'gpt-4-turbo', + maxTokens: 1024, + temp: 0, + prompt: `I'm going to give you a list of descriptions. + Each one is separated by '${DescriptionSeperator}' on either side. + Descriptions will vary in length, so make sure to only separate when you see '${DescriptionSeperator}'. + Based on the question/command the user asks, provide a tag label of the given descriptions that best matches the user's specifications. + Format your response precisely as a single string that prints each description followed by '${DataSeperator}' followed by the label followed by '${DescriptionSeperator}'. + Do not use any additional formatting marks or punctuation'. + Immediately afterward, surrounded by '${DocSeperator}' on BOTH SIDES, provide some insight into your reasoning for the way you sorted (and mention nothing about the formatting details given in this description). + `, }, subset_docs: { model: 'gpt-4-turbo', @@ -284,7 +294,7 @@ const gptImageCall = async (prompt: string, n?: number) => { n: n ?? 1, size: '1024x1024', }); - return response.data.map((data: Image) => data.url); + return (response.data ?? []).map((data: Image) => data.url); // return response.data.data[0].url; } catch (err) { console.error(err); |