Add AI captions.
This commit is contained in:
parent
945dcdead0
commit
f3784e75f4
3 changed files with 201 additions and 28 deletions
33
src/api/caption.ts
Normal file
33
src/api/caption.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { z } from "zod"
|
||||
import { fetchJsonSafeWith } from "../request"
|
||||
import type { RequestError } from "../request"
|
||||
import type { Result } from "../result"
|
||||
|
||||
const CAPTION_API_URL = "https://picsum-caption-worker.meatbagoverclocked.workers.dev/"
|
||||
|
||||
const captionResponseSchema = z.object({
|
||||
description: z.string(),
|
||||
})
|
||||
|
||||
export type CaptionResponse = z.infer<typeof captionResponseSchema>
|
||||
|
||||
export type GetCaptionParams = {
|
||||
imageUrl: string
|
||||
maxWords: number
|
||||
}
|
||||
|
||||
export async function getCaption({
|
||||
imageUrl,
|
||||
maxWords,
|
||||
}: GetCaptionParams): Promise<Result<CaptionResponse, RequestError>> {
|
||||
return fetchJsonSafeWith(CAPTION_API_URL, (json) => captionResponseSchema.parse(json), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
imageUrl,
|
||||
maxWords,
|
||||
}),
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue