Skip to content
Closed

test #10

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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @KO1231
37 changes: 37 additions & 0 deletions .github/workflows/close_pr_from_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Close Pull Requests from main
on:
pull_request_target:
types:
- opened
- reopened
- edited

permissions:
contents: read
issues: write
pull-requests: write

jobs:
close_pr_from_main:
runs-on: ubuntu-latest
if: github.head_ref == 'main'
steps:
- name: Close PR
uses: actions/github-script@v7
with:
script: |
const commentParams = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: 'Pull request from main branch is restricted.',
};
const closeParams = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
state: 'closed',
};

await github.rest.issues.createComment(commentParams);
await github.rest.pulls.update(closeParams);
42 changes: 42 additions & 0 deletions .github/workflows/close_pr_to_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Close Pull Requests to main
on:
pull_request_target:
branches:
- main
types:
- opened
- reopened
- edited

permissions:
contents: read
issues: write
pull-requests: write

jobs:
close_pr_to_main:
runs-on: ubuntu-latest
if: |
github.head_ref != 'develop' &&
github.head_ref != 'hotfix' &&
!startsWith(github.head_ref, 'hotfix/')
steps:
- name: Close PR
uses: actions/github-script@v7
with:
script: |
const commentParams = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: 'Pull request to main branch from this branch is restricted.',
};
const closeParams = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
state: 'closed',
};

await github.rest.issues.createComment(commentParams);
await github.rest.pulls.update(closeParams);
2 changes: 1 addition & 1 deletion email_priority_classifier/classifier/classifier_gptoss.py
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", ""))
Comment on lines 38 to +41

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve whitespace in decoded email bodies

The new _decode_body now strips every carriage return, newline, and tab by replacing them with the empty string (lines 38‑41). For any multi‑line plain‑text email this merges adjacent tokens—for example "Order number:\n1234" becomes "Order number:1234"—and collapses paragraphs before the text is fed to the classifier. Because _encode_thread_messages forwards this string to both OpenAI/GPTOSS prompts, every classification request on emails containing line breaks now operates on corrupted content, which will noticeably hurt accuracy. The decoded body needs to preserve its whitespace (or at least replace it with spaces) instead of deleting it outright.

Useful? React with 👍 / 👎.

"""
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