🐛 Bug: Fix the bug of undefined review content.
Browse files
main.py
CHANGED
@@ -470,14 +470,24 @@ class StatsMiddleware(BaseHTTPMiddleware):
|
|
470 |
model = request_model.model
|
471 |
current_info["model"] = model
|
472 |
|
|
|
473 |
if request_model.request_type == "chat":
|
474 |
moderated_content = request_model.get_last_text_message()
|
475 |
elif request_model.request_type == "image":
|
476 |
moderated_content = request_model.prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
477 |
if moderated_content:
|
478 |
current_info["text"] = moderated_content
|
479 |
|
480 |
-
|
481 |
if enable_moderation and moderated_content:
|
482 |
moderation_response = await self.moderate_content(moderated_content, api_index)
|
483 |
is_flagged = moderation_response.get('results', [{}])[0].get('flagged', False)
|
|
|
470 |
model = request_model.model
|
471 |
current_info["model"] = model
|
472 |
|
473 |
+
moderated_content = None
|
474 |
if request_model.request_type == "chat":
|
475 |
moderated_content = request_model.get_last_text_message()
|
476 |
elif request_model.request_type == "image":
|
477 |
moderated_content = request_model.prompt
|
478 |
+
elif request_model.request_type == "moderation":
|
479 |
+
pass
|
480 |
+
elif request_model.request_type == "embedding":
|
481 |
+
if isinstance(request_model.input, list) and len(request_model.input) > 0 and isinstance(request_model.input[0], str):
|
482 |
+
moderated_content = "\n".join(request_model.input)
|
483 |
+
else:
|
484 |
+
moderated_content = request_model.input
|
485 |
+
else:
|
486 |
+
logger.error(f"Unknown request type: {request_model.request_type}")
|
487 |
+
|
488 |
if moderated_content:
|
489 |
current_info["text"] = moderated_content
|
490 |
|
|
|
491 |
if enable_moderation and moderated_content:
|
492 |
moderation_response = await self.moderate_content(moderated_content, api_index)
|
493 |
is_flagged = moderation_response.get('results', [{}])[0].get('flagged', False)
|
models.py
CHANGED
@@ -115,6 +115,8 @@ class EmbeddingRequest(BaseRequest):
|
|
115 |
input: Union[str, List[Union[str, int, List[int]]]] # 支持字符串或数组
|
116 |
model: str
|
117 |
encoding_format: Optional[str] = "float"
|
|
|
|
|
118 |
stream: bool = False
|
119 |
|
120 |
class AudioTranscriptionRequest(BaseRequest):
|
@@ -130,7 +132,7 @@ class AudioTranscriptionRequest(BaseRequest):
|
|
130 |
arbitrary_types_allowed = True
|
131 |
|
132 |
class ModerationRequest(BaseRequest):
|
133 |
-
input: str
|
134 |
model: Optional[str] = "text-moderation-latest"
|
135 |
stream: bool = False
|
136 |
|
@@ -150,12 +152,12 @@ class UnifiedRequest(BaseModel):
|
|
150 |
elif "file" in values:
|
151 |
values["data"] = AudioTranscriptionRequest(**values)
|
152 |
values["data"].request_type = "audio"
|
|
|
|
|
|
|
153 |
elif "input" in values:
|
154 |
values["data"] = ModerationRequest(**values)
|
155 |
values["data"].request_type = "moderation"
|
156 |
-
elif "input" in values:
|
157 |
-
values["data"] = EmbeddingRequest(**values)
|
158 |
-
values["data"].request_type = "embedding"
|
159 |
else:
|
160 |
raise ValueError("无法确定请求类型")
|
161 |
return values
|
|
|
115 |
input: Union[str, List[Union[str, int, List[int]]]] # 支持字符串或数组
|
116 |
model: str
|
117 |
encoding_format: Optional[str] = "float"
|
118 |
+
dimensions: Optional[int] = None
|
119 |
+
user: Optional[str] = None
|
120 |
stream: bool = False
|
121 |
|
122 |
class AudioTranscriptionRequest(BaseRequest):
|
|
|
132 |
arbitrary_types_allowed = True
|
133 |
|
134 |
class ModerationRequest(BaseRequest):
|
135 |
+
input: Union[str, List[str]]
|
136 |
model: Optional[str] = "text-moderation-latest"
|
137 |
stream: bool = False
|
138 |
|
|
|
152 |
elif "file" in values:
|
153 |
values["data"] = AudioTranscriptionRequest(**values)
|
154 |
values["data"].request_type = "audio"
|
155 |
+
elif "text-embedding" in values.get("model", ""):
|
156 |
+
values["data"] = EmbeddingRequest(**values)
|
157 |
+
values["data"].request_type = "embedding"
|
158 |
elif "input" in values:
|
159 |
values["data"] = ModerationRequest(**values)
|
160 |
values["data"].request_type = "moderation"
|
|
|
|
|
|
|
161 |
else:
|
162 |
raise ValueError("无法确定请求类型")
|
163 |
return values
|