From 966c7f0280a6ee79b50b6f85cac430ceaca696ed Mon Sep 17 00:00:00 2001 From: Martin Breuss Date: Tue, 22 Oct 2024 10:37:34 +0200 Subject: [PATCH] Force utf-8 output Based on a user comment: https://realpython.com/practical-prompt-engineering/#comment-6571881084 --- prompt-engineering/app.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prompt-engineering/app.py b/prompt-engineering/app.py index 1405739ac9..afea1d635a 100644 --- a/prompt-engineering/app.py +++ b/prompt-engineering/app.py @@ -1,5 +1,7 @@ import argparse +import io import os +import sys import tomllib from pathlib import Path @@ -7,6 +9,9 @@ __all__ = ["get_chat_completion"] +# Force UTF-8 output to avoid encoding issues +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") + # Authenticate client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))