diff --git a/types/defines/ai.d.ts b/types/defines/ai.d.ts index 90c7a2c51f3..1425eb1fad6 100644 --- a/types/defines/ai.d.ts +++ b/types/defines/ai.d.ts @@ -14,6 +14,12 @@ export type AiImageToTextInput = { prompt?: string; max_tokens?: number; temperature?: number; + top_p?: number; + top_k?: number; + seed?: number; + repetition_penalty?: number; + frequency_penalty?: number; + presence_penalty?: number; raw?: boolean; messages?: RoleScopedChatInput[]; }; @@ -94,19 +100,48 @@ export declare abstract class BaseAiTextEmbeddings { postProcessedOutputs: AiTextEmbeddingsOutput; } export type RoleScopedChatInput = { - role: string; + role: "user" | "assistant" | "system" | "tool"; content: string; }; +export type AiTextGenerationToolInput = { + type: "function"; + function: { + name: string; + description: string; + parameters?: { + type: "object"; + properties: { + [key: string]: { + type: string; + description?: string; + }; + }; + required: string[]; + }; + }; +}; export type AiTextGenerationInput = { prompt?: string; raw?: boolean; stream?: boolean; max_tokens?: number; + temperature?: number; + top_p?: number; + top_k?: number; + seed?: number; + repetition_penalty?: number; + frequency_penalty?: number; + presence_penalty?: number; messages?: RoleScopedChatInput[]; + tools?: AiTextGenerationToolInput[]; }; export type AiTextGenerationOutput = | { response?: string; + tool_calls?: { + name: string; + arguments: unknown; + }[]; } | ReadableStream; export declare abstract class BaseAiTextGeneration { @@ -149,108 +184,113 @@ export type AiOptions = { prefix?: string; extraHeaders?: object; }; +export type BaseAiTextClassificationModels = + "@cf/huggingface/distilbert-sst-2-int8"; +export type BaseAiTextToImageModels = + | "@cf/stabilityai/stable-diffusion-xl-base-1.0" + | "@cf/runwayml/stable-diffusion-v1-5-inpainting" + | "@cf/runwayml/stable-diffusion-v1-5-img2img" + | "@cf/lykon/dreamshaper-8-lcm" + | "@cf/bytedance/stable-diffusion-xl-lightning"; +export type BaseAiTextEmbeddingsModels = + | "@cf/baai/bge-small-en-v1.5" + | "@cf/baai/bge-base-en-v1.5" + | "@cf/baai/bge-large-en-v1.5"; +export type BaseAiSpeechRecognitionModels = + | "@cf/openai/whisper" + | "@cf/openai/whisper-tiny-en" + | "@cf/openai/whisper-sherpa"; +export type BaseAiImageClassificationModels = "@cf/microsoft/resnet-50"; +export type BaseAiObjectDetectionModels = "@cf/facebook/detr-resnet-50"; +export type BaseAiTextGenerationModels = + | "@cf/meta/llama-3-8b-instruct" + | "@cf/meta/llama-3-8b-instruct-awq" + | "@cf/meta/llama-2-7b-chat-int8" + | "@cf/mistral/mistral-7b-instruct-v0.1" + | "@cf/mistral/mistral-7b-instruct-v0.2-lora" + | "@cf/meta/llama-2-7b-chat-fp16" + | "@hf/thebloke/llama-2-13b-chat-awq" + | "@hf/thebloke/zephyr-7b-beta-awq" + | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" + | "@hf/thebloke/codellama-7b-instruct-awq" + | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" + | "@hf/thebloke/neural-chat-7b-v3-1-awq" + | "@hf/thebloke/llamaguard-7b-awq" + | "@hf/thebloke/deepseek-coder-6.7b-base-awq" + | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" + | "@hf/nousresearch/hermes-2-pro-mistral-7b" + | "@hf/mistral/mistral-7b-instruct-v0.2" + | "@hf/google/gemma-7b-it" + | "@hf/nexusflow/starling-lm-7b-beta" + | "@cf/deepseek-ai/deepseek-math-7b-instruct" + | "@cf/defog/sqlcoder-7b-2" + | "@cf/openchat/openchat-3.5-0106" + | "@cf/tiiuae/falcon-7b-instruct" + | "@cf/thebloke/discolm-german-7b-v1-awq" + | "@cf/qwen/qwen1.5-0.5b-chat" + | "@cf/qwen/qwen1.5-1.8b-chat" + | "@cf/qwen/qwen1.5-7b-chat-awq" + | "@cf/qwen/qwen1.5-14b-chat-awq" + | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" + | "@cf/microsoft/phi-2" + | "@cf/google/gemma-2b-it-lora" + | "@cf/google/gemma-7b-it-lora" + | "@cf/meta-llama/llama-2-7b-chat-hf-lora" + | "@cf/fblgit/una-cybertron-7b-v2-bf16" + | "@cf/fblgit/una-cybertron-7b-v2-awq"; +export type BaseAiTranslationModels = "@cf/meta/m2m100-1.2b"; +export type BaseAiSummarizationModels = "@cf/facebook/bart-large-cnn"; +export type BaseAiImageToTextModels = + | "@cf/unum/uform-gen2-qwen-500m" + | "@cf/llava-hf/llava-1.5-7b-hf"; export declare abstract class Ai { run( - model: - | "@cf/huggingface/distilbert-sst-2-int8" - | "@cf/jpmorganchase/roberta-spam" - | "@cf/inml/inml-roberta-dga", + model: BaseAiTextClassificationModels, inputs: BaseAiTextClassification["inputs"], options?: AiOptions ): Promise; run( - model: - | "@cf/stabilityai/stable-diffusion-xl-base-1.0" - | "@cf/runwayml/stable-diffusion-v1-5-inpainting" - | "@cf/runwayml/stable-diffusion-v1-5-img2img" - | "@cf/lykon/dreamshaper-8-lcm" - | "@cf/bytedance/stable-diffusion-xl-lightning", + model: BaseAiTextToImageModels, inputs: BaseAiTextToImage["inputs"], options?: AiOptions ): Promise; run( - model: "@hf/sentence-transformers/all-minilm-l6-v2", - inputs: BaseAiSentenceSimilarity["inputs"], - options?: AiOptions - ): Promise; - run( - model: - | "@cf/baai/bge-small-en-v1.5" - | "@cf/baai/bge-base-en-v1.5" - | "@cf/baai/bge-large-en-v1.5", + model: BaseAiTextEmbeddingsModels, inputs: BaseAiTextEmbeddings["inputs"], options?: AiOptions ): Promise; run( - model: - | "@cf/openai/whisper" - | "@cf/openai/whisper-tiny-en" - | "@cf/openai/whisper-sherpa", + model: BaseAiSpeechRecognitionModels, inputs: BaseAiSpeechRecognition["inputs"], options?: AiOptions ): Promise; run( - model: "@cf/microsoft/resnet-50", + model: BaseAiImageClassificationModels, inputs: BaseAiImageClassification["inputs"], options?: AiOptions ): Promise; run( - model: "@cf/facebook/detr-resnet-50", + model: BaseAiObjectDetectionModels, inputs: BaseAiObjectDetection["inputs"], options?: AiOptions ): Promise; run( - model: - | "@cf/meta/llama-3-8b-instruct" - | "@cf/meta/llama-2-7b-chat-int8" - | "@cf/mistral/mistral-7b-instruct-v0.1" - | "@cf/mistral/mistral-7b-instruct-v0.1-vllm" - | "@cf/mistral/mistral-7b-instruct-v0.2-lora" - | "@cf/meta/llama-2-7b-chat-fp16" - | "@hf/thebloke/llama-2-13b-chat-awq" - | "@hf/thebloke/zephyr-7b-beta-awq" - | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" - | "@hf/thebloke/codellama-7b-instruct-awq" - | "@hf/thebloke/openchat_3.5-awq" - | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" - | "@hf/thebloke/neural-chat-7b-v3-1-awq" - | "@hf/thebloke/llamaguard-7b-awq" - | "@hf/thebloke/deepseek-coder-6.7b-base-awq" - | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" - | "@hf/nousresearch/hermes-2-pro-mistral-7b" - | "@hf/mistral/mistral-7b-instruct-v0.2" - | "@cf/mistral/mixtral-8x7b-instruct-v0.1-awq" - | "@hf/google/gemma-7b-it" - | "@hf/nexusflow/starling-lm-7b-beta" - | "@cf/deepseek-ai/deepseek-math-7b-instruct" - | "@cf/defog/sqlcoder-7b-2" - | "@cf/openchat/openchat-3.5-0106" - | "@cf/tiiuae/falcon-7b-instruct" - | "@cf/thebloke/discolm-german-7b-v1-awq" - | "@cf/qwen/qwen1.5-0.5b-chat" - | "@cf/qwen/qwen1.5-1.8b-chat" - | "@cf/qwen/qwen1.5-7b-chat-awq" - | "@cf/qwen/qwen1.5-14b-chat-awq" - | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" - | "@cf/microsoft/phi-2" - | "@cf/google/gemma-2b-it-lora" - | "@cf/google/gemma-7b-it-lora" - | "@cf/meta-llama/llama-2-7b-chat-hf-lora", + model: BaseAiTextGenerationModels, inputs: BaseAiTextGeneration["inputs"], options?: AiOptions ): Promise; run( - model: "@cf/meta/m2m100-1.2b", + model: BaseAiTranslationModels, inputs: BaseAiTranslation["inputs"], options?: AiOptions ): Promise; run( - model: "@cf/facebook/bart-large-cnn", + model: BaseAiSummarizationModels, inputs: BaseAiSummarization["inputs"], options?: AiOptions ): Promise; run( - model: "@cf/unum/uform-gen2-qwen-500m" | "@cf/llava-hf/llava-1.5-7b-hf", + model: BaseAiImageToTextModels, inputs: BaseAiImageToText["inputs"], options?: AiOptions ): Promise;