Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def calc(self, thread_messages: list[ClassifiedEmailData]) -> EmailPriority:
input=request_input
)

logger.debug(f"GPTOSS request_data: {json.dumps(request_input, indent=2)}")
logger.debug(f"GPTOSS request_data: {json.dumps(request_input, indent=2, ensure_ascii=False)}")
except Exception as e:
raise EmailPriorityClassifierOpenAIException("Some error occurred while calling the GPTOSS API.") from e

Expand Down
4 changes: 2 additions & 2 deletions email_priority_classifier/classifier/classifier_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def calc(self, thread_messages: list[ClassifiedEmailData]) -> EmailPriority:
try:
data = {
"thread_subject": thread_messages[0].subject,
"thread_messages": super()._encode_thread_messages(thread_messages)[:1500], # 大体4000前後input-tokenくらい
"thread_messages": super()._encode_thread_messages(thread_messages)[:2500], # 大体4000前後input-tokenくらい
}
response = _CLIENT.responses.create(
# model="gpt-5-nano",
Expand All @@ -41,7 +41,7 @@ def calc(self, thread_messages: list[ClassifiedEmailData]) -> EmailPriority:
}
)

logger.debug(f"OpenAPI request_data: {json.dumps(data, indent=2)}")
logger.debug(f"OpenAPI request_data: {json.dumps(data, indent=2, ensure_ascii=False)}")
except Exception as e:
raise EmailPriorityClassifierOpenAIException("Some error occurred while calling the OpenAI API.") from e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _encode_thread_messages(thread_messages: list[ClassifiedEmailData]) -> str:
return json.dumps({
"labels": list(labels),
"messages": thread_messages
}, cls=ClassifiedEmailDataEncoder)
}, cls=ClassifiedEmailDataEncoder, ensure_ascii=False)

@abstractmethod
def calc(self, thread_messages: list[ClassifiedEmailData]) -> EmailPriority:
Expand Down
9 changes: 5 additions & 4 deletions email_priority_classifier/type/classified_email_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def _extract_subject_from_payload(payload: dict) -> str:

@staticmethod
def _decode_body(body: str, headers: list[dict]) -> str:
return base64.urlsafe_b64decode(body).decode("utf-8")
return (base64.urlsafe_b64decode(body).decode("utf-8")
.replace("\r", "").replace("\n", "").replace("\t", ""))
"""
for header in headers:
if header.get("name", "").lower() == 'content-transfer-encoding':
Expand All @@ -61,7 +62,7 @@ def get_data(self) -> str:
body = payload.get("body", {})
if len(body) != 0 and body.get("size", 0) != 0:
data = self._decode_body(body["data"], payload.get("headers", []))
return json.dumps(data)
return data

text_parts = [part for part in payload.get("parts", []) if part.get("mimeType", "").startswith("text/")]
if len(text_parts) == 0:
Expand All @@ -75,9 +76,9 @@ def get_data(self) -> str:
if body_data is None:
return "body data could not found."
data = self._decode_body(text_part["body"]["data"], text_part.get("headers", []))
return json.dumps(data)
return data

return json.dumps(text_parts[0])
return json.dumps(text_parts[0], ensure_ascii=False)

@classmethod
def init(cls, message: dict, personal_labels_info: dict[str, str]) -> "ClassifiedEmailData":
Expand Down