diff options
Diffstat (limited to 'src/client/apis/gpt')
-rw-r--r-- | src/client/apis/gpt/customization.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/client/apis/gpt/customization.ts b/src/client/apis/gpt/customization.ts index db91e45a7..42f112f88 100644 --- a/src/client/apis/gpt/customization.ts +++ b/src/client/apis/gpt/customization.ts @@ -84,6 +84,68 @@ export const gptTrailSlideCustomization = async (inputText: string) => { } }; +// layout +export const smartLayout = async (inputData: { width: number; height: number }[]) => { + let prompt = + 'I want to layout documents in a 2d space in a nice, grid-like fashion with nice padding of about 50 units around each document, making sure they do not overlap. Given a json array of documents containing their width and heights in this form: {width: number, height: number}[], give me a json array in this form: {x: number, y: number}[] corresponding to the documents with a nice layout. Return just the json array.'; + + let messages: ChatCompletionMessageParam[] = [ + { role: 'system', content: prompt }, + { role: 'user', content: JSON.stringify(inputData) }, + ]; + + console.log('Prompt: ', prompt); + console.log('Messages: ', messages); + + try { + const response = await openai.chat.completions.create({ + model: 'gpt-4', + messages: messages, + temperature: 0.01, + max_tokens: 2000, + }); + const content = response.choices[0].message?.content; + if (content) { + return content; + } + return 'Malformed response.'; + } catch (err) { + console.log(err); + return 'Error connecting with API.'; + } +}; + +// layout +export const smartLayout2 = async (inputData: { width: number; height: number; content: string }[]) => { + let prompt = + 'I want to layout documents in a 2d space in an organized fashion with padding of about 50 units around each document, importantly making sure they do not overlap. I also want you to group documents by their content, with space separating semantic categories. Given a json array of documents containing their width and heights in this form: {width: number, height: number, content: string}[], give me a json array in this form: {x: number, y: number}[] corresponding to the documents in the same order with a nice layout. Return just the json array.'; + + let messages: ChatCompletionMessageParam[] = [ + { role: 'system', content: prompt }, + { role: 'user', content: JSON.stringify(inputData) }, + ]; + + console.log('Prompt: ', prompt); + console.log('Messages: ', messages); + + try { + const response = await openai.chat.completions.create({ + model: 'gpt-4', + messages: messages, + temperature: 0.01, + max_tokens: 2000, + }); + const content = response.choices[0].message?.content; + if (content) { + return content; + } + return 'Malformed response.'; + } catch (err) { + console.log(err); + return 'Error connecting with API.'; + } +}; + // palette / styling export const generatePalette = async (inputData: StyleInput, useImageData: boolean, inputText: string, lastResponse?: GeneratedResponse[]) => { let prompt = 'Dash is a hypermedia web application that allows users to organize documents of different media types into collections. The user wants you to come up with cohesive color palettes for a collection.'; @@ -121,6 +183,7 @@ export const generatePalette = async (inputData: StyleInput, useImageData: boole { role: 'user', content: JSON.stringify(inputData) }, ]; + // continuing conversation if (lastResponse && inputText !== '') { messages.push({ role: 'assistant', content: JSON.stringify(lastResponse) }); messages.push({ role: 'user', content: 'Please modify the previously generated palettes with the following: ' + inputText }); |