@crowdin/app-project-module
Version:
Module that generates for you all common endpoints for serving standalone Crowdin App
156 lines (155 loc) • 5.05 kB
TypeScript
import { CrowdinClientRequest, CrowdinContextInfo, Environments, ModuleKey, UiModule } from '../../types';
import Crowdin from '@crowdin/crowdin-api-client';
import { ExtendedResult } from '../integration/types';
export interface AiProviderModule extends Environments, ModuleKey {
/**
* module name
*/
name: string;
/**
* module description
*/
description: string;
/**
* Settings UI module
*/
settingsUiModule?: UiModule;
/**
* processes a sequence of conversation messages and generates responses from the assistant
*/
chatCompletions: ({ messages, model, action, responseFormat, client, context, req, isStream, sendEvent, tools, toolChoice, }: {
messages: ChatCompletionMessage[];
model: string;
action: string;
responseFormat: string;
client: Crowdin;
context: CrowdinContextInfo;
req: CrowdinClientRequest;
isStream: boolean;
sendEvent: (chunk: ChatCompletionChunkMessage) => Promise<void>;
tools?: ChatCompletionTool[];
toolChoice?: string | AiToolChoice;
}) => Promise<ChatCompletionResponseMessage[] | ExtendedResult<ChatCompletionResponseMessage[]> | void>;
/**
* provides a list of available model
*/
getModelsList: ({ client, context, }: {
client: Crowdin;
context: CrowdinContextInfo;
}) => Promise<SupportedModels[]>;
}
export interface SupportedModels {
id: string;
supportsJsonMode?: boolean;
supportsFunctionCalling?: boolean;
supportsStreaming?: boolean;
supportsVision?: boolean;
contextWindowLimit?: number;
outputLimit?: number;
}
export interface ChatCompletionTool {
type: 'function';
function: ChatCompletionToolFunctionDeclaration;
}
export interface ChatCompletionToolFunctionDeclaration {
/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
*/
name: string;
/**
* A description of what the function does, used by the model to choose when and how to call the function.
*/
description?: string;
/**
* The parameters the functions accepts, described as a JSON Schema object.
* https://json-schema.org/understanding-json-schema/
*/
parameters?: object;
}
export interface AiToolChoice {
type: 'function';
function: {
/**
* The name of the function to call.
*/
name: string;
};
}
export type ChatCompletionMessage = ChatCompletionSystemMessage | ChatCompletionUserMessage | ChatCompletionAssistantMessage | ChatCompletionToolMessage;
export interface ChatCompletionSystemMessage {
role: 'system';
content: string | ChatCompletionContentPartText[];
}
export interface ChatCompletionUserMessage {
role?: 'user';
content: string | ChatCompletionContentPart[];
}
export type ChatCompletionResponseMessage = ChatCompletionAssistantMessage;
export interface ChatCompletionAssistantMessage {
role?: 'assistant';
content?: string | ChatCompletionContentPartText[] | null;
tool_calls?: ChatCompletionMessageToolCall[] | null;
}
export interface ChatCompletionChunkMessage {
role?: ROLES;
content?: string | null;
tool_calls?: ChatCompletionDeltaMessageToolCall[];
}
export interface ChatCompletionToolMessage {
content: string | ChatCompletionContentPartText[];
role: 'tool';
/**
* Tool call that this message is responding to.
*/
tool_call_id: string;
}
export type ROLES = 'user' | 'assistant' | 'system' | 'tool';
export type ChatCompletionContentPart = ChatCompletionContentPartText | ChatCompletionContentPartImage;
export type ChatCompletionContentPartText = {
type: 'text';
text: string;
};
export type ChatCompletionContentPartImage = {
type: 'image_url';
image_url: {
/**
* Either a URL of the image or the base64 encoded image data.
*/
url: string;
};
};
export interface ChatCompletionMessageToolCall {
id: string;
type: 'function';
function: {
/**
* The arguments to call the function with, as generated by the model in JSON format.
* Note that the model does not always generate valid JSON.
*/
arguments?: string;
name: string;
};
}
export interface ChatCompletionDeltaMessageToolCall {
index: number;
id?: string;
type?: 'function';
function?: {
/**
* The arguments to call the function with, as generated by the model in JSON format.
* Note that the model does not always generate valid JSON.
*/
arguments?: string;
name?: string;
};
}
export interface InputMessage {
role?: ROLES;
content: string | InputContentPart[];
}
export type InputContentPart = ChatCompletionContentPartText | InputChatCompletionContentPartImage;
export type InputChatCompletionContentPartImage = {
type: 'image';
mimeType: string;
url: string;
};