Spaces:
Sleeping
Sleeping
Commit
·
15478bb
1
Parent(s):
aad5401
compatibility fix
Browse files
main.py
CHANGED
|
@@ -65,9 +65,31 @@ def build_notion_request(request_data: ChatCompletionRequest) -> NotionRequestBo
|
|
| 65 |
if message.role == "assistant":
|
| 66 |
# Notion uses "markdown-chat" for assistant replies in the transcript history
|
| 67 |
transcript.append(NotionTranscriptItem(type="markdown-chat", value=message.content))
|
| 68 |
-
else:
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Use globally configured spaceId, set createThread=True
|
| 73 |
return NotionRequestBody(
|
|
|
|
| 65 |
if message.role == "assistant":
|
| 66 |
# Notion uses "markdown-chat" for assistant replies in the transcript history
|
| 67 |
transcript.append(NotionTranscriptItem(type="markdown-chat", value=message.content))
|
| 68 |
+
else: # Handles 'user', 'system', etc.
|
| 69 |
+
content = message.content
|
| 70 |
+
if isinstance(content, str):
|
| 71 |
+
# Handle string content: Append one item, using default [[""]] for empty strings
|
| 72 |
+
notion_value = [[content]] if content else [[""]]
|
| 73 |
+
transcript.append(NotionTranscriptItem(type="user", value=notion_value))
|
| 74 |
+
elif isinstance(content, list):
|
| 75 |
+
# Handle list content: Append a SEPARATE item for each valid text part
|
| 76 |
+
found_text_part = False
|
| 77 |
+
for part in content:
|
| 78 |
+
# Check if part is a dict with type="text" and non-empty text
|
| 79 |
+
if isinstance(part, dict) and part.get("type") == "text":
|
| 80 |
+
text_content = part.get("text")
|
| 81 |
+
if isinstance(text_content, str) and text_content:
|
| 82 |
+
# Create and append a SEPARATE item for this text part
|
| 83 |
+
transcript.append(NotionTranscriptItem(type="user", value=[[text_content]]))
|
| 84 |
+
found_text_part = True
|
| 85 |
+
# If the list was empty or had no valid text parts, append a default empty item to maintain behavior
|
| 86 |
+
if not found_text_part:
|
| 87 |
+
print(f'Error: no valid input found: {message}')
|
| 88 |
+
transcript.append(NotionTranscriptItem(type="user", value=[[""]]))
|
| 89 |
+
else:
|
| 90 |
+
# Handle unexpected content types (e.g., None, int) by appending a default empty item
|
| 91 |
+
transcript.append(NotionTranscriptItem(type="user", value=[[""]]))
|
| 92 |
+
print(f'Error: no valid input found: {message}')
|
| 93 |
|
| 94 |
# Use globally configured spaceId, set createThread=True
|
| 95 |
return NotionRequestBody(
|
models.py
CHANGED
|
@@ -8,7 +8,7 @@ from typing import List, Optional, Dict, Any, Literal, Union
|
|
| 8 |
# Input Models (OpenAI-like)
|
| 9 |
class ChatMessage(BaseModel):
|
| 10 |
role: Literal["system", "user", "assistant"]
|
| 11 |
-
content: str
|
| 12 |
|
| 13 |
class ChatCompletionRequest(BaseModel):
|
| 14 |
messages: List[ChatMessage]
|
|
|
|
| 8 |
# Input Models (OpenAI-like)
|
| 9 |
class ChatMessage(BaseModel):
|
| 10 |
role: Literal["system", "user", "assistant"]
|
| 11 |
+
content: Union[str, List[Dict[str, Any]]]
|
| 12 |
|
| 13 |
class ChatCompletionRequest(BaseModel):
|
| 14 |
messages: List[ChatMessage]
|