From 756027325dc9c95a4232f045e2a413655635376b Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 22 Apr 2024 16:02:41 -0700 Subject: [PATCH] Alternate prompting scheme from #241 --- python/src/typechat/_internal/translator.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/python/src/typechat/_internal/translator.py b/python/src/typechat/_internal/translator.py index 6c649c1e..63751a13 100644 --- a/python/src/typechat/_internal/translator.py +++ b/python/src/typechat/_internal/translator.py @@ -64,14 +64,14 @@ async def translate(self, input: str, *, prompt_preamble: str | list[PromptSecti messages: list[PromptSection] = [] - messages.append({"role": "user", "content": input}) + messages.append({"role": "system", "content": self._create_request_prompt(input)}) + if prompt_preamble: if isinstance(prompt_preamble, str): prompt_preamble = [{"role": "user", "content": prompt_preamble}] - else: - messages.extend(prompt_preamble) + messages.extend(prompt_preamble) - messages.append({"role": "user", "content": self._create_request_prompt(input)}) + messages.append({"role": "user", "content": input}) num_repairs_attempted = 0 while True: @@ -103,11 +103,7 @@ def _create_request_prompt(self, intent: str) -> str: ``` {self._schema_str} ``` -The following is a user request: -''' -{intent} -''' -The following is the user request translated into a JSON object with 2 spaces of indentation and no properties with the value undefined: +You translate each user request into a JSON object with 2 spaces of indentation and no properties with the value undefined. """ return prompt