Skip to content

Commit ff7f062

Browse files
committed
put endpoint to update topic summary
Signed-off-by: Stephanie <[email protected]>
1 parent 690a6bc commit ff7f062

File tree

6 files changed

+343
-1
lines changed

6 files changed

+343
-1
lines changed

src/app/endpoints/conversations_v2.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
from configuration import configuration
1111
from models.cache_entry import CacheEntry
1212
from models.config import Action
13+
from models.requests import ConversationUpdateRequest
1314
from models.responses import (
1415
ConversationDeleteResponse,
1516
ConversationResponse,
17+
ConversationUpdateResponse,
1618
ConversationsListResponseV2,
1719
UnauthorizedResponse,
1820
)
@@ -89,6 +91,29 @@
8991
}
9092
}
9193

94+
conversation_update_responses: dict[int | str, dict[str, Any]] = {
95+
200: {
96+
"conversation_id": "123e4567-e89b-12d3-a456-426614174000",
97+
"success": True,
98+
"message": "Topic summary updated successfully",
99+
"topic_summary": "Updated topic summary",
100+
},
101+
400: {
102+
"description": "Missing or invalid credentials provided by client",
103+
"model": UnauthorizedResponse,
104+
},
105+
401: {
106+
"description": "Unauthorized: Invalid or missing Bearer token",
107+
"model": UnauthorizedResponse,
108+
},
109+
404: {
110+
"detail": {
111+
"response": "Conversation not found",
112+
"cause": "The specified conversation ID does not exist.",
113+
}
114+
},
115+
}
116+
92117

93118
@router.get("/conversations", responses=conversations_list_responses)
94119
@authorize(Action.LIST_CONVERSATIONS)
@@ -207,6 +232,58 @@ async def delete_conversation_endpoint_handler(
207232
)
208233

209234

235+
@router.put(
236+
"/conversations/{conversation_id}", responses=conversation_update_responses
237+
)
238+
@authorize(Action.UPDATE_CONVERSATION)
239+
async def update_conversation_endpoint_handler(
240+
conversation_id: str,
241+
update_request: ConversationUpdateRequest,
242+
auth: Any = Depends(get_auth_dependency()),
243+
) -> ConversationUpdateResponse:
244+
"""Handle request to update a conversation topic summary by ID."""
245+
check_configuration_loaded(configuration)
246+
check_valid_conversation_id(conversation_id)
247+
248+
user_id = auth[0]
249+
logger.info(
250+
"Updating topic summary for conversation %s for user %s",
251+
conversation_id,
252+
user_id,
253+
)
254+
255+
skip_userid_check = auth[2]
256+
257+
if configuration.conversation_cache is None:
258+
logger.warning("Conversation cache is not configured")
259+
raise HTTPException(
260+
status_code=status.HTTP_404_NOT_FOUND,
261+
detail={
262+
"response": "Conversation cache is not configured",
263+
"cause": "Conversation cache is not configured",
264+
},
265+
)
266+
267+
check_conversation_existence(user_id, conversation_id)
268+
269+
# Update the topic summary in the cache
270+
configuration.conversation_cache.set_topic_summary(
271+
user_id, conversation_id, update_request.topic_summary, skip_userid_check
272+
)
273+
274+
logger.info(
275+
"Successfully updated topic summary for conversation %s for user %s",
276+
conversation_id,
277+
user_id,
278+
)
279+
280+
return ConversationUpdateResponse(
281+
conversation_id=conversation_id,
282+
success=True,
283+
message="Topic summary updated successfully",
284+
)
285+
286+
210287
def check_valid_conversation_id(conversation_id: str) -> None:
211288
"""Check validity of conversation ID format."""
212289
if not check_suid(conversation_id):

src/models/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ class Action(str, Enum):
356356

357357
# Access the conversation delete endpoint
358358
DELETE_CONVERSATION = "delete_conversation"
359+
360+
# Access the conversation update endpoint
361+
UPDATE_CONVERSATION = "update_conversation"
359362
FEEDBACK = "feedback"
360363
GET_MODELS = "get_models"
361364
GET_TOOLS = "get_tools"

src/models/requests.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,29 @@ class FeedbackStatusUpdateRequest(BaseModel):
410410
def get_value(self) -> bool:
411411
"""Return the value of the status attribute."""
412412
return self.status
413+
414+
415+
class ConversationUpdateRequest(BaseModel):
416+
"""Model representing a request to update a conversation topic summary.
417+
418+
Attributes:
419+
topic_summary: The new topic summary for the conversation.
420+
421+
Example:
422+
```python
423+
update_request = ConversationUpdateRequest(
424+
topic_summary="Discussion about machine learning algorithms"
425+
)
426+
```
427+
"""
428+
429+
topic_summary: str = Field(
430+
...,
431+
description="The new topic summary for the conversation",
432+
examples=["Discussion about machine learning algorithms"],
433+
min_length=1,
434+
max_length=1000,
435+
)
436+
437+
# Reject unknown fields
438+
model_config = {"extra": "forbid"}

src/models/responses.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,38 @@ class FeedbackStatusUpdateResponse(BaseModel):
865865
]
866866
}
867867
}
868+
869+
870+
class ConversationUpdateResponse(BaseModel):
871+
"""Model representing a response for updating a conversation topic summary.
872+
873+
Attributes:
874+
conversation_id: The conversation ID (UUID) that was updated.
875+
success: Whether the update was successful.
876+
message: A message about the update result.
877+
878+
Example:
879+
```python
880+
update_response = ConversationUpdateResponse(
881+
conversation_id="123e4567-e89b-12d3-a456-426614174000",
882+
success=True,
883+
message="Topic summary updated successfully",
884+
)
885+
```
886+
"""
887+
888+
conversation_id: str = Field(
889+
...,
890+
description="The conversation ID (UUID) that was updated",
891+
examples=["123e4567-e89b-12d3-a456-426614174000"],
892+
)
893+
success: bool = Field(
894+
...,
895+
description="Whether the update was successful",
896+
examples=[True],
897+
)
898+
message: str = Field(
899+
...,
900+
description="A message about the update result",
901+
examples=["Topic summary updated successfully"],
902+
)

tests/integration/test_openapi_json.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ def test_servers_section_present(spec: dict):
7777
"delete",
7878
{"200", "400", "401", "404", "503", "422"},
7979
),
80+
(
81+
"/v1/conversations/{conversation_id}",
82+
"put",
83+
{"200", "400", "401", "404", "503", "422"},
84+
),
8085
("/readiness", "get", {"200", "503"}),
8186
("/liveness", "get", {"200"}),
8287
("/authorized", "post", {"200", "400", "401", "403"}),

0 commit comments

Comments
 (0)