Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
khanh nguyen
Openai Service
Commits
6407c7d0
Commit
6407c7d0
authored
Dec 19, 2025
by
server1
Browse files
KHANHNQ: Update ai and model
parent
6c16d772
Changes
1
Hide whitespace changes
Inline
Side-by-side
ai_service/openai_handler.py
View file @
6407c7d0
...
...
@@ -38,7 +38,7 @@ class OpenAIHandler:
elif
state
==
ProcessingState
.
PROCESSING
:
try
:
response
=
self
.
client
.
chat
.
completions
.
create
(
model
=
"gpt-5"
,
model
=
"gpt-5
-nano
"
,
messages
=
[
{
"role"
:
"user"
,
...
...
@@ -92,26 +92,6 @@ class OpenAIHandler:
elif
state
==
ProcessingState
.
PROCESSING
:
self
.
logger
.
info
(
"start processing"
)
try
:
# prompt = f"""
# Bạn là bộ lọc thông tin nhạy cảm (PII) và thông tin doanh nghiệp.
# Phân tích văn bản dưới đây và trả về {WarningResult.WARNING} nếu có bất kỳ thông tin nhạy cảm nào, {WarningResult.ACCEPTED} nếu không có.
# Chỉ trả {WarningResult.WARNING} hoặc {WarningResult.ACCEPTED}, KHÔNG giải thích gì thêm.
# Văn bản:
# {message}
# Các loại thông tin nhạy cảm cần kiểm tra:
# 1. Thông tin cá nhân:
# - Tên riêng (ít nhất 2 từ)
# - Email cá nhân
# - Số CCCD/CMND (9-12 chữ số)
# - Số điện thoại (VN: 10-11 chữ số)
# - Số hộ chiếu
# 2. Thông tin doanh nghiệp/đối tác:
# - Tên công ty/doanh nghiệp
# - Email liên hệ công ty
# - Số điện thoại liên hệ công ty
# """
prompt
=
f
"""
Bạn là bộ lọc phát hiện thông tin nhạy cảm (PII và thông tin doanh nghiệp).
Nhiệm vụ: phân tích văn bản và trả về đúng một trong hai giá trị:
...
...
@@ -140,12 +120,11 @@ class OpenAIHandler:
{
message
}
"""
response
=
self
.
client
.
chat
.
completions
.
create
(
model
=
"gpt-5"
,
model
=
"gpt-5
-nano
"
,
messages
=
[
{
"role"
:
"system"
,
"content"
:
"Bạn là bộ lọc thông tin nhạy cảm."
},
{
"role"
:
"user"
,
"content"
:
prompt
}
],
# temperature=0
)
result
=
response
.
choices
[
0
].
message
.
content
.
strip
()
self
.
logger
.
info
(
result
)
...
...
@@ -176,18 +155,6 @@ class OpenAIHandler:
# t.join()
return
def
validate_user_message
(
self
,
user_message
:
str
,
conversation_id
:
str
):
pass
def
on_validated_message
(
self
,
conversation_id
:
str
):
pass
def
evaluate_user_message
(
self
,
user_conversation
:
ConversationDTO
):
pass
def
on_evaluated_user_message
(
self
,
conversation_id
:
str
):
pass
def
chat
(
self
,
chat_id
:
str
,
input
,
model
:
str
,
on_response_callback
:
Callable
[[
str
,
str
,
str
,
str
,
Optional
[
str
],
str
],
None
],
spread_sheet_file_ids
:
List
[
str
]
=
[],):
...
...
@@ -210,10 +177,3 @@ class OpenAIHandler:
on_response_callback
(
self
.
conversation_id
,
chat_id
,
event
.
delta
,
ResponseType
.
CONTENT
,
None
,
model
)
if
event
.
type
==
"response.output_text.done"
:
on_response_callback
(
self
.
conversation_id
,
chat_id
,
event
.
text
,
ResponseType
.
DONE
,
input
[
-
1
].
get
(
"content"
)[
0
].
get
(
"text"
),
model
)
# def file_handler(self, url: str):
# file = self.client.files.create(
# file=("draconomicon.pdf", response.content), # tên file + binary data
# purpose="user_data"
# )
# return file.id
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment