translation: speficied / implemented the question format for OpenAI based translations

This commit is contained in:
2023-11-08 19:36:43 +01:00
parent c1dc152f48
commit a185c0db7b
2 changed files with 57 additions and 23 deletions
+7 -2
View File
@@ -7,6 +7,12 @@ from pathlib import Path
from ..message import Message, MessageError, source_code
def read_text_file(file: Path) -> str:
with open(file) as r:
content = r.read().strip()
return content
def add_file_as_text(question_parts: list[str], file: str) -> None:
"""
Add the given file as plain text to the question part list.
@@ -19,8 +25,7 @@ def add_file_as_text(question_parts: list[str], file: str) -> None:
if message and message.answer:
content = message.answer
except MessageError:
with open(file) as r:
content = r.read().strip()
content = read_text_file(Path(file))
if len(content) > 0:
question_parts.append(content)