Skip to content

AI Request Processors Modules

AI Request Processors:

  • Pre-compile module - executed before prompt text compilation. Module receives and can manipulate data that will be included in the prompt (e.g. for pre-translation prompts, it’s strings, glossary terms, TM matches, etc.);
  • Post-compile module - executed after prompt text compilation. Module receives and can manipulate full prompt body and headers. Module should maintain compatibility with used AI provider.
  • Pre-parse module - executed after receiving response from AI. Module receives and can manipulate full response body or stream chunks if request was made in streaming mode.
  • Post-parse module - executed after response is transformed into Crowdin objects for built-in actions (pre-translation, QA checks, alignment). Module receives and can manipulate list of objects parsed from response.

Sample

index.js
const crowdinModule = require('@crowdin/app-project-module');
const configuration = {
baseUrl: 'https://123.ngrok.io',
clientId: 'clientId',
clientSecret: 'clientSecret',
name: 'Sample App',
identifier: 'sample-app',
description: 'Sample App description',
dbFolder: __dirname,
imagePath: __dirname + '/' + 'logo.png',
aiRequestPreCompile: {
async processRequest(requestData, requestContext, client, crowdinContext) {
return requestData;
}
},
aiRequestPostCompile: {
async processRequest(requestData, requestContext, client, crowdinContext) {
return requestData;
}
},
aiRequestPreParse: {
async processRequest(requestData, requestContext, client, crowdinContext) {
return requestData;
},
// optional method to handle streams
// works with SSE chunks
async processStream(chunk, requestContext, client, crowdinContext) {
return chunk;
}
},
aiRequestPostParse: {
async processRequest(requestData, requestContext) {
return requestData;
}
},
},
};
crowdinModule.createApp(configuration);

processRequest Function

Used to update request data.

Parameters

  • requestData - Can vary depends on module and prompt action. E.g. for post-parse pre-translation prompt it will be object with next structure { "strings": []] }.
  • requestContext - Context data for request (model and it’s limitations, AI provider type and ID, project ID and prompt action).
  • client - Crowdin API client.
  • context - Context object.

Return Value

The function should return the updated data.

processStream Function

Optional function for aiRequestPreParse module. Used to update stream chunks. Should return updated chunks.

Parameters

  • chunk - Server-Sent Events chunk.
  • requestContext - Context data for request (model and it’s limitations, AI provider type and ID, project ID and prompt action).
  • client - Crowdin API client.
  • context - Context object.

Return Value

The function should return the updated chunk.