aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/gpt/GPT.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/apis/gpt/GPT.ts')
-rw-r--r--src/client/apis/gpt/GPT.ts102
1 files changed, 85 insertions, 17 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index 9cb47995c..6258a82dc 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -11,6 +11,12 @@ export enum GPTDocCommand {
export const DescriptionSeperator = '======';
export const DocSeperator = '------';
+export const DataSeperator = '>>>>>>';
+export enum TextClassifications {
+ Title = 'word', //a few words
+ Caption = 'sentence', //few sentences
+ LengthyDescription = 'paragraphs',
+}
enum GPTCallType {
SUMMARY = 'summary',
@@ -34,8 +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',
}
type GPTCallOpts = {
@@ -48,6 +58,20 @@ 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.
+ 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.
+ Make sure each description is only in the list once. Each item should be separated by '${DescriptionSeperator}'.
+ 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).
+ 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',
@@ -69,17 +93,23 @@ const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = {
temp: 0.5,
prompt: "You are a helpful resarch assistant. Analyze the user's data to find meaningful patterns and/or correlation. Please only return a JSON with a correlation column 1 propert, a correlation column 2 property, and an analysis property. ",
},
- sort_docs: {
+ //new
+ classify_text_minimal: {
model: 'gpt-4o',
maxTokens: 2048,
temp: 0.25,
- 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.
- Make sure each description is only in the list once. Each item should be separated by '${DescriptionSeperator}'.
- 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).
- 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`,
+ 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',
+ maxTokens: 2048,
+ temp: 0.25,
+ 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.`,
},
describe: { model: 'gpt-4-vision-preview', maxTokens: 2048, temp: 0, prompt: 'Describe these images in 3-5 words' },
flashcard: {
@@ -102,19 +132,20 @@ const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = {
prompt: "BRIEFLY (<50 words) describe any differences between the rubric and the user's answer answer in second person. If there are no differences, say correct",
},
template: {
- model: 'gpt-4-turbo',
+ model: 'gpt-4.1',
maxTokens: 512,
temp: 0.5,
prompt: 'You will be given a list of field descriptions for one or more templates in the format {field #0: “description”}{field #1: “description”}{...}, and a list of column descriptions in the format {“title”: “description”}{...}. Your job is to match columns with fields based on their descriptions. Your output should be in the following JSON format: {“template_title”:{“#”: “title”, “#”: “title”, “#”: “title” …}, “template_title”:{“#”: “title”, “#”: “title”, “#”: “title” …}} where “template_title” is the templates title as specified in the description provided, # represents the field # and “title” the title of the column assigned to it. A filled out example might look like {“fivefield2”:{“0”:”Name”, “1”:”Image”, “2”:”Caption”, “3”:”Position”, “4”:”Stats”}, “fivefield3”:{0:”Image”, 1:”Name”, 2:”Caption”, 3:”Stats”, 4:”Position”}. Include one object for each template. IT IS VERY IMPORTANT THAT YOU ONLY INCLUDE TEXT IN THE FORMAT ABOVE, WITH NO ADDITIONS WHATSOEVER. Do not include extraneous ‘#’ characters, ‘column’ for columns, or ‘template’ for templates: ONLY THE TITLES AND NUMBERS. There should never be one column assigned to more than one field (ie. if the “name” column is assigned to field 1, it can’t be assigned to any other fields) . Do this for each template whose fields are described. The descriptions are as follows:',
},
+
vizsum: {
- model: 'gpt-4-turbo',
+ model: 'gpt-4.1',
maxTokens: 512,
temp: 0.5,
prompt: 'Your job is to provide brief descriptions for columns in a dataset based on example rows. Your descriptions should be geared towards how each column’s data might fit together into a visual template. Would they make good titles, main focuses, captions, descriptions, etc. Pay special attention to connections between columns, i.e. is there one column that specifically seems to describe/be related to another more than the rest? You should provide your analysis in JSON format like so: {“col1”:”description”, “col2”:”description”, …}. DO NOT INCLUDE ANY OTHER TEXT, ONLY THE JSON.',
},
vizsum2: {
- model: 'gpt-4-turbo',
+ model: 'gpt-4.1',
maxTokens: 512,
temp: 0.5,
prompt: 'Your job is to provide structured information on columns in a dataset based on example rows. You will categorize each column in two ways: by type and size. The size categories are as follows: tiny (one or two words), small (a sentence/multiple words), medium (a few sentences), large (a longer paragraph), and huge (a very long or multiple paragraphs). The type categories are as follows: visual (links/file paths to images, pdfs, maps, or any other visual media type), and text (plain text that isn’t a link/file path). Visual media should be assumed to have size “medium” “large” or “huge”. You will give your responses in JSON format, like so: {“title (of column)”:{“type”:”text”, “size”:”small”}, “title (of column)”:{“type”:”visual”, “size”:”medium”}, …}. DO NOT INCLUDE ANY OTHER TEXT, ONLY THE JSON.',
@@ -138,18 +169,54 @@ const callTypeMap: { [type in GPTCallType]: GPTCallOpts } = {
temp: 0.5,
prompt: 'You will be coloring drawings. You will be given what the drawing is, then a list of descriptions for parts of the drawing. Based on each description, respond with the stroke and fill color that it should be. Follow the rules: 1. Avoid using black for stroke color 2. Make the stroke color 1-3 shades darker than the fill color 3. Use the same colors when possible. Format as {#abcdef #abcdef}, making sure theres a color for each description, and do not include any additional text.',
},
+
+ generate_scrapbook: {
+ model: 'gpt-4o',
+ maxTokens: 2048,
+ temp: 0.5,
+ 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
+ "tag": a singular tag summarizing the document
+ "acceptTags": [a list of all relevant tags that this document accepts, like ['PERSON', 'LANDSCAPE']]
+ "x": number,
+ "y": number,
+ "width": number, **note: if it is in an image, please respect existing aspect ratio if it is provided
+ "height": number
+ }, ...]
+ If there are mutliple documents and you wish to nest documents into a collection for aesthetic purposes, you may include
+ "children": [
+ { type:
+ 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 without including any '${DescriptionSeperator}', followed by '${DataSeperator}', followed by the tag 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',
@@ -222,11 +289,12 @@ const gptAPICall = async (inputTextIn: string, callType: GPTCallType, prompt?: s
const gptImageCall = async (prompt: string, n?: number) => {
try {
const response = await openai.images.generate({
+ model: 'dall-e-3',
prompt: prompt,
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);