Skip to content

Commit ac93708

Browse files
Refactor TypeChatJsonTranslator to use public attributes for type_name and schema_str. (#273)
* Refactor `TypeChatJsonTranslator` to use public attributes for `type_name` and `schema_str`. * Update samples.
1 parent fb4bdeb commit ac93708

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

python/examples/healthData/translator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def _create_request_prompt(self, intent: str) -> str:
4141
now = datetime.now()
4242

4343
prompt = F"""
44-
user: You are a service that translates user requests into JSON objects of type "{self._type_name}" according to the following TypeScript definitions:
44+
user: You are a service that translates user requests into JSON objects of type "{self.type_name}" according to the following TypeScript definitions:
4545
'''
46-
{self._schema_str}
46+
{self.schema_str}
4747
'''
4848
4949
user:

python/src/typechat/_internal/translator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class TypeChatJsonTranslator(Generic[T]):
1717
model: TypeChatLanguageModel
1818
validator: TypeChatValidator[T]
1919
target_type: type[T]
20-
_type_name: str
21-
_schema_str: str
20+
type_name: str
21+
schema_str: str
2222
_max_repair_attempts = 1
2323

2424
def __init__(
@@ -46,8 +46,8 @@ def __init__(
4646
error_text = "".join(f"\n- {error}" for error in conversion_result.errors)
4747
raise ValueError(f"Could not convert Python type to TypeScript schema: \n{error_text}")
4848

49-
self._type_name = conversion_result.typescript_type_reference
50-
self._schema_str = conversion_result.typescript_schema_str
49+
self.type_name = conversion_result.typescript_type_reference
50+
self.schema_str = conversion_result.typescript_schema_str
5151

5252
async def translate(self, input: str, *, prompt_preamble: str | list[PromptSection] | None = None) -> Result[T]:
5353
"""
@@ -102,9 +102,9 @@ async def translate(self, input: str, *, prompt_preamble: str | list[PromptSecti
102102

103103
def _create_request_prompt(self, intent: str) -> str:
104104
prompt = f"""
105-
You are a service that translates user requests into JSON objects of type "{self._type_name}" according to the following TypeScript definitions:
105+
You are a service that translates user requests into JSON objects of type "{self.type_name}" according to the following TypeScript definitions:
106106
```
107-
{self._schema_str}
107+
{self.schema_str}
108108
```
109109
The following is a user request:
110110
'''

0 commit comments

Comments
 (0)