Skip to content

Commit 1d20ec7

Browse files
committed
Make sure llm-prompt never returns bad characters to the monitor
1 parent 0a9897e commit 1d20ec7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lemonade/tools/chat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
END_OF_STREAM = "</s>"
2727

2828

29+
def sanitize_string(input_string):
30+
return input_string.encode("utf-8", "ignore").decode("utf-8")
31+
32+
2933
class LLMPrompt(Tool):
3034
"""
3135
Send a prompt to an LLM instance and print the response to the screen.
@@ -105,7 +109,7 @@ def run(
105109
state.save_stat(Keys.PROMPT_TOKENS, len_tokens_in)
106110
state.save_stat(Keys.PROMPT, prompt)
107111
state.save_stat(Keys.RESPONSE_TOKENS, len_tokens_out)
108-
state.save_stat(Keys.RESPONSE, response_text)
112+
state.save_stat(Keys.RESPONSE, sanitize_string(response_text))
109113

110114
return state
111115

0 commit comments

Comments
 (0)