Edits history of script submission #13265 for ' Get an embedding task's status (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Get an embedding task's status
     * Check the status of a current embedding task. Will be one of the following:
    - `queued` - Task is waiting to be picked up by a worker
    - `processing` - The embedding task is running
    - `success` - Task completed successfully and the bucket is embedded
    - `failure` - Task failed and no files were embedded successfully
    - `partial_success` - Some files were embedded successfully, but at least one failed
     */
    export async function main(auth: Telnyx, task_id: string) {
    	const url = new URL(`https://api.telnyx.com/v2/ai/embeddings/${task_id}`)
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago