Skip to content

Commit

Permalink
refine openai api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
derekphilipau committed Jan 2, 2024
1 parent dc4cef3 commit f07e7f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
34 changes: 9 additions & 25 deletions lib/openai/openaiArtworkDescription.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
/**
* Approx 0.012 cents for input, 0.015 cents for output = 0.03 cents per image
* 10 images = .3 cents ($0.003)
* 100 images = 3 cents ($0.03)
* 1000 images = 30 cents ($0.30)
* 10000 images = 300 cents ($3.00)
* 100000 images = 3000 cents ($30.00)
*
* Test run: 3 runs = $0.05, 1 run = $0.0166
*
* $0.0166 cents per run:
* 100 images * $0.0166 = $1.66
* 10000 images * $0.0166 = $166
* 100000 images * $0.0166 = $1660
*
* OpenAI Vision API:
* https://platform.openai.com/docs/guides/vision
*
* For possibly mapping keywords to emojis:
* https://unicode.org/Public/emoji/15.1/
* https://unicode.org/emoji/charts/emoji-list.html
*
* PUT /art/_mapping
{
"properties": {
"mlAltText": {
"type": "text",
"analyzer": "unaggregatedStandardAnalyzer"
},
"mlDescription": {
"type": "text",
"analyzer": "unaggregatedStandardAnalyzer"
}
}
}
*
*/
//import { loadEnvConfig } from '@next/env';
import OpenAI from 'openai';
Expand Down Expand Up @@ -94,16 +81,13 @@ export async function updateDocumentMLDescriptionFromImage(
const mlDescription = await getMLDescriptionFromImage(
document.image.thumbnailUrl
);
/*
TODO:
if (mlDescription) {
if (mlDescription.altText) document.mlAltText = mlDescription.altText;
if (mlDescription.longDescription)
document.mlDescription = mlDescription.longDescription;
const client = getClient();
await upsertDocument(client, index, id, document);
//await upsertDocument(client, index, id, document);
}
*/
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/openai/openaiArtworkEmbeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ export async function updateDocumentWithEmbeddings(
// Assuming you have a field in your document to store embeddings
// TODO document.embeddings = embeddings;
const client = getClient();
await upsertDocument(client, index, id, document);
// await upsertDocument(client, index, id, document);
}
}

/**
* Test the OpenAI API
*/
/*
export async function testOpenAI(id): Promise<void> {
export async function testOpenAI(id: string): Promise<void> {
const resp = await getDocument('art', id);
const doc = resp?.data as BaseDocument;
if (!doc?.image?.thumbnailUrl) {
Expand Down

0 comments on commit f07e7f1

Please sign in to comment.