MCPcopy Index your code
hub / github.com/microsoft/TypeChat / createProgramTranslator

Function createProgramTranslator

typescript/src/ts/program.ts:196–219  ·  view source on GitHub ↗
(model: TypeChatLanguageModel, schema: string)

Source from the content-addressed store, hash-verified

194 * @returns A `TypeChatJsonTranslator<Program>` instance.
195 */
196export function createProgramTranslator(model: TypeChatLanguageModel, schema: string): TypeChatJsonTranslator<Program> {
197 const validator = createTypeScriptJsonValidator<Program>(schema, "Program");
198 validator.createModuleTextFromJson = createModuleTextFromProgram;
199 const translator = createJsonTranslator<Program>(model, validator);
200 translator.createRequestPrompt = createRequestPrompt;
201 translator.createRepairPrompt = createRepairPrompt;
202 return translator;
203
204 function createRequestPrompt(request: string) {
205 return `You are a service that translates user requests into programs represented as JSON using the following TypeScript definitions:\n` +
206 `\`\`\`\n${programSchemaText}\`\`\`\n` +
207 `The programs can call functions from the API defined in the following TypeScript definitions:\n` +
208 `\`\`\`\n${validator.getSchemaText()}\`\`\`\n` +
209 `The following is a user request:\n` +
210 `"""\n${request}\n"""\n` +
211 `The following is the user request translated into a JSON program object with 2 spaces of indentation and no properties with the value undefined:\n`;
212 }
213
214 function createRepairPrompt(validationError: string) {
215 return `The JSON program object is invalid for the following reason:\n` +
216 `"""\n${validationError}\n"""\n` +
217 `The following is a revised JSON program object:\n`;
218 }
219}

Callers 3

createJsonMathAgentFunction · 0.90
main.tsFile · 0.90
main.tsFile · 0.90

Calls 2

createJsonTranslatorFunction · 0.90

Tested by

no test coverage detected