Skip to content

Conversation

key4ng
Copy link
Collaborator

@key4ng key4ng commented Oct 7, 2025

Motivation

Basic support for conversation API CRUD

Modifications

Tests

## CREATE CONVERSATION

ubuntu@moirai-a10-exp:~/sglang$  curl http://localhost:30000/v1/conversations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "metadata": {"topic": "demo"}
  }'
{"id":"conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45","object":"conversation","created_at":1759852825,"metadata":{"topic":"demo"}}

## GET CONVERSATION
ubuntu@moirai-a10-exp:~/sglang$   curl http://localhost  curl http://localhost:30000/v1/conversations/conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45 \
  -H "Authorization: Bearer $OPENAI_API_KEY"
{"id":"conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45","object":"conversation","created_at":1759852825,"metadata":{"topic":"demo"}}

## UPDATE CONVERSATION -1: add and update metadata
ubuntu@moirai-a10-exp:~/sglang$ curl  http://localhost:30000/v1/conveubuntu@moirai-a10-exp:~/sglang$ curl  http://localhost:30000/v1/conversations/conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "metadata": {"topic": "demo_updated", "topic2": "yyds"}
  }'

## UPDATE CONVERSATION - 2: remove metadata
{"id":"conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45","object":"conversation","created_at":1759852825,"metadata":{"topic":"demo_updated","topic2":"yyds"}ubuntu@moirai-a10-exp:~/sglang$ curl  http://localhost:30000/v1/conversations/conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45 \\
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "metadata": {"topic2": null}
  }'
{"id":"conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45","object":"conversation","created_at":1759852825,"metadata":{"topic":"demo_updated"}}

## DELETE CONVERSATION
ubuntu@moirai-a10-exp:~/sglang$   curl -X DELET  curl -X DELETE http://localhost:30000/v1/conversations/conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45 \
  -H "Authorization: Bearer $OPENAI_API_KEY"
{"id":"conv_ad518b1f7eee8ce468023661f1529422cd1292da1f51fb45","object":"conversation.deleted","deleted":true}

Benchmarking and Profiling

Checklist

@key4ng
Copy link
Collaborator Author

key4ng commented Oct 7, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces CRUD functionality for conversations, including a ConversationStorage trait and several implementations (in-memory, no-op, and Oracle). It also exposes these operations via new API endpoints. The implementation is well-structured, particularly the use of spawn_blocking for synchronous database calls and the clear separation of concerns in the storage modules. I've provided a few suggestions to improve performance in the Oracle store, adhere more closely to Rust idioms, and enhance code readability in the server routing.

@key4ng
Copy link
Collaborator Author

key4ng commented Oct 7, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive CRUD (Create, Read, Update, Delete) functionality for conversations. It adds new storage backends, including in-memory, no-op, and a detailed Oracle implementation, along with the necessary data structures and API endpoints. The changes are well-structured. My review focuses on improving performance by reducing unnecessary data cloning in the Oracle store, fixing a compilation error in the conversation ID generation logic, and suggesting a more efficient and idiomatic approach to JSON serialization in the server handlers. Overall, this is a solid addition of a major feature.

@key4ng key4ng marked this pull request as ready for review October 7, 2025 16:57
@key4ng key4ng changed the title support conversation crud[wip] [router] support Openai router conversation API CRUD Oct 7, 2025
}
}

async fn v1_conversations_update(
Copy link
Collaborator

Choose a reason for hiding this comment

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

should conversation handlers happen in router?
instead of server?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah. my bad, resolved


async fn create_conversation(&self, _headers: Option<&HeaderMap>, body: &Value) -> Response {
// Parse metadata: allow object or null/absent
let metadata = match body.get("metadata") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add a todo
these spec validation should be elsewhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure added

@key4ng
Copy link
Collaborator Author

key4ng commented Oct 7, 2025

^^ @slin1237 ci completed, ready to review

@slin1237 slin1237 merged commit 4ed67c2 into sgl-project:main Oct 7, 2025
35 checks passed
ch-tiger1 pushed a commit to ch-tiger1/sglang that referenced this pull request Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants