anya/tools/meme-maker.ts

66 lines
35 KiB
TypeScript

import OpenAI from "openai";
import { z } from "zod";
// get meta data from url
export const MemeMakerParams = z.object({
query: z.string(),
});
export type MemeMakerParams = z.infer<typeof MemeMakerParams>;
const ai_token = process.env.OPENAI_API_KEY?.trim();
const openai = new OpenAI({
apiKey: ai_token,
});
const mememaker_swagger =
'{"openapi":"3.0.3","info":{"title":"Memegen.link","version":"11.0","description":"\n## Quickstart\n\nFetch the list of templates:\n\n```\n$ http GET https://api.memegen.link/templates\n\n[\n {\n "id": "aag",\n "name": "Ancient Aliens Guy",\n "lines": 2,\n "overlays": 0,\n "styles": [],\n "blank": "https://api.memegen.link/images/aag.png",\n "example": {\n "text": [\n "",\n "aliens"\n ],\n "url": "https://api.memegen.link/images/aag/_/aliens.png"\n },\n "source": "http://knowyourmeme.com/memes/ancient-aliens",\n },\n ...\n]\n```\n\nAdd text to create a meme:\n\n```\n$ http POST https://api.memegen.link/images template_id=aag "text[]=foo" "text[]=bar"\n\n{\n "url": "https://api.memegen.link/images/aag/foo/bar.png"\n}\n```\n\nView the image: <https://api.memegen.link/images/aag/foo/bar.png>\n\n## Links\n","license":{"name":"View the license","url":"https://github.com/jacebrowning/memegen/blob/main/LICENSE.txt"},"contact":{"name":"support","email":"support@maketested.com"}},"paths":{"/auth":{"post":{"operationId":"post~Clients.validate","summary":"Validate your API key","tags":["Clients"],"responses":{"401":{"content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","title":"Error"}}}}},"description":"Your API key is invalid"},"200":{"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string","title":"Email"},"image_access":{"type":"boolean","title":"Image_Access"},"search_access":{"type":"boolean","title":"Search_Access"},"created":{"type":"string","format":"date-time","title":"Created"},"modified":{"type":"string","format":"date-time","title":"Modified"}}}}},"description":"Your API key is valid"}}}},"/images/preview.jpg":{"get":{"operationId":"get~Clients.preview","summary":"Display a preview of a custom meme","tags":["Clients"],"parameters":[{"name":"layout","schema":{"type":"string"},"description":"Text position: `default` or `top`","in":"query"},{"name":"template","schema":{"type":"string"},"description":"Template ID, URL, or custom background","in":"query"},{"name":"style","schema":{"type":"string"},"description":"Style name or custom overlay","in":"query"},{"name":"text[]","schema":{"type":"string"},"description":"Lines of text to render","in":"query"}],"responses":{"200":{"content":{"image/jpeg":{"schema":{"type":"string","format":"byte"}}},"description":"Successfully displayed a custom meme"}}}},"/fonts":{"get":{"operationId":"get~Fonts.index","summary":"List available fonts","tags":["Fonts"],"responses":{"200":{"content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"filename":{"type":"string","title":"Filename"},"id":{"type":"string","title":"Id"},"alias":{"type":"string","title":"Alias"}}}}}},"description":"Successfully returned a list of fonts"}}}},"/images/custom":{"get":{"operationId":"get~Images.index_custom","summary":"List popular custom memes","tags":["Images"],"parameters":[{"name":"filter","schema":{"type":"string"},"description":"Part of the meme\'s text to match","in":"query"},{"name":"safe","schema":{"type":"boolean"},"description":"Exclude NSFW results","in":"query"}],"responses":{"200":{"content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"url":{"type":"string","title":"Url"}}}}}},"description":"Successfully returned a list of custom memes"}}},"post":{"operationId":"post~Images.create_custom","summary":"Create a meme from any image","tags":["Images"],"responses":{"201":{"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","title":"Url"}}}}},"description":"Successfully created a meme from a custom image"}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"background":{"type":"string","title":"Background"},"style":{"type":"string","title":"Style"},"text":{"type":"array","items":{"type":"string"},"title":"Text"},"layout":{"type":"string","title":"Layout"},"font":{"type":"string","title":"Font"},"extension":{"type":"string","title":"Extension"},"redirect":{"type":"boolean","title":"Redirect"}}}}}}}},"/images":{"get":{"operationId":"get~Images.index","summary":"List example memes","tags":["Images"],"parameters":[{"name":"filter","schema":{"type":"string"},"description":"Part of the template name or example to match","in":"query"}],"responses":{"200":{"content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"url":{"type":"string","title":"Url"},"template":{"type":"string","title":"Template"}}}}}},"description":"Successfully returned a list of example memes"}}},"post":{"operationId":"post~Images.create","summary":"Create a meme from a template","tags":["Images"],"responses":{"404":{"content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","title":"Error"}}}}},"description":"Specified "template_id" does not exist"},"400":{"content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","title":"Error"}}}}},"description":"Required "template_id" missing in request body"},"201":{"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","title":"Url"}}}}},"description":"Successfully created a meme"}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"template_id":{"type":"string","title":"Template_Id"},"style":{"type":"array","items":{"type":"string"},"title":"Style"},"text":{"type":"array","items":{"type":"string"},"title":"Text"},"layout":{"type":"string","title":"Layout"},"font":{"type":"string","title":"Font"},"extension":{"type":"string","title":"Extension"},"redirect":{"type":"boolean","title":"Redirect"}}}}}}}},"/images/automatic":{"post":{"operationId":"post~Images.create_automatic","summary":"Create a meme from word or phrase","tags":["Images"],"responses":{"400":{"content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","title":"Error"}}}}},"description":"Required "text" missing in request body"},"201":{"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","title":"Url"}}}}},"description":"Successfully created a meme"}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"text":{"type":"string","title":"Text"},"safe":{"type":"boolean","title":"Safe"},"redirect":{"type":"boolean","title":"Redirect"}}}}}}}},"/templates/custom":{"post":{"operationId":"post~Templates.custom","summary":"Create a meme from any image","tags":["Templates"],"responses":{"201":{"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","title":"Url"}}}}},"description":"Successfully created a meme from a custom image"}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"background":{"type":"string","title":"Background"},"style":{"type":"string","title":"Style"},"text":{"type":"array","items":{"type":"string"},"title":"Text"},"layout":{"type":"string","title":"Layout"},"font":{"type":"string","title":"Font"},"extension":{"type":"string","title":"Extension"},"redirect":{"type":"boolean","title":"Redirect"}}}}}}}},"/templates":{"get":{"operationId":"get~Templates.index","summary":"List all templates","tags":["Templates"],"parameters":[{"name":"filter","schema":{"type":"string"},"description":"Part of the name, keyword, or example to match","in":"query"},{"name":"animated","schema":{"type":"boolean"},"description":"Limit results to templates supporting animation","in":"query"}],"responses":{"200":{"content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","title":"Id"},"name":{"type":"string","title":"Name"},"lines":{"type":"integer","format":"int32","title":"Lines"},"overlays":{"type":"integer","format":"int32","title":"Overlays"},"styles":{"type":"array","items":{"type":"string"},"title":"Styles"},"blank":{"type":"string","title":"Blank"},"example":{"type":"object","title":"Example","properties":{"text":{"type":"array","items":{"type":"string"},"title":"Text"},"url":{"type":"string","title":"Url"}}},"source":{"type":"string","title":"Source"}}}}}},"description":"Successfully returned a list of all templates"}}}},"/fonts/{id}":{"get":{"operationId":"get~Fonts.detail","summary":"View a specific font","tags":["Fonts"],"parameters":[{"name":"id","schema":{"type":"string"},"description":"ID of a font","required":true,"in":"path"}],"responses":{"404":{"content":{"*/*":{"schema":{"type":"string"}}},"description":"Font not found"},"200":{"content":{"application/json":{"schema":{"type":"object","properties":{"filename":{"type":"string","title":"Filename"},"id":{"type":"string","title":"Id"},"alias":{"type":"string","title":"Alias"}}}}},"description":"Successfully returned a specific font"}}}},"/templates/{id}":{"post":{"operationId":"post~Templates.build","summary":"Create a meme from a template","tags":["Templates"],"parameters":[{"name":"id","schema":{"type":"string"},"description":"ID of a meme template","required":true,"in":"path"}],"responses":{"201":{"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","title":"Url"}}}}},"description":"Successfully created a meme from a template"}},"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"style":{"type":"array","items":{"type":"string"},"title":"Style"},"text":{"type":"array","items":{"type":"string"},"title":"Text"},"layout":{"type":"string","title":"Layout"},"font":{"type":"string","title":"Font"},"extension":{"type":"string","title":"Extension"},"redirect":{"type":"boolean","title":"Redirect"}}}}}}},"get":{"operationId":"get~Templates.detail","summary":"View a specific template","tags":["Templates"],"parameters":[{"name":"id","schema":{"type":"string"},"description":"ID of a meme template","required":true,"in":"path"}],"responses":{"404":{"content":{"*/*":{"schema":{"type":"string"}}},"description":"Template not found"},"200":{"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","title":"Id"},"name":{"type":"string","title":"Name"},"lines":{"type":"integer","format":"int32","title":"Lines"},"overlays":{"type":"integer","format":"int32","title":"Overlays"},"styles":{"type":"array","items":{"type":"string"},"title":"Styles"},"blank":{"type":"string","title":"Blank"},"example":{"type":"object","title":"Example","properties":{"text":{"type":"array","items":{"type":"string"},"title":"Text"},"url":{"type":"string","title":"Url"}}},"source":{"type":"string","title":"Source"}}}}},"description":"Successfully returned a specific template"}}}},"/{template_id}":{"get":{"operationId":"get~Shortcuts.legacy_example_image","summary":"Redirect to an example image","tags":["Shortcuts"],"parameters":[{"name":"template_id","schema":{"type":"string"},"description":"ID of a meme template","required":true,"in":"path"}],"responses":{"404":{"content":{"text/html":{"schema":{"type":"string"}}},"description":"Template not found"},"302":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Successfully redirected to an example image"}}}},"/images/{template_filename}":{"get":{"operationId":"get~Images.detail_blank","summary":"Display a template background","tags":["Images"],"parameters":[{"name":"template_filename","schema":{"type":"string"},"description":"Template ID and image format: `<template_id>.<extension>`","required":true,"in":"path"}],"responses":{"422":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Invalid style for template or no image URL specified for custom template"},"415":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Unable to download image URL"},"404":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Template not found"},"200":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Successfully displayed a template background"}}}},"/images/{template_id}/{text_filepath}":{"get":{"operationId":"get~Images.detail_text","summary":"Display a custom meme","tags":["Images"],"parameters":[{"name":"template_id","schema":{"type":"string"},"description":"ID of a meme template","required":true,"in":"path"},{"name":"text_filepath","schema":{"type":"string"},"description":"Lines of text and image format: `<line1>/<line2>.<extension>`","required":true,"in":"path"}],"responses":{"422":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Invalid style for template or no image URL specified for custom template"},"415":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Unable to download image URL"},"414":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Custom text too long (length >200)"},"404":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Template not found"},"200":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Successfully displayed a custom meme"}}}},"/images/{template_id}/{text_paths}":{"get":{"operationId":"get~Shortcuts.custom_path","summary":"Redirect to a custom image","tags":["Shortcuts"],"parameters":[{"name":"template_id","schema":{"type":"string"},"description":"ID of a meme template","required":true,"in":"path"},{"name":"text_paths","schema":{"type":"string"},"description":"Lines of text: `<line1>/<line2>`","required":true,"in":"path"}],"responses":{"302":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Successfully redirected to a custom image"}}}},"/{template_id}/{text_paths}":{"get":{"operationId":"get~Shortcuts.legacy_custom_image","summary":"Redirect to a custom image","tags":["Shortcuts"],"parameters":[{"name":"template_id","schema":{"type":"string"},"description":"ID of a meme template","required":true,"in":"path"},{"name":"text_paths","schema":{"type":"string"},"description":"Lines of text: `<line1>/<line2>`","required":true,"in":"path"}],"responses":{"404":{"content":{"text/html":{"schema":{"type":"string"}}},"description":"Template not found"},"302":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Successfully redirected to a custom image"}}}},"/images/{template_id}":{"get":{"operationId":"get~Shortcuts.example_path","summary":"Redirect to an example image","tags":["Shortcuts"],"parameters":[{"name":"template_id","schema":{"type":"string"},"description":"ID of a meme template","required":true,"in":"path"}],"responses":{"501":{"content":{"text/html":{"schema":{"type":"string"}}},"description":"Template not fully implemented"},"404":{"content":{"text/html":{"schema":{"type":"string"}}},"description":"Template not found"},"302":{"content":{"image/*":{"schema":{"type":"string","format":"byte"}}},"description":"Successfully redirected to an example image"}}}}},"tags":[{"name":"Clients"},{"name":"Fonts"},{"name":"Images"},{"name":"Templates"},{"name":"Shortcuts"}],"servers":[],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","name":"X-API-KEY","in":"header"}}}}';
const cat_swagger =
'{"openapi":"3.0.3","info":{"version":"1.0.0","title":"Cat as a service (CATAAS)","description":"Cat as a service (CATAAS) is a REST API to spread peace and love (or not) thanks to cats."},"servers":[{"url":"https://cataas.com"}],"tags":[{"name":"Cats","description":"Cataas API"},{"name":"API","description":"Public API"},{"name":"Security","description":"Security"},{"name":"Admin","description":"Admin API"}],"components":{"securitySchemes":{"jwt":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"AdminCat":{"required":["file","tags","validated"],"type":"object","properties":{"_id":{"type":"string"},"validated":{"type":"boolean"},"file":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}}},"Cat":{"required":["file","tags"],"type":"object","properties":{"_id":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]}}},"EditCat":{"required":["tags"],"type":"object","properties":{"tags":{"type":"array","items":{"type":"string"},"default":[]}}},"Error":{"type":"object","properties":{"message":{"type":"string"},"code":{"type":"number"}}},"SignIn":{"required":["name","password"],"type":"object","properties":{"username":{"type":"string"},"password":{"type":"string"}}},"SignUp":{"required":["name","password","mail","secret"],"type":"object","properties":{"username":{"type":"string"},"password":{"type":"string"},"email":{"type":"string"},"secret":{"type":"string"}}},"Token":{"type":"object","properties":{"token":{"type":"string"}}}}},"paths":{"/admin/cats":{"get":{"operationId":"admin:cats:browse","security":[{"jwt":[]}],"tags":["Admin"],"description":"Browse cats","parameters":[{"name":"limit","in":"query","schema":{"type":"integer"}},{"name":"skip","in":"query","schema":{"type":"integer"}}],"responses":{"200":{"description":"List of cats","content":{"application/json":{"schema":{"type":"array","items":{"required":["file","tags","validated"],"type":"object","properties":{"_id":{"type":"string"},"validated":{"type":"boolean"},"file":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}}}}}}}}}},"/admin/cats/{id}/validate":{"put":{"operationId":"admin:cats:validate","security":[{"jwt":[]}],"tags":["Admin"],"description":"Activate cat","parameters":[{"name":"id","in":"path","schema":{"type":"string"},"required":true}],"responses":{"200":{"description":"Cat activated"},"404":{"description":"Cat not found"}}}},"/admin/cats/{id}":{"patch":{"operationId":"admin:cats:edit","security":[{"jwt":[]}],"tags":["Admin"],"description":"Activate cat","parameters":[{"name":"id","in":"path","schema":{"type":"string"},"required":true}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"tags":{"type":"string"}}}}}},"responses":{"200":{"description":"Cat updated"},"404":{"description":"Cat not found"}}},"delete":{"operationId":"admin:cats:delete","security":[{"jwt":[]}],"tags":["Admin"],"description":"Delete cat","parameters":[{"name":"id","in":"path","schema":{"type":"string"},"required":true}],"responses":{"203":{"description":"Cat deleted"},"404":{"description":"Cat not found"}}}},"/cat":{"get":{"operationId":"cat:random","tags":["Cats"],"description":"Get a random cat","parameters":[{"name":"type","in":"query","schema":{"type":"string","enum":["square","medium","small","xsmall"]}},{"name":"filter","in":"query","schema":{"type":"string","enum":["mono","negate","custom"]}},{"name":"fit","in":"query","schema":{"type":"string","enum":["cover","contain","fill","inside","outside"]}},{"name":"position","in":"query","schema":{"type":"string","default":"center","enum":["top","right top","right","right bottom","bottom","left bottom","left","left top","center"]}},{"name":"width","in":"query","schema":{"type":"integer"}},{"name":"height","in":"query","schema":{"type":"integer"}},{"name":"blur","in":"query","schema":{"type":"integer"}},{"name":"r","in":"query","schema":{"type":"integer"},"description":"Red"},{"name":"g","in":"query","schema":{"type":"integer"},"description":"Green"},{"name":"b","in":"query","schema":{"type":"integer"},"description":"Blue"},{"name":"brightness","in":"query","schema":{"type":"number","format":"float"},"description":"Brightness multiplier"},{"name":"saturation","in":"query","schema":{"type":"number","format":"float"},"description":"Saturation multiplier"},{"name":"hue","in":"query","schema":{"type":"integer"},"description":"Hue rotation in degrees"},{"name":"lightness","in":"query","schema":{"type":"integer"},"description":"Lightness addend"},{"name":"html","in":"query","schema":{"type":"boolean"}},{"name":"json","in":"query","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Cat returned","content":{"image/*":{"schema":{"type":"string","format":"binary"}},"application/json":{"schema":{"required":["file","tags"],"type":"object","properties":{"_id":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]}}}}}}}}},"/cat/{id}":{"get":{"operationId":"cat:get","tags":["Cats"],"description":"Get cat by id","parameters":[{"name":"id","in":"path","schema":{"type":"string"},"required":true},{"name":"type","in":"query","schema":{"type":"string","enum":["square","medium","small","xsmall"]}},{"name":"filter","in":"query","schema":{"type":"string","enum":["mono","negate","custom"]}},{"name":"fit","in":"query","schema":{"type":"string","enum":["cover","contain","fill","inside","outside"]}},{"name":"position","in":"query","schema":{"type":"string","default":"center","enum":["top","right top","right","right bottom","bottom","left bottom","left","left top","center"]}},{"name":"width","in":"query","schema":{"type":"integer"}},{"name":"height","in":"query","schema":{"type":"integer"}},{"name":"blur","in":"query","schema":{"type":"integer"}},{"name":"r","in":"query","schema":{"type":"integer"},"description":"Red"},{"name":"g","in":"query","schema":{"type":"integer"},"description":"Green"},{"name":"b","in":"query","schema":{"type":"integer"},"description":"Blue"},{"name":"brightness","in":"query","schema":{"type":"number","format":"float"},"description":"Brightness multiplier"},{"name":"saturation","in":"query","schema":{"type":"number","format":"float"},"description":"Saturation multiplier"},{"name":"hue","in":"query","schema":{"type":"integer"},"description":"Hue rotation in degrees"},{"name":"lightness","in":"query","schema":{"type":"integer"},"description":"Lightness addend"},{"name":"html","in":"query","schema":{"type":"boolean"}},{"name":"json","in":"query","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Cat returned","content":{"image/*":{"schema":{"type":"string","format":"binary"}},"application/json":{"schema":{"required":["file","tags"],"type":"object","properties":{"_id":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]}}}}}},"404":{"description":"Cat not found"}}}},"/cat/{tag}":{"get":{"operationId":"cat:random:tag","tags":["Cats"],"description":"Get random cat by tag","parameters":[{"name":"tag","in":"path","schema":{"type":"string"},"required":true},{"name":"type","in":"query","schema":{"type":"string","enum":["square","medium","small","xsmall"]}},{"name":"filter","in":"query","schema":{"type":"string","enum":["mono","negate","custom"]}},{"name":"fit","in":"query","schema":{"type":"string","enum":["cover","contain","fill","inside","outside"]}},{"name":"position","in":"query","schema":{"type":"string","default":"center","enum":["top","right top","right","right bottom","bottom","left bottom","left","left top","center"]}},{"name":"width","in":"query","schema":{"type":"integer"}},{"name":"height","in":"query","schema":{"type":"integer"}},{"name":"blur","in":"query","schema":{"type":"integer"}},{"name":"r","in":"query","schema":{"type":"integer"},"description":"Red"},{"name":"g","in":"query","schema":{"type":"integer"},"description":"Green"},{"name":"b","in":"query","schema":{"type":"integer"},"description":"Blue"},{"name":"brightness","in":"query","schema":{"type":"number","format":"float"},"description":"Brightness multiplier"},{"name":"saturation","in":"query","schema":{"type":"number","format":"float"},"description":"Saturation multiplier"},{"name":"hue","in":"query","schema":{"type":"integer"},"description":"Hue rotation in degrees"},{"name":"lightness","in":"query","schema":{"type":"integer"},"description":"Lightness addend"},{"name":"html","in":"query","schema":{"type":"boolean"}},{"name":"json","in":"query","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Cat returned","content":{"image/*":{"schema":{"type":"string","format":"binary"}},"application/json":{"schema":{"required":["file","tags"],"type":"object","properties":{"_id":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]}}}}}}}}},"/cat/says/{text}":{"get":{"operationId":"cat:random:text","tags":["Cats"],"description":"Get random cat saying text","parameters":[{"name":"text","in":"path","schema":{"type":"string"},"required":true},{"name":"font","in":"query","schema":{"type":"string","default":"Impact","enum":["Andale Mono","Impact","Arial","Arial Black","Comic Sans MS","Courier New","Georgia","Times New Roman","Verdana","Webdings"]}},{"name":"fontSize","in":"query","schema":{"type":"integer","default":30}},{"name":"fontColor","in":"query","schema":{"type":"string","default":"#000"}},{"name":"fontBackground","in":"query","schema":{"type":"string","default":"none"}},{"name":"type","in":"query","schema":{"type":"string","enum":["square","medium","small","xsmall"]}},{"name":"filter","in":"query","schema":{"type":"string","enum":["mono","negate","custom"]}},{"name":"fit","in":"query","schema":{"type":"string","enum":["cover","contain","fill","inside","outside"]}},{"name":"position","in":"query","schema":{"type":"string","default":"center","enum":["top","right top","right","right bottom","bottom","left bottom","left","left top","center"]}},{"name":"width","in":"query","schema":{"type":"integer"}},{"name":"height","in":"query","schema":{"type":"integer"}},{"name":"blur","in":"query","schema":{"type":"integer"}},{"name":"r","in":"query","schema":{"type":"integer"},"description":"Red"},{"name":"g","in":"query","schema":{"type":"integer"},"description":"Green"},{"name":"b","in":"query","schema":{"type":"integer"},"description":"Blue"},{"name":"brightness","in":"query","schema":{"type":"number","format":"float"},"description":"Brightness multiplier"},{"name":"saturation","in":"query","schema":{"type":"number","format":"float"},"description":"Saturation multiplier"},{"name":"hue","in":"query","schema":{"type":"integer"},"description":"Hue rotation in degrees"},{"name":"lightness","in":"query","schema":{"type":"integer"},"description":"Lightness addend"},{"name":"html","in":"query","schema":{"type":"boolean"}},{"name":"json","in":"query","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Cat returned","content":{"image/*":{"schema":{"type":"string","format":"binary"}},"application/json":{"schema":{"required":["file","tags"],"type":"object","properties":{"_id":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]}}}}}}}}},"/cat/{id}/says/{text}":{"get":{"operationId":"cat:get:text","tags":["Cats"],"description":"Get cat by id saying text","parameters":[{"name":"id","in":"path","schema":{"type":"string"},"required":true},{"name":"text","in":"path","schema":{"type":"string"},"required":true},{"name":"font","in":"query","schema":{"type":"string","default":"Impact","enum":["Andale Mono","Impact","Arial","Arial Black","Comic Sans MS","Courier New","Georgia","Times New Roman","Verdana","Webdings"]}},{"name":"fontSize","in":"query","schema":{"type":"integer","default":30}},{"name":"fontColor","in":"query","schema":{"type":"string","default":"#000"}},{"name":"fontBackground","in":"query","schema":{"type":"string","default":"none"}},{"name":"type","in":"query","schema":{"type":"string","enum":["square","medium","small","xsmall"]}},{"name":"filter","in":"query","schema":{"type":"string","enum":["mono","negate","custom"]}},{"name":"fit","in":"query","schema":{"type":"string","enum":["cover","contain","fill","inside","outside"]}},{"name":"position","in":"query","schema":{"type":"string","default":"center","enum":["top","right top","right","right bottom","bottom","left bottom","left","left top","center"]}},{"name":"width","in":"query","schema":{"type":"integer"}},{"name":"height","in":"query","schema":{"type":"integer"}},{"name":"blur","in":"query","schema":{"type":"integer"}},{"name":"r","in":"query","schema":{"type":"integer"},"description":"Red"},{"name":"g","in":"query","schema":{"type":"integer"},"description":"Green"},{"name":"b","in":"query","schema":{"type":"integer"},"description":"Blue"},{"name":"brightness","in":"query","schema":{"type":"number","format":"float"},"description":"Brightness multiplier"},{"name":"saturation","in":"query","schema":{"type":"number","format":"float"},"description":"Saturation multiplier"},{"name":"hue","in":"query","schema":{"type":"integer"},"description":"Hue rotation in degrees"},{"name":"lightness","in":"query","schema":{"type":"integer"},"description":"Lightness addend"},{"name":"html","in":"query","schema":{"type":"boolean"}},{"name":"json","in":"query","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Cat returned","content":{"image/*":{"schema":{"type":"string","format":"binary"}},"application/json":{"schema":{"required":["file","tags"],"type":"object","properties":{"_id":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]}}}}}},"404":{"description":"Cat not found"}}}},"/cat/{tag}/says/{text}":{"get":{"operationId":"cat:random:tag:text","tags":["Cats"],"description":"Get random cat by tag saying text","parameters":[{"name":"tag","in":"path","schema":{"type":"string"},"required":true},{"name":"text","in":"path","schema":{"type":"string"},"required":true},{"name":"font","in":"query","schema":{"type":"string","default":"Impact","enum":["Andale Mono","Impact","Arial","Arial Black","Comic Sans MS","Courier New","Georgia","Times New Roman","Verdana","Webdings"]}},{"name":"fontSize","in":"query","schema":{"type":"integer","default":30}},{"name":"fontColor","in":"query","schema":{"type":"string","default":"#000"}},{"name":"fontBackground","in":"query","schema":{"type":"string","default":"none"}},{"name":"type","in":"query","schema":{"type":"string","enum":["square","medium","small","xsmall"]}},{"name":"filter","in":"query","schema":{"type":"string","enum":["mono","negate","custom"]}},{"name":"fit","in":"query","schema":{"type":"string","enum":["cover","contain","fill","inside","outside"]}},{"name":"position","in":"query","schema":{"type":"string","default":"center","enum":["top","right top","right","right bottom","bottom","left bottom","left","left top","center"]}},{"name":"width","in":"query","schema":{"type":"integer"}},{"name":"height","in":"query","schema":{"type":"integer"}},{"name":"blur","in":"query","schema":{"type":"integer"}},{"name":"r","in":"query","schema":{"type":"integer"},"description":"Red"},{"name":"g","in":"query","schema":{"type":"integer"},"description":"Green"},{"name":"b","in":"query","schema":{"type":"integer"},"description":"Blue"},{"name":"brightness","in":"query","schema":{"type":"number","format":"float"},"description":"Brightness multiplier"},{"name":"saturation","in":"query","schema":{"type":"number","format":"float"},"description":"Saturation multiplier"},{"name":"hue","in":"query","schema":{"type":"integer"},"description":"Hue rotation in degrees"},{"name":"lightness","in":"query","schema":{"type":"integer"},"description":"Lightness addend"},{"name":"html","in":"query","schema":{"type":"boolean"}},{"name":"json","in":"query","schema":{"type":"boolean"}}],"responses":{"200":{"description":"Cat returned","content":{"image/*":{"schema":{"type":"string","format":"binary"}},"application/json":{"schema":{"required":["file","tags"],"type":"object","properties":{"_id":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]}}}}}}}}},"/api/cats":{"get":{"operationId":"api:cats","tags":["API"],"description":"Will return all cats","parameters":[{"name":"limit","in":"query","schema":{"type":"number","default":10}},{"name":"skip","in":"query","schema":{"type":"number","default":0}},{"name":"tags","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"List of cats","content":{"application/json":{"schema":{"type":"array","items":{"required":["file","tags"],"type":"object","properties":{"_id":{"type":"string"},"mimetype":{"type":"string"},"size":{"type":"number"},"tags":{"type":"array","items":{"type":"string"},"default":[]}}}}}}}}}},"/api/tags":{"get":{"operationId":"api:tags","tags":["API"],"description":"Will return all tags","responses":{"200":{"description":"List of tags","content":{"application/json":{"schema":{"type":"array","items":{"type":"string"}}}}}}}},"/api/count":{"get":{"operationId":"api:count","tags":["API"],"description":"Count how many cat","responses":{"200":{"description":"List of tags","content":{"application/json":{"schema":{"type":"object","properties":{"count":{"type":"number"}}}}}}}}},"/security/sign-in":{"post":{"operationId":"api:security:sign-in","tags":["Security"],"requestBody":{"content":{"application/json":{"schema":{"required":["name","password"],"type":"object","properties":{"username":{"type":"string"},"password":{"type":"string"}}}}}},"responses":{"200":{"description":"Authenticated","content":{"application/json":{"schema":{"type":"object","properties":{"token":{"type":"string"}}}}}},"401":{"description":"Unauthorized"}}}},"/security/sign-up":{"post":{"operationId":"api:security:sign-up","tags":["Security"],"requestBody":{"content":{"application/json":{"schema":{"required":["name","password","mail","secret"],"type":"object","properties":{"username":{"type":"string"},"password":{"type":"string"},"email":{"type":"string"},"secret":{"type":"string"}}}}}},"responses":{"201":{"description":"Registered"},"400":{"description":"Bad request"}}}}}}';
export async function meme_maker({ query }: MemeMakerParams) {
const res = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{
role: "system",
content: `Use the below openapi schema to generate a meme's image URL or a Cat image URL and return the url alone.
MemeMaker OpenAPI Schema:
\`\`\`
${mememaker_swagger}
\`\`\`
Cat Image OpenAPI Schema:
\`\`\`
${cat_swagger}
\`\`\`
MemeMaker Useage:
- You can allow user to use external images using their public web url.
- You can allow user to use external images using their base64 encoded string.
Basic Cat Image Useage:
- /cat Will return a random cat
- /cat/:tag Will return a random cat with a :tag, You can combine multiple tags with :tag separator, Example: https://cataas.com/cat/orange,cute
- /cat/gif Will return a random gif cat \o/
- /cat/says/:text Will return a random cat saying :text
- /cat/:tag/says/:text Will return a random cat with a :tag and saying :text
Notes:
- You can use cat image urls in memes.
`,
},
{
role: "user",
content: query,
},
],
});
return {
response: res.choices[0].message.content,
};
}