aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/gpt/GPT.ts
diff options
context:
space:
mode:
authoreleanor-park <eleanor_park@brown.edu>2024-12-30 23:35:24 -0500
committereleanor-park <eleanor_park@brown.edu>2024-12-30 23:35:24 -0500
commit0eff48b757ca81860a883d25e147b8a869e5fe00 (patch)
tree11e8333c424bc72b08357a38d05ab668423d16d1 /src/client/apis/gpt/GPT.ts
parent7e5f6fdc205eae1b0ab76390644257a82bf6ebf1 (diff)
created image regeneration with dialogue
Diffstat (limited to 'src/client/apis/gpt/GPT.ts')
-rw-r--r--src/client/apis/gpt/GPT.ts39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index 03380e4d6..9241eb120 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -249,6 +249,41 @@ const gptHandwriting = async (src: string): Promise<string> => {
}
};
+const gptDescribeImage = async (image: string): Promise<string> => {
+ try {
+ const response = await openai.chat.completions.create({
+ model: 'gpt-4o',
+ temperature: 0,
+ messages: [
+ {
+ role: 'user',
+ content: [
+ {
+ type: 'text',
+ text: `Identify what this drawing is, naming as many elements and their location in the drawing as possible`,
+ },
+ {
+ type: 'image_url',
+ image_url: {
+ url: `${image}`,
+ detail: 'low',
+ },
+ },
+ ],
+ },
+ ],
+ });
+ if (response.choices[0].message.content) {
+ console.log('GPT DESCRIPTION', response.choices[0].message.content);
+ return response.choices[0].message.content;
+ }
+ return 'Unknown drawing';
+ } catch (err) {
+ console.log(err);
+ return 'Error connecting with API';
+ }
+};
+
const gptDrawingColor = async (image: string, coords: string[]): Promise<string> => {
try {
const response = await openai.chat.completions.create({
@@ -276,11 +311,11 @@ const gptDrawingColor = async (image: string, coords: string[]): Promise<string>
if (response.choices[0].message.content) {
return response.choices[0].message.content;
}
- return 'Missing labels';
+ return 'Unknown drawing';
} catch (err) {
console.log(err);
return 'Error connecting with API';
}
};
-export { gptAPICall, gptImageCall, GPTCallType, gptImageLabel, gptGetEmbedding, gptHandwriting, gptDrawingColor };
+export { gptAPICall, gptImageCall, GPTCallType, gptImageLabel, gptGetEmbedding, gptHandwriting, gptDescribeImage, gptDrawingColor };