diff --git a/email_priority_classifier/classifier/classifier_gptoss.py b/email_priority_classifier/classifier/classifier_gptoss.py index a975616..9a9b633 100644 --- a/email_priority_classifier/classifier/classifier_gptoss.py +++ b/email_priority_classifier/classifier/classifier_gptoss.py @@ -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 diff --git a/email_priority_classifier/classifier/classifier_openai.py b/email_priority_classifier/classifier/classifier_openai.py index 3f82ce2..eda4611 100644 --- a/email_priority_classifier/classifier/classifier_openai.py +++ b/email_priority_classifier/classifier/classifier_openai.py @@ -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", @@ -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 diff --git a/email_priority_classifier/classifier/email_priority_classifier.py b/email_priority_classifier/classifier/email_priority_classifier.py index 6a7ffca..39ebf41 100644 --- a/email_priority_classifier/classifier/email_priority_classifier.py +++ b/email_priority_classifier/classifier/email_priority_classifier.py @@ -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: diff --git a/email_priority_classifier/type/classified_email_data.py b/email_priority_classifier/type/classified_email_data.py index 6f1f7aa..2a1086f 100644 --- a/email_priority_classifier/type/classified_email_data.py +++ b/email_priority_classifier/type/classified_email_data.py @@ -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': @@ -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: @@ -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":