Edits history of script submission #9785 for ' List corpora (vectara)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vectara = {
    	apiKey: string
    }
    /**
     * List corpora
     * List corpora in the account. The corpus objects that are returned are less
    detailed than the direct corpus retrieval operation.
    
     */
    export async function main(
    	auth: Vectara,
    	limit: string | undefined,
    	filter: string | undefined,
    	page_key: string | undefined
    ) {
    	const url = new URL(`https://api.vectara.io/v2/corpora`)
    	for (const [k, v] of [
    		['limit', limit],
    		['filter', filter],
    		['page_key', page_key]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			'x-api-key': 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 581 days ago