Skip to main content
Glama

mcp-google-sheets

create-embeddings.ts1.92 kB
import { createAction, Property } from '@activepieces/pieces-framework'; import { HttpMethod, httpClient, AuthenticationType } from '@activepieces/pieces-common'; import { mistralAuth } from '../common/auth'; import { parseMistralError } from '../common/props'; export const createEmbeddings = createAction({ auth: mistralAuth, name: 'create_embeddings', displayName: 'Create Embeddings', description: 'Creates new embedding in Mistral AI.', props: { input: Property.Array({ displayName: 'Input', description: 'The input text for which to create an embedding.', required: true, }), timeout: Property.Number({ displayName: 'Timeout (ms)', required: false, defaultValue: 30000 }), }, async run(context) { const { input, timeout } = context.propsValue; let inputArr: string[] = []; try { if (typeof input === 'string') { try { inputArr = JSON.parse(input); } catch { inputArr = input; } } inputArr = input as string[]; } catch { throw new Error('Input must be a non-empty string or a JSON array of non-empty strings'); } const body = { model: 'mistral-embed', input: inputArr, }; let lastErr; for (let attempt = 0; attempt <= 3; ++attempt) { try { const response = await httpClient.sendRequest({ method: HttpMethod.POST, url: 'https://api.mistral.ai/v1/embeddings', authentication: { type: AuthenticationType.BEARER_TOKEN, token: context.auth, }, body, timeout: timeout ?? 30000, }); return response.body; } catch (e: any) { lastErr = e; const status = e.response?.status; if (status === 429 || (status && status >= 500 && status < 600)) { if (attempt < 3) { await new Promise((r) => setTimeout(r, 1000 * (attempt + 1))); continue; } } throw new Error(parseMistralError(e)); } } throw new Error(parseMistralError(lastErr)); }, });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/activepieces/activepieces'

If you have feedback or need assistance with the MCP directory API, please join our Discord server