cloudflare
Version:
The official TypeScript library for the Cloudflare API
277 lines • 6.8 kB
TypeScript
import * as Core from 'cloudflare/core';
import { APIResource } from 'cloudflare/resource';
import * as AIAPI from 'cloudflare/resources/workers/ai';
import { type Uploadable } from 'cloudflare/core';
export declare class AI extends APIResource {
/**
* This endpoint provides users with the capability to run specific AI models
* on-demand.
*
* By submitting the required input data, users can receive real-time predictions
* or results generated by the chosen AI model. The endpoint supports various AI
* model types, ensuring flexibility and adaptability for diverse use cases.
*
* Model specific inputs available in
* [Cloudflare Docs](https://developers.cloudflare.com/workers-ai/models/).
*/
run(modelName: string, params: AIRunParams, options?: Core.RequestOptions): Core.APIPromise<AIRunResponse>;
}
export type AIRunResponse = Array<AIRunResponse.TextClassification> | Uploadable | Array<number> | AIRunResponse.TextEmbeddings | AIRunResponse.SpeechRecognition | Array<AIRunResponse.ImageClassification> | Array<AIRunResponse.ObjectDetection> | AIRunResponse.Response | Uploadable | AIRunResponse.Translation | AIRunResponse.Summarization | AIRunResponse.ImageToText;
export declare namespace AIRunResponse {
interface TextClassification {
label?: string;
score?: number;
}
interface TextEmbeddings {
data?: Array<Array<number>>;
shape?: Array<number>;
}
interface SpeechRecognition {
text: string;
vtt?: string;
word_count?: number;
words?: Array<SpeechRecognition.Word>;
}
namespace SpeechRecognition {
interface Word {
end?: number;
start?: number;
word?: string;
}
}
interface ImageClassification {
label?: string;
score?: number;
}
interface ObjectDetection {
box?: ObjectDetection.Box;
label?: string;
score?: number;
}
namespace ObjectDetection {
interface Box {
xmax?: number;
xmin?: number;
ymax?: number;
ymin?: number;
}
}
interface Response {
response?: string;
}
interface Translation {
translated_text?: string;
}
interface Summarization {
summary?: string;
}
interface ImageToText {
description?: string;
}
}
export type AIRunParams = AIRunParams.TextClassification | AIRunParams.TextToImage | AIRunParams.SentenceSimilarity | AIRunParams.TextEmbeddings | AIRunParams.SpeechRecognition | AIRunParams.ImageClassification | AIRunParams.ObjectDetection | AIRunParams.TextGeneration | AIRunParams.Translation | AIRunParams.Summarization | AIRunParams.ImageToText;
export declare namespace AIRunParams {
interface TextClassification {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
text: string;
}
interface TextToImage {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
prompt: string;
/**
* Body param:
*/
guidance?: number;
/**
* Body param:
*/
image?: Array<number>;
/**
* Body param:
*/
mask?: Array<number>;
/**
* Body param:
*/
num_steps?: number;
/**
* Body param:
*/
strength?: number;
}
interface SentenceSimilarity {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
sentences: Array<string>;
/**
* Body param:
*/
source: string;
}
interface TextEmbeddings {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
text: string | Array<string>;
}
interface SpeechRecognition {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
audio?: Array<number>;
}
interface ImageClassification {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
image?: Array<number>;
}
interface ObjectDetection {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
image?: Array<number>;
}
interface TextGeneration {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
lora?: string;
/**
* Body param:
*/
max_tokens?: number;
/**
* Body param:
*/
messages?: Array<AIRunParams.TextGeneration.Message>;
/**
* Body param:
*/
prompt?: string;
/**
* Body param:
*/
raw?: boolean;
/**
* Body param:
*/
stream?: boolean;
}
namespace TextGeneration {
interface Message {
content: string;
role: string;
}
}
interface Translation {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
target_lang: string;
/**
* Body param:
*/
text: string;
/**
* Body param:
*/
source_lang?: string;
}
interface Summarization {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
input_text: string;
/**
* Body param:
*/
max_length?: number;
}
interface ImageToText {
/**
* Path param:
*/
account_id: string;
/**
* Body param:
*/
image: Array<number>;
/**
* Body param:
*/
max_tokens?: number;
/**
* Body param:
*/
messages?: Array<AIRunParams.ImageToText.Message>;
/**
* Body param:
*/
prompt?: string;
/**
* Body param:
*/
raw?: boolean;
/**
* Body param:
*/
temperature?: number;
}
namespace ImageToText {
interface Message {
content: string;
role: string;
}
}
}
export declare namespace AI {
export import AIRunResponse = AIAPI.AIRunResponse;
export import AIRunParams = AIAPI.AIRunParams;
}
//# sourceMappingURL=ai.d.ts.map