Skip to content

AI Tools

These types of modules allow to implement communication with LLMs known as Function calling.

Common Use Cases

Function calling allows you to more reliably get structured data back from the model. For example, you can:

  • Create assistants that answer questions by calling external APIs, e.g. define functions like send_email(to: string, body: string), or get_current_weather(location: string, unit: 'celsius' | 'fahrenheit').
  • Convert natural language into API calls, e.g. convert “Who are my top customers?” to get_customers(min_revenue: int, created_before: string, limit: int) and call your internal API.
  • Extract structured data from text, e.g. define a function called extract_data(name: string, birthday: string), or sql_query(query: string).

Sample

index.js
const crowdinModule = require('@crowdin/app-project-module');
const jsonForm = {
16 collapsed lines
formSchema: {
bio: {
type: 'string'
}
},
formUiSchema: {
bio: {
'ui:widget': 'htmlWidget',
'ui:options': {
'content': '<p>This one will be omitted, because formData provided</p>'
}
}
},
formData: {
bio: '<h2>Form Data!</h2>'
}
};
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',
aiTools: {
function: {
name: 'get_project_files',
description: 'Get project files.',
parameters: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name of the user'
}
},
required: ['name']
}
},
toolCalls: async ({ client, args, projectId, payload, context, req }) => {
const { data } = await client.sourceFilesApi
.withFetchAll()
.listProjectFiles(projectId);
const content = data.map(({data}) => ({id: data.id, name: data.name}));
return {
content,
error: 'some error'
}
}
},
aiToolsWidget: {
...jsonForm,
function: {
name: 'get_project_files',
description: 'Get project files.'
}
}
};
crowdinModule.createApp(configuration);

Configuration

aiTools Module

This module is used in classic cases. When module make some action or get some information and give result directly to LLM, cases like above.

It should implement the function attribute with the following properties:

{
name: string,
description: string,
parameters?: {
type: string,
properties: {
[key: string]: {
type: string,
description: string
}
},
required: string[]
}
}

The parameters is not required. But if presents, it should include two required attributes: type, properties. Refer to JSON Schema.

the properties attribute should be an object with keys as parameter names and values as parameter definitions. Each parameter definition should include the following properties.

toolCalls Function

The toolCalls function represents the actual implementation of the function. It should be an async function that takes the following arguments:

{
content: any,
error?: string
}

If the content is not a string, it will be stringifies. The error is optional and should be a string.

aiToolsWidget Module

This module is used when the module has own UI that would be rendered in chat as new message.

It can implement Json form, or own UI. In the example above, it implements Json form. Read more about User Interface.

More Tools in One App

Also, more than one tool can be defined in the application configuration. Attributes aiTools and aiToolsWidget may be defined as the array of module configs.

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',
aiTools: [
{
function: {
name: 'get_project_files',
description: 'Get project files.'
},
toolCalls: async ({ client, args, projectId, payload, context, req }) => {
const { data } = await client.sourceFilesApi
.withFetchAll()
.listProjectFiles(projectId);
return {
content: data.map(({data}) => ({id: data.id, name: data.name}))
}
}
},
{
function: {
name: 'get_project_languages',
description: 'Get project target languages.'
},
toolCalls: async ({ client, args, projectId, payload, context, req }) => {
const { data } = await client.projectsGroupsApi.getProject(projectId);
return {
content: data.targetLanguages.map(({id, name}) => ({id, name}))
}
}
}
]
};
crowdinModule.createApp(configuration);