"test/wmma_op/wmma_op.cpp" did not exist on "8784a72e23538d594ea6b1bd527478fba2962d30"
mod.rs 6.54 KB
Newer Older
1
2
//! Router implementations

3
4
use std::fmt::Debug;

5
use async_trait::async_trait;
6
7
8
9
10
11
use axum::{
    body::Body,
    extract::Request,
    http::{HeaderMap, StatusCode},
    response::{IntoResponse, Response},
};
12
use serde_json::Value;
13

14
15
16
17
18
19
20
21
22
use crate::protocols::{
    chat::ChatCompletionRequest,
    completion::CompletionRequest,
    embedding::EmbeddingRequest,
    generate::GenerateRequest,
    rerank::RerankRequest,
    responses::{ResponsesGetParams, ResponsesRequest},
};

23
pub mod factory;
24
pub mod grpc;
25
pub mod header_utils;
26
pub mod http;
27
pub mod openai; // New refactored OpenAI router module
28
pub mod router_manager;
29
30

pub use factory::RouterFactory;
31
32
// Re-export HTTP routers for convenience
pub use http::{pd_router, pd_types, router};
33
34
35
36
37

/// Core trait for all router implementations
///
/// This trait provides a unified interface for routing requests,
/// regardless of whether it's a regular router or PD router.
38
#[async_trait]
39
pub trait RouterTrait: Send + Sync + Debug {
40
41
    /// Get a reference to self as Any for downcasting
    fn as_any(&self) -> &dyn std::any::Any;
42

43
    /// Route a health generate request
44
    async fn health_generate(&self, req: Request<Body>) -> Response;
45
46

    /// Get server information
47
    async fn get_server_info(&self, req: Request<Body>) -> Response;
48
49

    /// Get available models
50
    async fn get_models(&self, req: Request<Body>) -> Response;
51
52

    /// Get model information
53
    async fn get_model_info(&self, req: Request<Body>) -> Response;
54
55

    /// Route a generate request
56
57
58
59
60
61
    async fn route_generate(
        &self,
        headers: Option<&HeaderMap>,
        body: &GenerateRequest,
        model_id: Option<&str>,
    ) -> Response;
62
63
64
65

    /// Route a chat completion request
    async fn route_chat(
        &self,
66
67
        headers: Option<&HeaderMap>,
        body: &ChatCompletionRequest,
68
        model_id: Option<&str>,
69
    ) -> Response;
70
71
72
73

    /// Route a completion request
    async fn route_completion(
        &self,
74
75
        headers: Option<&HeaderMap>,
        body: &CompletionRequest,
76
        model_id: Option<&str>,
77
    ) -> Response;
78

79
80
81
82
83
    /// Route a responses request
    async fn route_responses(
        &self,
        headers: Option<&HeaderMap>,
        body: &ResponsesRequest,
84
        model_id: Option<&str>,
85
86
    ) -> Response;

87
    /// Retrieve a stored/background response by id
88
89
90
91
92
93
    async fn get_response(
        &self,
        headers: Option<&HeaderMap>,
        response_id: &str,
        params: &ResponsesGetParams,
    ) -> Response;
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

    /// Cancel a background response by id
    async fn cancel_response(&self, headers: Option<&HeaderMap>, response_id: &str) -> Response;

    /// Delete a response by id
    async fn delete_response(&self, _headers: Option<&HeaderMap>, _response_id: &str) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Responses delete endpoint not implemented",
        )
            .into_response()
    }

    /// List input items of a response by id
    async fn list_response_input_items(
        &self,
        _headers: Option<&HeaderMap>,
        _response_id: &str,
    ) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Responses list input items endpoint not implemented",
        )
            .into_response()
    }

120
121
122
123
124
125
126
    /// Route embedding requests (OpenAI-compatible /v1/embeddings)
    async fn route_embeddings(
        &self,
        headers: Option<&HeaderMap>,
        body: &EmbeddingRequest,
        model_id: Option<&str>,
    ) -> Response;
127

128
129
130
131
132
133
    async fn route_rerank(
        &self,
        headers: Option<&HeaderMap>,
        body: &RerankRequest,
        model_id: Option<&str>,
    ) -> Response;
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
    // Conversations API
    async fn create_conversation(&self, _headers: Option<&HeaderMap>, _body: &Value) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Conversations create endpoint not implemented",
        )
            .into_response()
    }

    async fn get_conversation(
        &self,
        _headers: Option<&HeaderMap>,
        _conversation_id: &str,
    ) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Conversations get endpoint not implemented",
        )
            .into_response()
    }

    async fn update_conversation(
        &self,
        _headers: Option<&HeaderMap>,
        _conversation_id: &str,
        _body: &Value,
    ) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Conversations update endpoint not implemented",
        )
            .into_response()
    }

    async fn delete_conversation(
        &self,
        _headers: Option<&HeaderMap>,
        _conversation_id: &str,
    ) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Conversations delete endpoint not implemented",
        )
            .into_response()
    }

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    /// List items for a conversation
    async fn list_conversation_items(
        &self,
        _headers: Option<&HeaderMap>,
        _conversation_id: &str,
        _limit: Option<usize>,
        _order: Option<String>,
        _after: Option<String>,
    ) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Conversation items list endpoint not implemented",
        )
            .into_response()
    }

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
    /// Create items in a conversation
    async fn create_conversation_items(
        &self,
        _headers: Option<&HeaderMap>,
        _conversation_id: &str,
        _body: &Value,
    ) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Conversation items create endpoint not implemented",
        )
            .into_response()
    }

    /// Get a single conversation item
    /// The `include` parameter is accepted but not yet implemented
    async fn get_conversation_item(
        &self,
        _headers: Option<&HeaderMap>,
        _conversation_id: &str,
        _item_id: &str,
        _include: Option<Vec<String>>,
    ) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Conversation item get endpoint not implemented",
        )
            .into_response()
    }

    /// Delete a conversation item
    async fn delete_conversation_item(
        &self,
        _headers: Option<&HeaderMap>,
        _conversation_id: &str,
        _item_id: &str,
    ) -> Response {
        (
            StatusCode::NOT_IMPLEMENTED,
            "Conversation item delete endpoint not implemented",
        )
            .into_response()
    }

241
242
243
244
245
246
247
248
    /// Get router type name
    fn router_type(&self) -> &'static str;

    /// Check if this is a PD router
    fn is_pd_mode(&self) -> bool {
        self.router_type() == "pd"
    }
}