MCPcopy Create free account
hub / github.com/microsoft/TypeChat / TypeChatProgramTranslator

Class TypeChatProgramTranslator

python/examples/math/program.py:120–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118
119
120class TypeChatProgramTranslator(TypeChatJsonTranslator[JsonProgram]):
121 _api_declaration_str: str
122
123 def __init__(self, model: TypeChatLanguageModel, validator: TypeChatProgramValidator, api_type: type):
124 super().__init__(model=model, validator=validator, target_type=api_type, _raise_on_schema_errors = False)
125 # TODO: the conversion result here has errors!
126 conversion_result = python_type_to_typescript_schema(api_type)
127 self._api_declaration_str = conversion_result.typescript_schema_str
128
129 @override
130 def _create_request_prompt(self, intent: str) -> str:
131
132 prompt = F"""
133You are a service that translates user requests into programs represented as JSON using the following TypeScript definitions:
134```
135{program_schema_text}
136```
137The programs can call functions from the API defined in the following TypeScript definitions:
138```
139{self._api_declaration_str}
140```
141The following is a user request:
142'''
143{intent}
144'''
145The following is the user request translated into a JSON program object with 2 spaces of indentation and no properties with the value undefined:
146"""
147 return prompt
148
149 @override
150 def _create_repair_prompt(self, validation_error: str) -> str:
151 prompt = F"""
152The JSON program object is invalid for the following reason:
153'''
154{validation_error}
155'''
156The following is a revised JSON program object:
157"""
158 return prompt

Callers 2

__init__Method · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…