@cloudflare/workers-types 4.20250109.0 → 4.20250124.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3598,7 +3598,10 @@ export type AiTextGenerationInput = {
3598
3598
  frequency_penalty?: number;
3599
3599
  presence_penalty?: number;
3600
3600
  messages?: RoleScopedChatInput[];
3601
- tools?: AiTextGenerationToolInput[] | AiTextGenerationToolLegacyInput[];
3601
+ tools?:
3602
+ | AiTextGenerationToolInput[]
3603
+ | AiTextGenerationToolLegacyInput[]
3604
+ | (object & NonNullable<unknown>);
3602
3605
  functions?: AiTextGenerationFunctionsInput[];
3603
3606
  };
3604
3607
  export type AiTextGenerationOutput =
@@ -3657,12 +3660,417 @@ export declare abstract class BaseAiTranslation {
3657
3660
  inputs: AiTranslationInput;
3658
3661
  postProcessedOutputs: AiTranslationOutput;
3659
3662
  }
3660
- export type AiOptions = {
3661
- gateway?: GatewayOptions;
3663
+ export type Ai_Cf_Openai_Whisper_Input =
3664
+ | string
3665
+ | {
3666
+ /**
3667
+ * An array of integers that represent the audio data constrained to 8-bit unsigned integer values
3668
+ */
3669
+ audio: number[];
3670
+ };
3671
+ export interface Ai_Cf_Openai_Whisper_Output {
3672
+ /**
3673
+ * The transcription
3674
+ */
3675
+ text: string;
3676
+ word_count?: number;
3677
+ words?: {
3678
+ word?: string;
3679
+ /**
3680
+ * The second this word begins in the recording
3681
+ */
3682
+ start?: number;
3683
+ /**
3684
+ * The ending second when the word completes
3685
+ */
3686
+ end?: number;
3687
+ }[];
3688
+ vtt?: string;
3689
+ }
3690
+ export declare abstract class Base_Ai_Cf_Openai_Whisper {
3691
+ inputs: Ai_Cf_Openai_Whisper_Input;
3692
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Output;
3693
+ }
3694
+ export type Ai_Cf_Openai_Whisper_Tiny_En_Input =
3695
+ | string
3696
+ | {
3697
+ /**
3698
+ * An array of integers that represent the audio data constrained to 8-bit unsigned integer values
3699
+ */
3700
+ audio: number[];
3701
+ };
3702
+ export interface Ai_Cf_Openai_Whisper_Tiny_En_Output {
3703
+ /**
3704
+ * The transcription
3705
+ */
3706
+ text: string;
3707
+ word_count?: number;
3708
+ words?: {
3709
+ word?: string;
3710
+ /**
3711
+ * The second this word begins in the recording
3712
+ */
3713
+ start?: number;
3714
+ /**
3715
+ * The ending second when the word completes
3716
+ */
3717
+ end?: number;
3718
+ }[];
3719
+ vtt?: string;
3720
+ }
3721
+ export declare abstract class Base_Ai_Cf_Openai_Whisper_Tiny_En {
3722
+ inputs: Ai_Cf_Openai_Whisper_Tiny_En_Input;
3723
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Tiny_En_Output;
3724
+ }
3725
+ export interface Ai_Cf_Openai_Whisper_Large_V3_Turbo_Input {
3726
+ /**
3727
+ * Base64 encoded value of the audio data.
3728
+ */
3729
+ audio: string;
3730
+ /**
3731
+ * Supported tasks are 'translate' or 'transcribe'.
3732
+ */
3733
+ task?: string;
3734
+ /**
3735
+ * The language of the audio being transcribed or translated.
3736
+ */
3737
+ language?: string;
3738
+ /**
3739
+ * Preprocess the audio with a voice activity detection model.
3740
+ */
3741
+ vad_filter?: string;
3742
+ /**
3743
+ * A text prompt to help provide context to the model on the contents of the audio.
3744
+ */
3745
+ initial_prompt?: string;
3746
+ /**
3747
+ * The prefix it appended the the beginning of the output of the transcription and can guide the transcription result.
3748
+ */
3662
3749
  prefix?: string;
3663
- extraHeaders?: object;
3664
- };
3665
- export type ModelType<Name extends keyof AiModels> = AiModels[Name];
3750
+ }
3751
+ export interface Ai_Cf_Openai_Whisper_Large_V3_Turbo_Output {
3752
+ transcription_info?: {
3753
+ /**
3754
+ * The language of the audio being transcribed or translated.
3755
+ */
3756
+ language?: string;
3757
+ /**
3758
+ * The confidence level or probability of the detected language being accurate, represented as a decimal between 0 and 1.
3759
+ */
3760
+ language_probability?: number;
3761
+ /**
3762
+ * The total duration of the original audio file, in seconds.
3763
+ */
3764
+ duration?: number;
3765
+ /**
3766
+ * The duration of the audio after applying Voice Activity Detection (VAD) to remove silent or irrelevant sections, in seconds.
3767
+ */
3768
+ duration_after_vad?: number;
3769
+ };
3770
+ /**
3771
+ * The complete transcription of the audio.
3772
+ */
3773
+ text: string;
3774
+ /**
3775
+ * The total number of words in the transcription.
3776
+ */
3777
+ word_count?: number;
3778
+ segments?: {
3779
+ /**
3780
+ * The starting time of the segment within the audio, in seconds.
3781
+ */
3782
+ start?: number;
3783
+ /**
3784
+ * The ending time of the segment within the audio, in seconds.
3785
+ */
3786
+ end?: number;
3787
+ /**
3788
+ * The transcription of the segment.
3789
+ */
3790
+ text?: string;
3791
+ /**
3792
+ * The temperature used in the decoding process, controlling randomness in predictions. Lower values result in more deterministic outputs.
3793
+ */
3794
+ temperature?: number;
3795
+ /**
3796
+ * The average log probability of the predictions for the words in this segment, indicating overall confidence.
3797
+ */
3798
+ avg_logprob?: number;
3799
+ /**
3800
+ * The compression ratio of the input to the output, measuring how much the text was compressed during the transcription process.
3801
+ */
3802
+ compression_ratio?: number;
3803
+ /**
3804
+ * The probability that the segment contains no speech, represented as a decimal between 0 and 1.
3805
+ */
3806
+ no_speech_prob?: number;
3807
+ words?: {
3808
+ /**
3809
+ * The individual word transcribed from the audio.
3810
+ */
3811
+ word?: string;
3812
+ /**
3813
+ * The starting time of the word within the audio, in seconds.
3814
+ */
3815
+ start?: number;
3816
+ /**
3817
+ * The ending time of the word within the audio, in seconds.
3818
+ */
3819
+ end?: number;
3820
+ }[];
3821
+ };
3822
+ /**
3823
+ * The transcription in WebVTT format, which includes timing and text information for use in subtitles.
3824
+ */
3825
+ vtt?: string;
3826
+ }
3827
+ export declare abstract class Base_Ai_Cf_Openai_Whisper_Large_V3_Turbo {
3828
+ inputs: Ai_Cf_Openai_Whisper_Large_V3_Turbo_Input;
3829
+ postProcessedOutputs: Ai_Cf_Openai_Whisper_Large_V3_Turbo_Output;
3830
+ }
3831
+ export interface Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Input {
3832
+ /**
3833
+ * A text description of the image you want to generate.
3834
+ */
3835
+ prompt: string;
3836
+ /**
3837
+ * The number of diffusion steps; higher values can improve quality but take longer.
3838
+ */
3839
+ steps?: number;
3840
+ }
3841
+ export interface Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Output {
3842
+ /**
3843
+ * The generated image in Base64 format.
3844
+ */
3845
+ image?: string;
3846
+ }
3847
+ export declare abstract class Base_Ai_Cf_Black_Forest_Labs_Flux_1_Schnell {
3848
+ inputs: Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Input;
3849
+ postProcessedOutputs: Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Output;
3850
+ }
3851
+ export type Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Input = Prompt | Messages;
3852
+ export interface Prompt {
3853
+ /**
3854
+ * The input text prompt for the model to generate a response.
3855
+ */
3856
+ prompt: string;
3857
+ image?: number[] | (string & NonNullable<unknown>);
3858
+ /**
3859
+ * If true, a chat template is not applied and you must adhere to the specific model's expected formatting.
3860
+ */
3861
+ raw?: boolean;
3862
+ /**
3863
+ * If true, the response will be streamed back incrementally using SSE, Server Sent Events.
3864
+ */
3865
+ stream?: boolean;
3866
+ /**
3867
+ * The maximum number of tokens to generate in the response.
3868
+ */
3869
+ max_tokens?: number;
3870
+ /**
3871
+ * Controls the randomness of the output; higher values produce more random results.
3872
+ */
3873
+ temperature?: number;
3874
+ /**
3875
+ * Adjusts the creativity of the AI's responses by controlling how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses.
3876
+ */
3877
+ top_p?: number;
3878
+ /**
3879
+ * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises.
3880
+ */
3881
+ top_k?: number;
3882
+ /**
3883
+ * Random seed for reproducibility of the generation.
3884
+ */
3885
+ seed?: number;
3886
+ /**
3887
+ * Penalty for repeated tokens; higher values discourage repetition.
3888
+ */
3889
+ repetition_penalty?: number;
3890
+ /**
3891
+ * Decreases the likelihood of the model repeating the same lines verbatim.
3892
+ */
3893
+ frequency_penalty?: number;
3894
+ /**
3895
+ * Increases the likelihood of the model introducing new topics.
3896
+ */
3897
+ presence_penalty?: number;
3898
+ /**
3899
+ * Name of the LoRA (Low-Rank Adaptation) model to fine-tune the base model.
3900
+ */
3901
+ lora?: string;
3902
+ }
3903
+ export interface Messages {
3904
+ /**
3905
+ * An array of message objects representing the conversation history.
3906
+ */
3907
+ messages: {
3908
+ /**
3909
+ * The role of the message sender (e.g., 'user', 'assistant', 'system', 'tool').
3910
+ */
3911
+ role: string;
3912
+ /**
3913
+ * The content of the message as a string.
3914
+ */
3915
+ content: string;
3916
+ }[];
3917
+ image?: number[] | string;
3918
+ functions?: {
3919
+ name: string;
3920
+ code: string;
3921
+ }[];
3922
+ /**
3923
+ * A list of tools available for the assistant to use.
3924
+ */
3925
+ tools?: (
3926
+ | {
3927
+ /**
3928
+ * The name of the tool. More descriptive the better.
3929
+ */
3930
+ name: string;
3931
+ /**
3932
+ * A brief description of what the tool does.
3933
+ */
3934
+ description: string;
3935
+ /**
3936
+ * Schema defining the parameters accepted by the tool.
3937
+ */
3938
+ parameters: {
3939
+ /**
3940
+ * The type of the parameters object (usually 'object').
3941
+ */
3942
+ type: string;
3943
+ /**
3944
+ * List of required parameter names.
3945
+ */
3946
+ required?: string[];
3947
+ /**
3948
+ * Definitions of each parameter.
3949
+ */
3950
+ properties: {
3951
+ [k: string]: {
3952
+ /**
3953
+ * The data type of the parameter.
3954
+ */
3955
+ type: string;
3956
+ /**
3957
+ * A description of the expected parameter.
3958
+ */
3959
+ description: string;
3960
+ };
3961
+ };
3962
+ };
3963
+ }
3964
+ | {
3965
+ /**
3966
+ * Specifies the type of tool (e.g., 'function').
3967
+ */
3968
+ type: string;
3969
+ /**
3970
+ * Details of the function tool.
3971
+ */
3972
+ function: {
3973
+ /**
3974
+ * The name of the function.
3975
+ */
3976
+ name: string;
3977
+ /**
3978
+ * A brief description of what the function does.
3979
+ */
3980
+ description: string;
3981
+ /**
3982
+ * Schema defining the parameters accepted by the function.
3983
+ */
3984
+ parameters: {
3985
+ /**
3986
+ * The type of the parameters object (usually 'object').
3987
+ */
3988
+ type: string;
3989
+ /**
3990
+ * List of required parameter names.
3991
+ */
3992
+ required?: string[];
3993
+ /**
3994
+ * Definitions of each parameter.
3995
+ */
3996
+ properties: {
3997
+ [k: string]: {
3998
+ /**
3999
+ * The data type of the parameter.
4000
+ */
4001
+ type: string;
4002
+ /**
4003
+ * A description of the expected parameter.
4004
+ */
4005
+ description: string;
4006
+ };
4007
+ };
4008
+ };
4009
+ };
4010
+ }
4011
+ )[];
4012
+ /**
4013
+ * If true, the response will be streamed back incrementally.
4014
+ */
4015
+ stream?: boolean;
4016
+ /**
4017
+ * The maximum number of tokens to generate in the response.
4018
+ */
4019
+ max_tokens?: number;
4020
+ /**
4021
+ * Controls the randomness of the output; higher values produce more random results.
4022
+ */
4023
+ temperature?: number;
4024
+ /**
4025
+ * Controls the creativity of the AI's responses by adjusting how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses.
4026
+ */
4027
+ top_p?: number;
4028
+ /**
4029
+ * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises.
4030
+ */
4031
+ top_k?: number;
4032
+ /**
4033
+ * Random seed for reproducibility of the generation.
4034
+ */
4035
+ seed?: number;
4036
+ /**
4037
+ * Penalty for repeated tokens; higher values discourage repetition.
4038
+ */
4039
+ repetition_penalty?: number;
4040
+ /**
4041
+ * Decreases the likelihood of the model repeating the same lines verbatim.
4042
+ */
4043
+ frequency_penalty?: number;
4044
+ /**
4045
+ * Increases the likelihood of the model introducing new topics.
4046
+ */
4047
+ presence_penalty?: number;
4048
+ }
4049
+ export type Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Output =
4050
+ | {
4051
+ /**
4052
+ * The generated text response from the model
4053
+ */
4054
+ response?: string;
4055
+ /**
4056
+ * An array of tool calls requests made during the response generation
4057
+ */
4058
+ tool_calls?: {
4059
+ /**
4060
+ * The arguments passed to be passed to the tool call request
4061
+ */
4062
+ arguments?: object;
4063
+ /**
4064
+ * The name of the tool to be called
4065
+ */
4066
+ name?: string;
4067
+ }[];
4068
+ }
4069
+ | ReadableStream;
4070
+ export declare abstract class Base_Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct {
4071
+ inputs: Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Input;
4072
+ postProcessedOutputs: Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Output;
4073
+ }
3666
4074
  export interface AiModels {
3667
4075
  "@cf/huggingface/distilbert-sst-2-int8": BaseAiTextClassification;
3668
4076
  "@cf/stabilityai/stable-diffusion-xl-base-1.0": BaseAiTextToImage;
@@ -3719,16 +4127,56 @@ export interface AiModels {
3719
4127
  "@cf/facebook/bart-large-cnn": BaseAiSummarization;
3720
4128
  "@cf/unum/uform-gen2-qwen-500m": BaseAiImageToText;
3721
4129
  "@cf/llava-hf/llava-1.5-7b-hf": BaseAiImageToText;
4130
+ "@cf/openai/whisper": Base_Ai_Cf_Openai_Whisper;
4131
+ "@cf/openai/whisper-tiny-en": Base_Ai_Cf_Openai_Whisper_Tiny_En;
4132
+ "@cf/openai/whisper-large-v3-turbo": Base_Ai_Cf_Openai_Whisper_Large_V3_Turbo;
4133
+ "@cf/black-forest-labs/flux-1-schnell": Base_Ai_Cf_Black_Forest_Labs_Flux_1_Schnell;
4134
+ "@cf/meta/llama-3.2-11b-vision-instruct": Base_Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct;
3722
4135
  }
3723
- export type ModelListType = Record<string, any>;
3724
- export declare abstract class Ai<ModelList extends ModelListType = AiModels> {
4136
+ export type AiOptions = {
4137
+ gateway?: GatewayOptions;
4138
+ prefix?: string;
4139
+ extraHeaders?: object;
4140
+ };
4141
+ export type AiModelsSearchParams = {
4142
+ author?: string;
4143
+ hide_experimental?: boolean;
4144
+ page?: number;
4145
+ per_page?: number;
4146
+ search?: string;
4147
+ source?: number;
4148
+ task?: string;
4149
+ };
4150
+ export type AiModelsSearchObject = {
4151
+ id: string;
4152
+ source: number;
4153
+ name: string;
4154
+ description: string;
4155
+ task: {
4156
+ id: string;
4157
+ name: string;
4158
+ description: string;
4159
+ };
4160
+ tags: string[];
4161
+ properties: {
4162
+ property_id: string;
4163
+ value: string;
4164
+ }[];
4165
+ };
4166
+ export interface InferenceUpstreamError extends Error {}
4167
+ export interface AiInternalError extends Error {}
4168
+ export type AiModelListType = Record<string, any>;
4169
+ export declare abstract class Ai<
4170
+ AiModelList extends AiModelListType = AiModels,
4171
+ > {
3725
4172
  aiGatewayLogId: string | null;
3726
4173
  gateway(gatewayId: string): AiGateway;
3727
- run<Name extends keyof ModelList>(
4174
+ run<Name extends keyof AiModelList>(
3728
4175
  model: Name,
3729
- inputs: ModelList[Name]["inputs"],
4176
+ inputs: AiModelList[Name]["inputs"],
3730
4177
  options?: AiOptions,
3731
- ): Promise<ModelList[Name]["postProcessedOutputs"]>;
4178
+ ): Promise<AiModelList[Name]["postProcessedOutputs"]>;
4179
+ public models(params?: AiModelsSearchParams): Promise<AiModelsSearchObject[]>;
3732
4180
  }
3733
4181
  export type GatewayOptions = {
3734
4182
  id: string;