-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
3,655 additions
and
3,649 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type Props } from "../../../openai/loaders/vision.ts"; | ||
import { AppContext } from "../../mod.ts"; | ||
|
||
export default async function action( | ||
props: Props, | ||
_req: Request, | ||
ctx: AppContext, | ||
): Promise<string | null> { | ||
const response = await ctx.invoke("openai/loaders/vision.ts", props); | ||
|
||
return response.choices?.[0]?.message.content; | ||
} |
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,46 @@ | ||
import { AppContext } from "../mod.ts"; | ||
import { OpenAI } from "../deps.ts"; | ||
|
||
export interface Props { | ||
/** | ||
* @description the links of the site that contains images | ||
* @examples "https://www.instagram.com/marcoscandeia" | ||
*/ | ||
images: string[]; | ||
/** | ||
* @description what kind of description do you want? | ||
* @examples you can ask for something like "What’s in this image?"\n or "Is there a car?" | ||
*/ | ||
prompt: string; | ||
choices?: number; | ||
maxTokens?: number; | ||
} | ||
|
||
export type Return = OpenAI.ChatCompletion; | ||
|
||
export default async function ( | ||
{ images, prompt, choices = 1, maxTokens = 4096 }: Props, | ||
_req: Request, | ||
ctx: AppContext, | ||
): Promise<Return> { | ||
const response = await ctx.openAI.chat.completions.create({ | ||
n: choices, | ||
stream: false, | ||
max_tokens: maxTokens, | ||
model: "gpt-4-vision-preview", | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ type: "text", text: prompt }, | ||
...images.map((image) => ({ | ||
type: "image_url" as const, | ||
image_url: { "url": image }, | ||
})), | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
return response; | ||
} |
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
Oops, something went wrong.