-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tabs for gallery and grid views
- Loading branch information
1 parent
1ffc8af
commit 331a6f3
Showing
10 changed files
with
507 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import OpenAI from "openai"; | ||
import { internalAction } from "./_generated/server"; | ||
import { v } from "convex/values"; | ||
import { api, internal } from "./_generated/api"; | ||
|
||
const openai = new OpenAI(); | ||
|
||
export const generateAIComment = internalAction({ | ||
args: { | ||
imageIds: v.array(v.id("_storage")), | ||
thumbnailId: v.id("thumbnails"), | ||
userId: v.id("users"), | ||
}, | ||
async handler(ctx, args) { | ||
const images = await Promise.all( | ||
args.imageIds.map(async (imageId) => ({ | ||
type: "image_url", | ||
image_url: { | ||
url: await ctx.storage.getUrl(imageId), | ||
}, | ||
})) | ||
); | ||
|
||
const response = await openai.chat.completions.create({ | ||
model: "gpt-4-vision-preview", | ||
max_tokens: 1000, | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Pick which Thumbnails Looks the Best:", | ||
}, | ||
...(images as any), | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
const content = response.choices[0].message.content; | ||
|
||
await ctx.runMutation(internal.thumbnails.addCommentInternal, { | ||
thumbnailId: args.thumbnailId, | ||
text: content ?? "", | ||
userId: args.userId, | ||
}); | ||
}, | ||
}); |
Oops, something went wrong.