[model-gateway] bug fix on module name (#16332)
This commit is contained in:
@@ -14,7 +14,7 @@ vendored-openssl = ["openssl/vendored"]
|
|||||||
unused_qualifications = "warn"
|
unused_qualifications = "warn"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "sgl_model_gateway"
|
name = "smg"
|
||||||
crate-type = ["rlib"]
|
crate-type = ["rlib"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{sync::Arc, thread};
|
use std::{sync::Arc, thread};
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::{BasicWorkerBuilder, Worker, WorkerType},
|
core::{BasicWorkerBuilder, Worker, WorkerType},
|
||||||
policies::{LoadBalancingPolicy, ManualPolicy, SelectWorkerInfo},
|
policies::{LoadBalancingPolicy, ManualPolicy, SelectWorkerInfo},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::time::Instant;
|
|||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
||||||
use serde_json::{from_str, to_string, to_value, to_vec};
|
use serde_json::{from_str, to_string, to_value, to_vec};
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::{BasicWorker, BasicWorkerBuilder, Worker, WorkerType},
|
core::{BasicWorker, BasicWorkerBuilder, Worker, WorkerType},
|
||||||
protocols::{
|
protocols::{
|
||||||
chat::{ChatCompletionRequest, ChatMessage, MessageContent},
|
chat::{ChatCompletionRequest, ChatMessage, MessageContent},
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||||
use sgl_model_gateway::core::{
|
use smg::core::{BasicWorkerBuilder, CircuitBreakerConfig, WorkerRegistry, WorkerType};
|
||||||
BasicWorkerBuilder, CircuitBreakerConfig, WorkerRegistry, WorkerType,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper to populate registry
|
// Helper to populate registry
|
||||||
fn setup_registry(count: usize) -> Arc<WorkerRegistry> {
|
fn setup_registry(count: usize) -> Arc<WorkerRegistry> {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, BenchmarkId, Criterion, Throughput};
|
use criterion::{black_box, criterion_group, BenchmarkId, Criterion, Throughput};
|
||||||
use sgl_model_gateway::tokenizer::{
|
use smg::tokenizer::{
|
||||||
cache::{CacheConfig, CachedTokenizer},
|
cache::{CacheConfig, CachedTokenizer},
|
||||||
huggingface::HuggingFaceTokenizer,
|
huggingface::HuggingFaceTokenizer,
|
||||||
sequence::Sequence,
|
sequence::Sequence,
|
||||||
@@ -31,9 +31,7 @@ fn get_tokenizer_path() -> &'static PathBuf {
|
|||||||
// with special: true, normalized: false - perfect for demonstrating L1 cache
|
// with special: true, normalized: false - perfect for demonstrating L1 cache
|
||||||
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
|
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
|
||||||
let tokenizer_dir = rt.block_on(async {
|
let tokenizer_dir = rt.block_on(async {
|
||||||
sgl_model_gateway::tokenizer::hub::download_tokenizer_from_hf(
|
smg::tokenizer::hub::download_tokenizer_from_hf("Qwen/Qwen3-4B-Instruct-2507")
|
||||||
"Qwen/Qwen3-4B-Instruct-2507",
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to download Qwen3-4B-Instruct tokenizer from HuggingFace")
|
.expect("Failed to download Qwen3-4B-Instruct tokenizer from HuggingFace")
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use std::{
|
|||||||
|
|
||||||
use criterion::{black_box, criterion_group, BenchmarkId, Criterion, Throughput};
|
use criterion::{black_box, criterion_group, BenchmarkId, Criterion, Throughput};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
protocols::common::{Function, Tool},
|
protocols::common::{Function, Tool},
|
||||||
tool_parser::{JsonParser, ParserFactory as ToolParserFactory, ToolParser},
|
tool_parser::{JsonParser, ParserFactory as ToolParserFactory, ToolParser},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use rand::{
|
|||||||
rng as thread_rng, Rng,
|
rng as thread_rng, Rng,
|
||||||
};
|
};
|
||||||
// Import the tree module
|
// Import the tree module
|
||||||
use sgl_model_gateway::policies::tree::Tree;
|
use smg::policies::tree::Tree;
|
||||||
|
|
||||||
// Global results storage for summary
|
// Global results storage for summary
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ use tokio::runtime::Runtime;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use sgl_model_gateway::tokenizer::create_tokenizer_from_file;
|
use smg::tokenizer::create_tokenizer_from_file;
|
||||||
use sgl_model_gateway::tokenizer::traits::Tokenizer;
|
use smg::tokenizer::traits::Tokenizer;
|
||||||
use sgl_model_gateway::grpc_client::sglang_scheduler::SglangSchedulerClient;
|
use smg::grpc_client::sglang_scheduler::SglangSchedulerClient;
|
||||||
use sgl_model_gateway::protocols::chat::ChatCompletionRequest;
|
use smg::protocols::chat::ChatCompletionRequest;
|
||||||
use sgl_model_gateway::routers::grpc::utils::{process_chat_messages, generate_tool_constraints};
|
use smg::routers::grpc::utils::{process_chat_messages, generate_tool_constraints};
|
||||||
|
|
||||||
use super::error::{SglErrorCode, set_error_message};
|
use super::error::{SglErrorCode, set_error_message};
|
||||||
use super::grpc_converter::sgl_grpc_response_converter_create;
|
use super::grpc_converter::sgl_grpc_response_converter_create;
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ use serde_json::Value;
|
|||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use sgl_model_gateway::tokenizer::traits::Tokenizer;
|
use smg::tokenizer::traits::Tokenizer;
|
||||||
use sgl_model_gateway::tokenizer::stream::DecodeStream;
|
use smg::tokenizer::stream::DecodeStream;
|
||||||
use sgl_model_gateway::tool_parser::ToolParser;
|
use smg::tool_parser::ToolParser;
|
||||||
use sgl_model_gateway::protocols::common::{Tool, ToolChoice, ToolChoiceValue, ToolCallDelta, FunctionCallDelta, Usage, StringOrArray};
|
use smg::protocols::common::{Tool, ToolChoice, ToolChoiceValue, ToolCallDelta, FunctionCallDelta, Usage, StringOrArray};
|
||||||
use sgl_model_gateway::tokenizer::stop::StopSequenceDecoder;
|
use smg::tokenizer::stop::StopSequenceDecoder;
|
||||||
use sgl_model_gateway::grpc_client::sglang_proto as proto;
|
use smg::grpc_client::sglang_proto as proto;
|
||||||
|
|
||||||
use super::error::{SglErrorCode, set_error_message, clear_error_message};
|
use super::error::{SglErrorCode, set_error_message, clear_error_message};
|
||||||
use super::tokenizer::TokenizerHandle;
|
use super::tokenizer::TokenizerHandle;
|
||||||
@@ -22,9 +22,9 @@ use super::utils::generate_tool_call_id;
|
|||||||
|
|
||||||
/// Global parser factory (initialized once)
|
/// Global parser factory (initialized once)
|
||||||
// Use the re-exported ParserFactory from tool_parser module
|
// Use the re-exported ParserFactory from tool_parser module
|
||||||
static PARSER_FACTORY: Lazy<sgl_model_gateway::tool_parser::ParserFactory> = Lazy::new(|| {
|
static PARSER_FACTORY: Lazy<smg::tool_parser::ParserFactory> = Lazy::new(|| {
|
||||||
// ParserFactory is re-exported from tool_parser::factory, so we can use it directly
|
// ParserFactory is re-exported from tool_parser::factory, so we can use it directly
|
||||||
sgl_model_gateway::tool_parser::ParserFactory::default()
|
smg::tool_parser::ParserFactory::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Global tokio runtime for async operations
|
/// Global tokio runtime for async operations
|
||||||
@@ -151,7 +151,7 @@ pub unsafe extern "C" fn sgl_grpc_response_converter_create(
|
|||||||
// Create stop decoder if needed
|
// Create stop decoder if needed
|
||||||
let stop_decoder = if stop.is_some() || stop_token_ids.is_some() {
|
let stop_decoder = if stop.is_some() || stop_token_ids.is_some() {
|
||||||
Some(Arc::new(tokio::sync::Mutex::new(
|
Some(Arc::new(tokio::sync::Mutex::new(
|
||||||
sgl_model_gateway::routers::grpc::utils::create_stop_decoder(
|
smg::routers::grpc::utils::create_stop_decoder(
|
||||||
&tokenizer,
|
&tokenizer,
|
||||||
stop.as_ref(),
|
stop.as_ref(),
|
||||||
stop_token_ids.as_ref(),
|
stop_token_ids.as_ref(),
|
||||||
@@ -389,9 +389,9 @@ pub(crate) async fn convert_proto_chunk_to_openai(
|
|||||||
request_id: &str,
|
request_id: &str,
|
||||||
created: u64,
|
created: u64,
|
||||||
system_fingerprint: Option<&str>,
|
system_fingerprint: Option<&str>,
|
||||||
) -> Result<Option<sgl_model_gateway::protocols::chat::ChatCompletionStreamResponse>, String> {
|
) -> Result<Option<smg::protocols::chat::ChatCompletionStreamResponse>, String> {
|
||||||
use sgl_model_gateway::grpc_client::sglang_proto::generate_response::Response::*;
|
use smg::grpc_client::sglang_proto::generate_response::Response::*;
|
||||||
use sgl_model_gateway::protocols::chat::{ChatCompletionStreamResponse, ChatMessageDelta, ChatStreamChoice};
|
use smg::protocols::chat::{ChatCompletionStreamResponse, ChatMessageDelta, ChatStreamChoice};
|
||||||
|
|
||||||
match proto_response.response {
|
match proto_response.response {
|
||||||
Some(Chunk(chunk)) => {
|
Some(Chunk(chunk)) => {
|
||||||
@@ -427,19 +427,19 @@ pub(crate) async fn convert_proto_chunk_to_openai(
|
|||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
for &token_id in &chunk.token_ids {
|
for &token_id in &chunk.token_ids {
|
||||||
match decoder_guard.process_token(token_id).unwrap_or_else(|_| {
|
match decoder_guard.process_token(token_id).unwrap_or_else(|_| {
|
||||||
sgl_model_gateway::tokenizer::stop::SequenceDecoderOutput::Held
|
smg::tokenizer::stop::SequenceDecoderOutput::Held
|
||||||
}) {
|
}) {
|
||||||
sgl_model_gateway::tokenizer::stop::SequenceDecoderOutput::Text(t) => {
|
smg::tokenizer::stop::SequenceDecoderOutput::Text(t) => {
|
||||||
text.push_str(&t);
|
text.push_str(&t);
|
||||||
}
|
}
|
||||||
sgl_model_gateway::tokenizer::stop::SequenceDecoderOutput::StoppedWithText(t) => {
|
smg::tokenizer::stop::SequenceDecoderOutput::StoppedWithText(t) => {
|
||||||
text.push_str(&t);
|
text.push_str(&t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sgl_model_gateway::tokenizer::stop::SequenceDecoderOutput::Stopped => {
|
smg::tokenizer::stop::SequenceDecoderOutput::Stopped => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sgl_model_gateway::tokenizer::stop::SequenceDecoderOutput::Held => {}
|
smg::tokenizer::stop::SequenceDecoderOutput::Held => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text
|
text
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use std::ptr;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use sgl_model_gateway::grpc_client::sglang_proto as proto;
|
use smg::grpc_client::sglang_proto as proto;
|
||||||
|
|
||||||
use super::error::{SglErrorCode, set_error_message};
|
use super::error::{SglErrorCode, set_error_message};
|
||||||
use super::grpc_converter::GrpcResponseConverterHandle;
|
use super::grpc_converter::GrpcResponseConverterHandle;
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ use std::os::raw::{c_char, c_int};
|
|||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::os::raw::c_uint;
|
use std::os::raw::c_uint;
|
||||||
|
|
||||||
use sgl_model_gateway::tokenizer::create_tokenizer_from_file;
|
use smg::tokenizer::create_tokenizer_from_file;
|
||||||
use sgl_model_gateway::protocols::chat::ChatCompletionRequest;
|
use smg::protocols::chat::ChatCompletionRequest;
|
||||||
use sgl_model_gateway::routers::grpc::utils::{process_chat_messages, generate_tool_constraints};
|
use smg::routers::grpc::utils::{process_chat_messages, generate_tool_constraints};
|
||||||
|
|
||||||
use super::error::{SglErrorCode, set_error_message};
|
use super::error::{SglErrorCode, set_error_message};
|
||||||
use super::memory::{sgl_free_string, sgl_free_token_ids};
|
use super::memory::{sgl_free_string, sgl_free_token_ids};
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use tokio::runtime::Runtime;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
|
|
||||||
use sgl_model_gateway::grpc_client::{sglang_proto as proto, sglang_scheduler::{SglangSchedulerClient, AbortOnDropStream}};
|
use smg::grpc_client::{sglang_proto as proto, sglang_scheduler::{SglangSchedulerClient, AbortOnDropStream}};
|
||||||
|
|
||||||
use super::error::{SglErrorCode, set_error_message};
|
use super::error::{SglErrorCode, set_error_message};
|
||||||
use super::grpc_converter::{GrpcResponseConverterHandle, convert_proto_chunk_to_openai};
|
use super::grpc_converter::{GrpcResponseConverterHandle, convert_proto_chunk_to_openai};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::ptr;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use sgl_model_gateway::tokenizer::{
|
use smg::tokenizer::{
|
||||||
create_tokenizer_from_file,
|
create_tokenizer_from_file,
|
||||||
traits::Tokenizer as TokenizerTrait,
|
traits::Tokenizer as TokenizerTrait,
|
||||||
chat_template::ChatTemplateParams,
|
chat_template::ChatTemplateParams,
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ use serde_json::{json, Value};
|
|||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{ParserFactory, ToolParser};
|
use smg::tool_parser::{ParserFactory, ToolParser};
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
use super::error::{SglErrorCode, set_error_message, clear_error_message};
|
use super::error::{SglErrorCode, set_error_message, clear_error_message};
|
||||||
use super::utils::generate_tool_call_id;
|
use super::utils::generate_tool_call_id;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use sgl_model_gateway::*;
|
use smg::*;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ impl std::fmt::Display for ProviderType {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use sgl_model_gateway::core::{ModelCard, ModelType, ProviderType};
|
/// use smg::core::{ModelCard, ModelType, ProviderType};
|
||||||
///
|
///
|
||||||
/// let card = ModelCard::new("meta-llama/Llama-3.1-8B-Instruct")
|
/// let card = ModelCard::new("meta-llama/Llama-3.1-8B-Instruct")
|
||||||
/// .with_display_name("Llama 3.1 8B Instruct")
|
/// .with_display_name("Llama 3.1 8B Instruct")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use clap::{ArgAction, Parser, Subcommand, ValueEnum};
|
use clap::{ArgAction, Parser, Subcommand, ValueEnum};
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
auth::{ApiKeyEntry, ControlPlaneAuthConfig, JwtConfig, Role},
|
auth::{ApiKeyEntry, ControlPlaneAuthConfig, JwtConfig, Role},
|
||||||
config::{
|
config::{
|
||||||
CircuitBreakerConfig, ConfigError, ConfigResult, DiscoveryConfig, HealthCheckConfig,
|
CircuitBreakerConfig, ConfigError, ConfigResult, DiscoveryConfig, HealthCheckConfig,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
//! # Usage
|
//! # Usage
|
||||||
//!
|
//!
|
||||||
//! ```rust,ignore
|
//! ```rust,ignore
|
||||||
//! use sgl_model_gateway::multimodal::vision::{
|
//! use smg::multimodal::vision::{
|
||||||
//! PreProcessorConfig,
|
//! PreProcessorConfig,
|
||||||
//! processors::LlavaProcessor,
|
//! processors::LlavaProcessor,
|
||||||
//! ImagePreProcessor,
|
//! ImagePreProcessor,
|
||||||
|
|||||||
@@ -116,10 +116,8 @@ pub fn otel_tracing_init(enable: bool, otlp_endpoint: Option<&str>) -> Result<()
|
|||||||
.with_batch_config(batch_config)
|
.with_batch_config(batch_config)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let resource = Resource::default().merge(&Resource::new(vec![KeyValue::new(
|
let resource =
|
||||||
"service.name",
|
Resource::default().merge(&Resource::new(vec![KeyValue::new("service.name", "smg")]));
|
||||||
"smg",
|
|
||||||
)]));
|
|
||||||
|
|
||||||
let provider = TracerProvider::builder()
|
let provider = TracerProvider::builder()
|
||||||
.with_span_processor(span_processor)
|
.with_span_processor(span_processor)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
//! ## Usage
|
//! ## Usage
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```ignore
|
||||||
//! use sgl_model_gateway::routers::grpc::harmony::{HarmonyDetector, HarmonyBuilder};
|
//! use smg::routers::grpc::harmony::{HarmonyDetector, HarmonyBuilder};
|
||||||
//!
|
//!
|
||||||
//! // Detect if model supports Harmony
|
//! // Detect if model supports Harmony
|
||||||
//! if HarmonyDetector::is_harmony_model("gpt-4o") {
|
//! if HarmonyDetector::is_harmony_model("gpt-4o") {
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ as of `sgl-model-gateway/src/tokenizer/*`.
|
|||||||
## Usage Examples
|
## Usage Examples
|
||||||
```rust
|
```rust
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use sgl_model_gateway::tokenizer::{
|
use smg::tokenizer::{
|
||||||
create_tokenizer, SequenceDecoderOutput, StopSequenceDecoderBuilder, Tokenizer,
|
create_tokenizer, SequenceDecoderOutput, StopSequenceDecoderBuilder, Tokenizer,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ for &token in encoding.token_ids() {
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
// Apply a chat template when one is bundled with the tokenizer
|
// Apply a chat template when one is bundled with the tokenizer
|
||||||
use sgl_model_gateway::tokenizer::{chat_template::ChatTemplateParams, HuggingFaceTokenizer};
|
use smg::tokenizer::{chat_template::ChatTemplateParams, HuggingFaceTokenizer};
|
||||||
|
|
||||||
let mut hf = HuggingFaceTokenizer::from_file_with_chat_template(
|
let mut hf = HuggingFaceTokenizer::from_file_with_chat_template(
|
||||||
"./tokenizer.json",
|
"./tokenizer.json",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use axum::{
|
|||||||
use common::mock_worker::{HealthStatus, MockWorker, MockWorkerConfig, WorkerType};
|
use common::mock_worker::{HealthStatus, MockWorker, MockWorkerConfig, WorkerType};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
app_context::AppContext,
|
app_context::AppContext,
|
||||||
config::{RouterConfig, RoutingMode},
|
config::{RouterConfig, RoutingMode},
|
||||||
core::Job,
|
core::Job,
|
||||||
@@ -1028,7 +1028,7 @@ mod responses_endpoint_tests {
|
|||||||
let app = ctx.create_app().await;
|
let app = ctx.create_app().await;
|
||||||
|
|
||||||
// Directly store a response in the storage to test the retrieval endpoint
|
// Directly store a response in the storage to test the retrieval endpoint
|
||||||
use sgl_model_gateway::data_connector::{ResponseId, StoredResponse};
|
use smg::data_connector::{ResponseId, StoredResponse};
|
||||||
let mut stored_response = StoredResponse::new(None);
|
let mut stored_response = StoredResponse::new(None);
|
||||||
stored_response.id = ResponseId::from("resp_test_input_items");
|
stored_response.id = ResponseId::from("resp_test_input_items");
|
||||||
stored_response.input = json!([
|
stored_response.input = json!([
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ use jsonwebtoken::{encode, EncodingKey, Header};
|
|||||||
use rsa::{traits::PublicKeyParts, RsaPrivateKey};
|
use rsa::{traits::PublicKeyParts, RsaPrivateKey};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::auth::{
|
use smg::auth::{ApiKeyEntry, ControlPlaneAuthConfig, ControlPlaneAuthState, JwtConfig, Role};
|
||||||
ApiKeyEntry, ControlPlaneAuthConfig, ControlPlaneAuthState, JwtConfig, Role,
|
|
||||||
};
|
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
const TEST_KEY_ID: &str = "test-key-1";
|
const TEST_KEY_ID: &str = "test-key-1";
|
||||||
@@ -572,7 +570,7 @@ async fn test_audit_logging_disabled() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_jwt_jti_replay_protection() {
|
async fn test_jwt_jti_replay_protection() {
|
||||||
use sgl_model_gateway::auth::JwtValidator;
|
use smg::auth::JwtValidator;
|
||||||
|
|
||||||
let (addr, _server) = start_mock_jwks_server().await;
|
let (addr, _server) = start_mock_jwks_server().await;
|
||||||
|
|
||||||
@@ -612,7 +610,7 @@ async fn test_jwt_jti_replay_protection() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_jwt_different_tokens_no_replay() {
|
async fn test_jwt_different_tokens_no_replay() {
|
||||||
use sgl_model_gateway::auth::JwtValidator;
|
use smg::auth::JwtValidator;
|
||||||
|
|
||||||
let (addr, _server) = start_mock_jwks_server().await;
|
let (addr, _server) = start_mock_jwks_server().await;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::{BasicWorkerBuilder, Worker, WorkerType},
|
core::{BasicWorkerBuilder, Worker, WorkerType},
|
||||||
policies::{CacheAwareConfig, CacheAwarePolicy, LoadBalancingPolicy, SelectWorkerInfo},
|
policies::{CacheAwareConfig, CacheAwarePolicy, LoadBalancingPolicy, SelectWorkerInfo},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
protocols::chat::{ChatMessage, MessageContent},
|
protocols::chat::{ChatMessage, MessageContent},
|
||||||
tokenizer::chat_template::{
|
tokenizer::chat_template::{
|
||||||
detect_chat_template_content_format, ChatTemplateContentFormat, ChatTemplateParams,
|
detect_chat_template_content_format, ChatTemplateContentFormat, ChatTemplateParams,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
protocols::{
|
protocols::{
|
||||||
chat::{ChatMessage, MessageContent},
|
chat::{ChatMessage, MessageContent},
|
||||||
common::{ContentPart, ImageUrl},
|
common::{ContentPart, ImageUrl},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
protocols::chat::{ChatMessage, MessageContent},
|
protocols::chat::{ChatMessage, MessageContent},
|
||||||
tokenizer::{chat_template::ChatTemplateParams, huggingface::HuggingFaceTokenizer},
|
tokenizer::{chat_template::ChatTemplateParams, huggingface::HuggingFaceTokenizer},
|
||||||
};
|
};
|
||||||
@@ -78,7 +78,7 @@ mod tests {
|
|||||||
.map(|msg| serde_json::to_value(msg).unwrap())
|
.map(|msg| serde_json::to_value(msg).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
use sgl_model_gateway::tokenizer::chat_template::ChatTemplateParams;
|
use smg::tokenizer::chat_template::ChatTemplateParams;
|
||||||
let params = ChatTemplateParams {
|
let params = ChatTemplateParams {
|
||||||
add_generation_prompt: true,
|
add_generation_prompt: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
app_context::AppContext,
|
app_context::AppContext,
|
||||||
config::{RouterConfig, RoutingMode},
|
config::{RouterConfig, RoutingMode},
|
||||||
core::{
|
core::{
|
||||||
@@ -95,17 +95,14 @@ pub async fn create_test_context(config: RouterConfig) -> Arc<AppContext> {
|
|||||||
|
|
||||||
// Initialize JobQueue after AppContext is created
|
// Initialize JobQueue after AppContext is created
|
||||||
let weak_context = Arc::downgrade(&app_context);
|
let weak_context = Arc::downgrade(&app_context);
|
||||||
let job_queue = sgl_model_gateway::core::JobQueue::new(
|
let job_queue = smg::core::JobQueue::new(smg::core::JobQueueConfig::default(), weak_context);
|
||||||
sgl_model_gateway::core::JobQueueConfig::default(),
|
|
||||||
weak_context,
|
|
||||||
);
|
|
||||||
app_context
|
app_context
|
||||||
.worker_job_queue
|
.worker_job_queue
|
||||||
.set(job_queue)
|
.set(job_queue)
|
||||||
.expect("JobQueue should only be initialized once");
|
.expect("JobQueue should only be initialized once");
|
||||||
|
|
||||||
// Initialize WorkflowEngine and register workflows
|
// Initialize WorkflowEngine and register workflows
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::steps::{create_worker_registration_workflow, create_worker_removal_workflow},
|
core::steps::{create_worker_registration_workflow, create_worker_removal_workflow},
|
||||||
workflow::WorkflowEngine,
|
workflow::WorkflowEngine,
|
||||||
};
|
};
|
||||||
@@ -142,7 +139,7 @@ pub async fn create_test_context(config: RouterConfig) -> Arc<AppContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize MCP manager with empty config
|
// Initialize MCP manager with empty config
|
||||||
use sgl_model_gateway::mcp::{McpConfig, McpManager};
|
use smg::mcp::{McpConfig, McpManager};
|
||||||
let empty_config = McpConfig {
|
let empty_config = McpConfig {
|
||||||
servers: vec![],
|
servers: vec![],
|
||||||
pool: Default::default(),
|
pool: Default::default(),
|
||||||
@@ -231,17 +228,14 @@ pub async fn create_test_context_with_parsers(config: RouterConfig) -> Arc<AppCo
|
|||||||
|
|
||||||
// Initialize JobQueue after AppContext is created
|
// Initialize JobQueue after AppContext is created
|
||||||
let weak_context = Arc::downgrade(&app_context);
|
let weak_context = Arc::downgrade(&app_context);
|
||||||
let job_queue = sgl_model_gateway::core::JobQueue::new(
|
let job_queue = smg::core::JobQueue::new(smg::core::JobQueueConfig::default(), weak_context);
|
||||||
sgl_model_gateway::core::JobQueueConfig::default(),
|
|
||||||
weak_context,
|
|
||||||
);
|
|
||||||
app_context
|
app_context
|
||||||
.worker_job_queue
|
.worker_job_queue
|
||||||
.set(job_queue)
|
.set(job_queue)
|
||||||
.expect("JobQueue should only be initialized once");
|
.expect("JobQueue should only be initialized once");
|
||||||
|
|
||||||
// Initialize WorkflowEngine and register workflows
|
// Initialize WorkflowEngine and register workflows
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::steps::{create_worker_registration_workflow, create_worker_removal_workflow},
|
core::steps::{create_worker_registration_workflow, create_worker_removal_workflow},
|
||||||
workflow::WorkflowEngine,
|
workflow::WorkflowEngine,
|
||||||
};
|
};
|
||||||
@@ -278,7 +272,7 @@ pub async fn create_test_context_with_parsers(config: RouterConfig) -> Arc<AppCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize MCP manager with empty config
|
// Initialize MCP manager with empty config
|
||||||
use sgl_model_gateway::mcp::{McpConfig, McpManager};
|
use smg::mcp::{McpConfig, McpManager};
|
||||||
let empty_config = McpConfig {
|
let empty_config = McpConfig {
|
||||||
servers: vec![],
|
servers: vec![],
|
||||||
pool: Default::default(),
|
pool: Default::default(),
|
||||||
@@ -303,7 +297,7 @@ pub async fn create_test_context_with_mcp_config(
|
|||||||
config: RouterConfig,
|
config: RouterConfig,
|
||||||
mcp_config_path: &str,
|
mcp_config_path: &str,
|
||||||
) -> Arc<AppContext> {
|
) -> Arc<AppContext> {
|
||||||
use sgl_model_gateway::mcp::{McpConfig, McpManager};
|
use smg::mcp::{McpConfig, McpManager};
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
@@ -367,17 +361,14 @@ pub async fn create_test_context_with_mcp_config(
|
|||||||
|
|
||||||
// Initialize JobQueue after AppContext is created
|
// Initialize JobQueue after AppContext is created
|
||||||
let weak_context = Arc::downgrade(&app_context);
|
let weak_context = Arc::downgrade(&app_context);
|
||||||
let job_queue = sgl_model_gateway::core::JobQueue::new(
|
let job_queue = smg::core::JobQueue::new(smg::core::JobQueueConfig::default(), weak_context);
|
||||||
sgl_model_gateway::core::JobQueueConfig::default(),
|
|
||||||
weak_context,
|
|
||||||
);
|
|
||||||
app_context
|
app_context
|
||||||
.worker_job_queue
|
.worker_job_queue
|
||||||
.set(job_queue)
|
.set(job_queue)
|
||||||
.expect("JobQueue should only be initialized once");
|
.expect("JobQueue should only be initialized once");
|
||||||
|
|
||||||
// Initialize WorkflowEngine and register workflows
|
// Initialize WorkflowEngine and register workflows
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::steps::{create_worker_registration_workflow, create_worker_removal_workflow},
|
core::steps::{create_worker_registration_workflow, create_worker_removal_workflow},
|
||||||
workflow::WorkflowEngine,
|
workflow::WorkflowEngine,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::sync::{Arc, OnceLock};
|
|||||||
|
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
app_context::AppContext,
|
app_context::AppContext,
|
||||||
config::RouterConfig,
|
config::RouterConfig,
|
||||||
core::{
|
core::{
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ use axum::{body::Body, response::Response};
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use http_body_util::BodyExt;
|
use http_body_util::BodyExt;
|
||||||
use sgl_model_gateway::core::{
|
use smg::core::{attach_guards_to_response, BasicWorkerBuilder, Worker, WorkerLoadGuard};
|
||||||
attach_guards_to_response, BasicWorkerBuilder, Worker, WorkerLoadGuard,
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use common::mock_mcp_server::MockMCPServer;
|
use common::mock_mcp_server::MockMCPServer;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::mcp::{McpConfig, McpError, McpManager, McpServerConfig, McpTransport};
|
use smg::mcp::{McpConfig, McpError, McpManager, McpServerConfig, McpTransport};
|
||||||
|
|
||||||
/// Create a new mock server for testing (each test gets its own)
|
/// Create a new mock server for testing (each test gets its own)
|
||||||
async fn create_mock_server() -> MockMCPServer {
|
async fn create_mock_server() -> MockMCPServer {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use sgl_model_gateway::core::metrics_aggregator::{aggregate_metrics, MetricPack};
|
use smg::core::metrics_aggregator::{aggregate_metrics, MetricPack};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_aggregate_simple() {
|
fn test_aggregate_simple() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc, time::Duration};
|
|||||||
|
|
||||||
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine};
|
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use sgl_model_gateway::multimodal::{
|
use smg::multimodal::{
|
||||||
AsyncMultiModalTracker, ChatContentPart, ConversationSegment, ImageFetchConfig, ImageSource,
|
AsyncMultiModalTracker, ChatContentPart, ConversationSegment, ImageFetchConfig, ImageSource,
|
||||||
MediaConnector, MediaConnectorConfig, MediaSource, Modality, TrackerConfig,
|
MediaConnector, MediaConnectorConfig, MediaSource, Modality, TrackerConfig,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use opentelemetry_proto::tonic::collector::trace::v1::{
|
|||||||
use portpicker::pick_unused_port;
|
use portpicker::pick_unused_port;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
config::{RouterConfig, TraceConfig},
|
config::{RouterConfig, TraceConfig},
|
||||||
core::Job,
|
core::Job,
|
||||||
observability::{logging, otel_trace},
|
observability::{logging, otel_trace},
|
||||||
@@ -161,14 +161,14 @@ async fn test_router_with_tracing() {
|
|||||||
log_dir: None,
|
log_dir: None,
|
||||||
colorize: false,
|
colorize: false,
|
||||||
log_file_name: "test-otel".to_string(),
|
log_file_name: "test-otel".to_string(),
|
||||||
log_targets: Some(vec!["sgl_model_gateway".to_string()]),
|
log_targets: Some(vec!["smg".to_string()]),
|
||||||
},
|
},
|
||||||
Some(trace_config),
|
Some(trace_config),
|
||||||
);
|
);
|
||||||
println!("Logging initialized with OTEL layer");
|
println!("Logging initialized with OTEL layer");
|
||||||
|
|
||||||
// 5. Create a span and sleep for a while
|
// 5. Create a span and sleep for a while
|
||||||
let _span = info_span!(target: "sgl_model_gateway::otel-trace", "test_router_with_tracing");
|
let _span = info_span!(target: "smg::otel-trace", "test_router_with_tracing");
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
drop(_span);
|
drop(_span);
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ async fn test_grpc_trace_context_injection() {
|
|||||||
// 4. Test within a span context
|
// 4. Test within a span context
|
||||||
tracing::subscriber::with_default(subscriber, || {
|
tracing::subscriber::with_default(subscriber, || {
|
||||||
// Create a span that will be exported to OTEL
|
// Create a span that will be exported to OTEL
|
||||||
let span = info_span!(target: "sgl_model_gateway::otel-trace", "test_grpc_span");
|
let span = info_span!(target: "smg::otel-trace", "test_grpc_span");
|
||||||
let _guard = span.enter();
|
let _guard = span.enter();
|
||||||
|
|
||||||
// Create empty gRPC metadata
|
// Create empty gRPC metadata
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use axum::{
|
|||||||
use common::mock_worker::{MockWorker, MockWorkerConfig};
|
use common::mock_worker::{MockWorker, MockWorkerConfig};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
app_context::AppContext,
|
app_context::AppContext,
|
||||||
config::{RouterConfig, RoutingMode},
|
config::{RouterConfig, RoutingMode},
|
||||||
routers::{RouterFactory, RouterTrait},
|
routers::{RouterFactory, RouterTrait},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
config::PolicyConfig, core::WorkerRegistry, policies::PolicyRegistry,
|
config::PolicyConfig, core::WorkerRegistry, policies::PolicyRegistry,
|
||||||
protocols::worker_spec::WorkerConfigRequest, routers::router_manager::RouterManager,
|
protocols::worker_spec::WorkerConfigRequest, routers::router_manager::RouterManager,
|
||||||
};
|
};
|
||||||
@@ -115,7 +115,7 @@ async fn test_policy_registry_with_router_manager() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_policy_registry_cleanup() {
|
fn test_policy_registry_cleanup() {
|
||||||
use sgl_model_gateway::{config::PolicyConfig, policies::PolicyRegistry};
|
use smg::{config::PolicyConfig, policies::PolicyRegistry};
|
||||||
|
|
||||||
let registry = PolicyRegistry::new(PolicyConfig::RoundRobin);
|
let registry = PolicyRegistry::new(PolicyConfig::RoundRobin);
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ fn test_policy_registry_cleanup() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_policy_registry_multiple_models() {
|
fn test_policy_registry_multiple_models() {
|
||||||
use sgl_model_gateway::{config::PolicyConfig, policies::PolicyRegistry};
|
use smg::{config::PolicyConfig, policies::PolicyRegistry};
|
||||||
|
|
||||||
let registry = PolicyRegistry::new(PolicyConfig::RoundRobin);
|
let registry = PolicyRegistry::new(PolicyConfig::RoundRobin);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::sync::Arc;
|
|||||||
use common::mock_worker::{HealthStatus, MockWorker, MockWorkerConfig, WorkerType};
|
use common::mock_worker::{HealthStatus, MockWorker, MockWorkerConfig, WorkerType};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
config::{RouterConfig, RoutingMode},
|
config::{RouterConfig, RoutingMode},
|
||||||
routers::{RouterFactory, RouterTrait},
|
routers::{RouterFactory, RouterTrait},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Integration test for Responses API
|
// Integration test for Responses API
|
||||||
|
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use sgl_model_gateway::protocols::{
|
use smg::protocols::{
|
||||||
common::{GenerationRequest, ToolChoice, ToolChoiceValue, UsageInfo},
|
common::{GenerationRequest, ToolChoice, ToolChoiceValue, UsageInfo},
|
||||||
responses::{
|
responses::{
|
||||||
ReasoningEffort, ResponseInput, ResponseReasoningParam, ResponseTool, ResponseToolType,
|
ReasoningEffort, ResponseInput, ResponseReasoningParam, ResponseTool, ResponseToolType,
|
||||||
@@ -14,7 +14,7 @@ use common::{
|
|||||||
mock_mcp_server::MockMCPServer,
|
mock_mcp_server::MockMCPServer,
|
||||||
mock_worker::{HealthStatus, MockWorker, MockWorkerConfig, WorkerType},
|
mock_worker::{HealthStatus, MockWorker, MockWorkerConfig, WorkerType},
|
||||||
};
|
};
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
config::RouterConfig,
|
config::RouterConfig,
|
||||||
routers::{conversations, RouterFactory},
|
routers::{conversations, RouterFactory},
|
||||||
};
|
};
|
||||||
@@ -397,7 +397,7 @@ fn test_usage_conversion() {
|
|||||||
completion_tokens: 25,
|
completion_tokens: 25,
|
||||||
total_tokens: 40,
|
total_tokens: 40,
|
||||||
reasoning_tokens: Some(8),
|
reasoning_tokens: Some(8),
|
||||||
prompt_tokens_details: Some(sgl_model_gateway::protocols::common::PromptTokenUsageInfo {
|
prompt_tokens_details: Some(smg::protocols::common::PromptTokenUsageInfo {
|
||||||
cached_tokens: 3,
|
cached_tokens: 3,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@@ -785,7 +785,7 @@ async fn test_max_tool_calls_limit() {
|
|||||||
async fn setup_streaming_mcp_test() -> (
|
async fn setup_streaming_mcp_test() -> (
|
||||||
MockMCPServer,
|
MockMCPServer,
|
||||||
MockWorker,
|
MockWorker,
|
||||||
Box<dyn sgl_model_gateway::routers::RouterTrait>,
|
Box<dyn smg::routers::RouterTrait>,
|
||||||
tempfile::TempDir,
|
tempfile::TempDir,
|
||||||
) {
|
) {
|
||||||
let mcp = MockMCPServer::start().await.expect("start mcp");
|
let mcp = MockMCPServer::start().await.expect("start mcp");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::protocols::{
|
use smg::protocols::{
|
||||||
chat::{ChatCompletionRequest, ChatMessage, MessageContent},
|
chat::{ChatCompletionRequest, ChatMessage, MessageContent},
|
||||||
common::{
|
common::{
|
||||||
Function, FunctionCall, FunctionChoice, StreamOptions, Tool, ToolChoice, ToolChoiceValue,
|
Function, FunctionCall, FunctionChoice, StreamOptions, Tool, ToolChoice, ToolChoiceValue,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::protocols::chat::{ChatMessage, MessageContent};
|
use smg::protocols::chat::{ChatMessage, MessageContent};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chat_message_tagged_by_role_system() {
|
fn test_chat_message_tagged_by_role_system() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use serde_json::{from_str, json, to_string};
|
use serde_json::{from_str, json, to_string};
|
||||||
use sgl_model_gateway::protocols::{common::GenerationRequest, embedding::EmbeddingRequest};
|
use smg::protocols::{common::GenerationRequest, embedding::EmbeddingRequest};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_embedding_request_serialization_string_input() {
|
fn test_embedding_request_serialization_string_input() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use serde_json::{from_str, to_string, Number, Value};
|
use serde_json::{from_str, to_string, Number, Value};
|
||||||
use sgl_model_gateway::protocols::{
|
use smg::protocols::{
|
||||||
common::{GenerationRequest, StringOrArray, UsageInfo},
|
common::{GenerationRequest, StringOrArray, UsageInfo},
|
||||||
rerank::{RerankRequest, RerankResponse, RerankResult, V1RerankReqInput},
|
rerank::{RerankRequest, RerankResponse, RerankResult, V1RerankReqInput},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::protocols::{
|
use smg::protocols::{
|
||||||
common::{Function, StringOrArray, ToolChoice, ToolChoiceValue},
|
common::{Function, StringOrArray, ToolChoice, ToolChoiceValue},
|
||||||
responses::{
|
responses::{
|
||||||
IncludeField, ResponseInput, ResponseInputOutputItem, ResponseTool, ResponseToolType,
|
IncludeField, ResponseInput, ResponseInputOutputItem, ResponseTool, ResponseToolType,
|
||||||
@@ -963,7 +963,7 @@ fn test_validate_input_items_structure() {
|
|||||||
/// Test tool_choice defaults to auto when tools are present
|
/// Test tool_choice defaults to auto when tools are present
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_tool_choice_auto() {
|
fn test_normalize_tool_choice_auto() {
|
||||||
use sgl_model_gateway::protocols::validated::Normalizable;
|
use smg::protocols::validated::Normalizable;
|
||||||
|
|
||||||
let mut request = ResponsesRequest {
|
let mut request = ResponsesRequest {
|
||||||
input: ResponseInput::Text("test".to_string()),
|
input: ResponseInput::Text("test".to_string()),
|
||||||
@@ -1004,7 +1004,7 @@ fn test_normalize_tool_choice_auto() {
|
|||||||
/// Test tool_choice defaults to none when tools array is empty
|
/// Test tool_choice defaults to none when tools array is empty
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_tool_choice_none() {
|
fn test_normalize_tool_choice_none() {
|
||||||
use sgl_model_gateway::protocols::validated::Normalizable;
|
use smg::protocols::validated::Normalizable;
|
||||||
|
|
||||||
let mut request = ResponsesRequest {
|
let mut request = ResponsesRequest {
|
||||||
input: ResponseInput::Text("test".to_string()),
|
input: ResponseInput::Text("test".to_string()),
|
||||||
@@ -1031,7 +1031,7 @@ fn test_normalize_tool_choice_none() {
|
|||||||
/// Test tool_choice is not overridden if already set
|
/// Test tool_choice is not overridden if already set
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_tool_choice_no_override() {
|
fn test_normalize_tool_choice_no_override() {
|
||||||
use sgl_model_gateway::protocols::validated::Normalizable;
|
use smg::protocols::validated::Normalizable;
|
||||||
|
|
||||||
let mut request = ResponsesRequest {
|
let mut request = ResponsesRequest {
|
||||||
input: ResponseInput::Text("test".to_string()),
|
input: ResponseInput::Text("test".to_string()),
|
||||||
@@ -1068,7 +1068,7 @@ fn test_normalize_tool_choice_no_override() {
|
|||||||
/// Test parallel_tool_calls defaults to true when tools are present
|
/// Test parallel_tool_calls defaults to true when tools are present
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_parallel_tool_calls() {
|
fn test_normalize_parallel_tool_calls() {
|
||||||
use sgl_model_gateway::protocols::validated::Normalizable;
|
use smg::protocols::validated::Normalizable;
|
||||||
|
|
||||||
let mut request = ResponsesRequest {
|
let mut request = ResponsesRequest {
|
||||||
input: ResponseInput::Text("test".to_string()),
|
input: ResponseInput::Text("test".to_string()),
|
||||||
@@ -1107,7 +1107,7 @@ fn test_normalize_parallel_tool_calls() {
|
|||||||
/// Test parallel_tool_calls is not set when tools are absent
|
/// Test parallel_tool_calls is not set when tools are absent
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_parallel_tool_calls_no_tools() {
|
fn test_normalize_parallel_tool_calls_no_tools() {
|
||||||
use sgl_model_gateway::protocols::validated::Normalizable;
|
use smg::protocols::validated::Normalizable;
|
||||||
|
|
||||||
let mut request = ResponsesRequest {
|
let mut request = ResponsesRequest {
|
||||||
input: ResponseInput::Text("test".to_string()),
|
input: ResponseInput::Text("test".to_string()),
|
||||||
@@ -1127,7 +1127,7 @@ fn test_normalize_parallel_tool_calls_no_tools() {
|
|||||||
/// Test parallel_tool_calls is not overridden if already set
|
/// Test parallel_tool_calls is not overridden if already set
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_parallel_tool_calls_no_override() {
|
fn test_normalize_parallel_tool_calls_no_override() {
|
||||||
use sgl_model_gateway::protocols::validated::Normalizable;
|
use smg::protocols::validated::Normalizable;
|
||||||
|
|
||||||
let mut request = ResponsesRequest {
|
let mut request = ResponsesRequest {
|
||||||
input: ResponseInput::Text("test".to_string()),
|
input: ResponseInput::Text("test".to_string()),
|
||||||
@@ -1162,7 +1162,7 @@ fn test_normalize_parallel_tool_calls_no_override() {
|
|||||||
/// Test store defaults to true
|
/// Test store defaults to true
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_store_default() {
|
fn test_normalize_store_default() {
|
||||||
use sgl_model_gateway::protocols::validated::Normalizable;
|
use smg::protocols::validated::Normalizable;
|
||||||
|
|
||||||
let mut request = ResponsesRequest {
|
let mut request = ResponsesRequest {
|
||||||
input: ResponseInput::Text("test".to_string()),
|
input: ResponseInput::Text("test".to_string()),
|
||||||
@@ -1182,7 +1182,7 @@ fn test_normalize_store_default() {
|
|||||||
/// Test store is not overridden if already set
|
/// Test store is not overridden if already set
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize_store_no_override() {
|
fn test_normalize_store_no_override() {
|
||||||
use sgl_model_gateway::protocols::validated::Normalizable;
|
use smg::protocols::validated::Normalizable;
|
||||||
|
|
||||||
let mut request = ResponsesRequest {
|
let mut request = ResponsesRequest {
|
||||||
input: ResponseInput::Text("test".to_string()),
|
input: ResponseInput::Text("test".to_string()),
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use common::mock_worker::{HealthStatus, MockWorker, MockWorkerConfig, WorkerType
|
|||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
config::{RouterConfig, RoutingMode},
|
config::{RouterConfig, RoutingMode},
|
||||||
routers::{RouterFactory, RouterTrait},
|
routers::{RouterFactory, RouterTrait},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use axum::{
|
|||||||
Json, Router,
|
Json, Router,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
config::{
|
config::{
|
||||||
ConfigError, ConfigValidator, HistoryBackend, OracleConfig, RouterConfig, RoutingMode,
|
ConfigError, ConfigValidator, HistoryBackend, OracleConfig, RouterConfig, RoutingMode,
|
||||||
},
|
},
|
||||||
@@ -579,14 +579,11 @@ async fn test_router_factory_openai_mode() {
|
|||||||
worker_urls: vec!["https://api.openai.com".to_string()],
|
worker_urls: vec!["https://api.openai.com".to_string()],
|
||||||
};
|
};
|
||||||
|
|
||||||
let router_config = RouterConfig::new(
|
let router_config = RouterConfig::new(routing_mode, smg::config::PolicyConfig::Random);
|
||||||
routing_mode,
|
|
||||||
sgl_model_gateway::config::PolicyConfig::Random,
|
|
||||||
);
|
|
||||||
|
|
||||||
let app_context = common::create_test_context(router_config).await;
|
let app_context = common::create_test_context(router_config).await;
|
||||||
|
|
||||||
let router = sgl_model_gateway::routers::RouterFactory::create_router(&app_context).await;
|
let router = smg::routers::RouterFactory::create_router(&app_context).await;
|
||||||
assert!(
|
assert!(
|
||||||
router.is_ok(),
|
router.is_ok(),
|
||||||
"Router factory should create OpenAI router successfully"
|
"Router factory should create OpenAI router successfully"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_pd_routing {
|
mod test_pd_routing {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
app_context::AppContext,
|
app_context::AppContext,
|
||||||
config::{PolicyConfig, RouterConfig, RoutingMode},
|
config::{PolicyConfig, RouterConfig, RoutingMode},
|
||||||
core::{BasicWorkerBuilder, Worker, WorkerType},
|
core::{BasicWorkerBuilder, Worker, WorkerType},
|
||||||
@@ -39,7 +39,7 @@ mod test_pd_routing {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_worker_types() {
|
fn test_worker_types() {
|
||||||
use sgl_model_gateway::core::{BasicWorkerBuilder, Worker, WorkerType};
|
use smg::core::{BasicWorkerBuilder, Worker, WorkerType};
|
||||||
|
|
||||||
let prefill_worker: Box<dyn Worker> = Box::new(
|
let prefill_worker: Box<dyn Worker> = Box::new(
|
||||||
BasicWorkerBuilder::new("http://prefill:8080")
|
BasicWorkerBuilder::new("http://prefill:8080")
|
||||||
@@ -215,7 +215,7 @@ mod test_pd_routing {
|
|||||||
let app_context = {
|
let app_context = {
|
||||||
use std::sync::{Arc, OnceLock};
|
use std::sync::{Arc, OnceLock};
|
||||||
|
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::{LoadMonitor, WorkerRegistry},
|
core::{LoadMonitor, WorkerRegistry},
|
||||||
data_connector::{
|
data_connector::{
|
||||||
MemoryConversationItemStorage, MemoryConversationStorage,
|
MemoryConversationItemStorage, MemoryConversationStorage,
|
||||||
@@ -674,7 +674,7 @@ mod test_pd_routing {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bootstrap_injection_with_benchmark_requests() {
|
fn test_bootstrap_injection_with_benchmark_requests() {
|
||||||
use sgl_model_gateway::core::{BasicWorkerBuilder, Worker, WorkerType};
|
use smg::core::{BasicWorkerBuilder, Worker, WorkerType};
|
||||||
|
|
||||||
let mut benchmark_request = json!({
|
let mut benchmark_request = json!({
|
||||||
"input_ids": vec![vec![1, 2, 3, 4]; 16], // Batch size 16
|
"input_ids": vec![vec![1, 2, 3, 4]; 16], // Batch size 16
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use std::{
|
|||||||
sync::{Arc, OnceLock},
|
sync::{Arc, OnceLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use sgl_model_gateway::tokenizer::{
|
use smg::tokenizer::{
|
||||||
cache::{CacheConfig, CachedTokenizer},
|
cache::{CacheConfig, CachedTokenizer},
|
||||||
hub::download_tokenizer_from_hf,
|
hub::download_tokenizer_from_hf,
|
||||||
huggingface::HuggingFaceTokenizer,
|
huggingface::HuggingFaceTokenizer,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ mod common;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use common::{ensure_tokenizer_cached, EXPECTED_HASHES, TEST_PROMPTS};
|
use common::{ensure_tokenizer_cached, EXPECTED_HASHES, TEST_PROMPTS};
|
||||||
use sgl_model_gateway::tokenizer::{
|
use smg::tokenizer::{
|
||||||
factory, huggingface::HuggingFaceTokenizer, sequence::Sequence, stop::*, stream::DecodeStream,
|
factory, huggingface::HuggingFaceTokenizer, sequence::Sequence, stop::*, stream::DecodeStream,
|
||||||
traits::*,
|
traits::*,
|
||||||
};
|
};
|
||||||
@@ -279,7 +279,7 @@ fn test_batch_encoding() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_special_tokens() {
|
fn test_special_tokens() {
|
||||||
use sgl_model_gateway::tokenizer::traits::Tokenizer as TokenizerTrait;
|
use smg::tokenizer::traits::Tokenizer as TokenizerTrait;
|
||||||
|
|
||||||
let tokenizer_path = ensure_tokenizer_cached();
|
let tokenizer_path = ensure_tokenizer_cached();
|
||||||
let tokenizer = HuggingFaceTokenizer::from_file(tokenizer_path.to_str().unwrap())
|
let tokenizer = HuggingFaceTokenizer::from_file(tokenizer_path.to_str().unwrap())
|
||||||
@@ -408,7 +408,7 @@ fn test_load_chat_template_from_local_file() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_tinyllama_embedded_template() {
|
async fn test_tinyllama_embedded_template() {
|
||||||
use sgl_model_gateway::tokenizer::hub::download_tokenizer_from_hf;
|
use smg::tokenizer::hub::download_tokenizer_from_hf;
|
||||||
|
|
||||||
// Skip in CI without HF_TOKEN
|
// Skip in CI without HF_TOKEN
|
||||||
|
|
||||||
@@ -444,7 +444,7 @@ async fn test_tinyllama_embedded_template() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_qwen3_next_embedded_template() {
|
async fn test_qwen3_next_embedded_template() {
|
||||||
use sgl_model_gateway::tokenizer::hub::download_tokenizer_from_hf;
|
use smg::tokenizer::hub::download_tokenizer_from_hf;
|
||||||
|
|
||||||
// Test 3: Qwen3-Next has chat template in tokenizer_config.json
|
// Test 3: Qwen3-Next has chat template in tokenizer_config.json
|
||||||
match download_tokenizer_from_hf("Qwen/Qwen3-Next-80B-A3B-Instruct").await {
|
match download_tokenizer_from_hf("Qwen/Qwen3-Next-80B-A3B-Instruct").await {
|
||||||
@@ -476,7 +476,7 @@ async fn test_qwen3_next_embedded_template() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_qwen3_vl_json_template_priority() {
|
async fn test_qwen3_vl_json_template_priority() {
|
||||||
use sgl_model_gateway::tokenizer::hub::download_tokenizer_from_hf;
|
use smg::tokenizer::hub::download_tokenizer_from_hf;
|
||||||
|
|
||||||
// Test 4: Qwen3-VL has both tokenizer_config.json template and chat_template.json
|
// Test 4: Qwen3-VL has both tokenizer_config.json template and chat_template.json
|
||||||
// Should prioritize chat_template.json
|
// Should prioritize chat_template.json
|
||||||
@@ -518,7 +518,7 @@ async fn test_qwen3_vl_json_template_priority() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_llava_separate_jinja_template() {
|
async fn test_llava_separate_jinja_template() {
|
||||||
use sgl_model_gateway::tokenizer::hub::download_tokenizer_from_hf;
|
use smg::tokenizer::hub::download_tokenizer_from_hf;
|
||||||
|
|
||||||
// Test 5: llava has chat_template.jinja as a separate file, not in tokenizer_config.json
|
// Test 5: llava has chat_template.jinja as a separate file, not in tokenizer_config.json
|
||||||
match download_tokenizer_from_hf("llava-hf/llava-1.5-7b-hf").await {
|
match download_tokenizer_from_hf("llava-hf/llava-1.5-7b-hf").await {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! DeepSeek V3 Parser Integration Tests
|
//! DeepSeek V3 Parser Integration Tests
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{DeepSeekParser, ToolParser};
|
use smg::tool_parser::{DeepSeekParser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::create_test_tools;
|
use common::create_test_tools;
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Tests for malformed input, edge cases, and error recovery
|
//! Tests for malformed input, edge cases, and error recovery
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{
|
use smg::tool_parser::{JsonParser, MistralParser, PythonicParser, QwenParser, ToolParser};
|
||||||
JsonParser, MistralParser, PythonicParser, QwenParser, ToolParser,
|
|
||||||
};
|
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::create_test_tools;
|
use common::create_test_tools;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! When tool call parsing fails, the original text should be preserved as normal text
|
//! When tool call parsing fails, the original text should be preserved as normal text
|
||||||
//! rather than being lost. This ensures graceful degradation.
|
//! rather than being lost. This ensures graceful degradation.
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{
|
use smg::tool_parser::{
|
||||||
DeepSeekParser, JsonParser, LlamaParser, MistralParser, QwenParser, ToolParser,
|
DeepSeekParser, JsonParser, LlamaParser, MistralParser, QwenParser, ToolParser,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! GLM-4.7 MoE Parser Integration Tests
|
//! GLM-4.7 MoE Parser Integration Tests
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{Glm4MoeParser, ToolParser};
|
use smg::tool_parser::{Glm4MoeParser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::create_test_tools;
|
use common::create_test_tools;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! GLM-4 MoE Parser Integration Tests
|
//! GLM-4 MoE Parser Integration Tests
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{Glm4MoeParser, ToolParser};
|
use smg::tool_parser::{Glm4MoeParser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::create_test_tools;
|
use common::create_test_tools;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! Tests for the JSON parser which handles OpenAI, Claude, and generic JSON formats
|
//! Tests for the JSON parser which handles OpenAI, Claude, and generic JSON formats
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::tool_parser::{JsonParser, ToolParser};
|
use smg::tool_parser::{JsonParser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::{create_test_tools, streaming_helpers::*};
|
use common::{create_test_tools, streaming_helpers::*};
|
||||||
@@ -166,7 +166,7 @@ async fn test_json_format_detection() {
|
|||||||
// Streaming tests for JSON array format
|
// Streaming tests for JSON array format
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_json_array_streaming_required_mode() {
|
async fn test_json_array_streaming_required_mode() {
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
// Test that simulates the exact streaming pattern from required mode
|
// Test that simulates the exact streaming pattern from required mode
|
||||||
let mut parser = JsonParser::new();
|
let mut parser = JsonParser::new();
|
||||||
@@ -174,7 +174,7 @@ async fn test_json_array_streaming_required_mode() {
|
|||||||
// Define test tools
|
// Define test tools
|
||||||
let tools = vec![Tool {
|
let tools = vec![Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_weather".to_string(),
|
name: "get_weather".to_string(),
|
||||||
description: Some("Get weather".to_string()),
|
description: Some("Get weather".to_string()),
|
||||||
parameters: serde_json::json!({}),
|
parameters: serde_json::json!({}),
|
||||||
@@ -240,7 +240,7 @@ async fn test_json_array_streaming_required_mode() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_json_array_multiple_tools_streaming() {
|
async fn test_json_array_multiple_tools_streaming() {
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
// Test with multiple tools in array
|
// Test with multiple tools in array
|
||||||
let mut parser = JsonParser::new();
|
let mut parser = JsonParser::new();
|
||||||
@@ -248,7 +248,7 @@ async fn test_json_array_multiple_tools_streaming() {
|
|||||||
let tools = vec![
|
let tools = vec![
|
||||||
Tool {
|
Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_weather".to_string(),
|
name: "get_weather".to_string(),
|
||||||
description: Some("Get weather".to_string()),
|
description: Some("Get weather".to_string()),
|
||||||
parameters: serde_json::json!({}),
|
parameters: serde_json::json!({}),
|
||||||
@@ -257,7 +257,7 @@ async fn test_json_array_multiple_tools_streaming() {
|
|||||||
},
|
},
|
||||||
Tool {
|
Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_news".to_string(),
|
name: "get_news".to_string(),
|
||||||
description: Some("Get news".to_string()),
|
description: Some("Get news".to_string()),
|
||||||
parameters: serde_json::json!({}),
|
parameters: serde_json::json!({}),
|
||||||
@@ -305,14 +305,14 @@ async fn test_json_array_multiple_tools_streaming() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_json_array_closing_bracket_separate_chunk() {
|
async fn test_json_array_closing_bracket_separate_chunk() {
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
// Test case where the closing ] comes as a separate chunk
|
// Test case where the closing ] comes as a separate chunk
|
||||||
let mut parser = JsonParser::new();
|
let mut parser = JsonParser::new();
|
||||||
|
|
||||||
let tools = vec![Tool {
|
let tools = vec![Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_weather".to_string(),
|
name: "get_weather".to_string(),
|
||||||
description: Some("Get weather".to_string()),
|
description: Some("Get weather".to_string()),
|
||||||
parameters: json!({}),
|
parameters: json!({}),
|
||||||
@@ -366,14 +366,14 @@ async fn test_json_array_closing_bracket_separate_chunk() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_json_single_object_with_trailing_text() {
|
async fn test_json_single_object_with_trailing_text() {
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
// Test single object format (no array) with trailing text
|
// Test single object format (no array) with trailing text
|
||||||
let mut parser = JsonParser::new();
|
let mut parser = JsonParser::new();
|
||||||
|
|
||||||
let tools = vec![Tool {
|
let tools = vec![Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_weather".to_string(),
|
name: "get_weather".to_string(),
|
||||||
description: Some("Get weather".to_string()),
|
description: Some("Get weather".to_string()),
|
||||||
parameters: serde_json::json!({}),
|
parameters: serde_json::json!({}),
|
||||||
@@ -420,14 +420,14 @@ async fn test_json_single_object_with_trailing_text() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_json_single_object_with_bracket_in_text() {
|
async fn test_json_single_object_with_bracket_in_text() {
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
// Test that ] in normal text is NOT stripped for single object format
|
// Test that ] in normal text is NOT stripped for single object format
|
||||||
let mut parser = JsonParser::new();
|
let mut parser = JsonParser::new();
|
||||||
|
|
||||||
let tools = vec![Tool {
|
let tools = vec![Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_weather".to_string(),
|
name: "get_weather".to_string(),
|
||||||
description: Some("Get weather".to_string()),
|
description: Some("Get weather".to_string()),
|
||||||
parameters: serde_json::json!({}),
|
parameters: serde_json::json!({}),
|
||||||
@@ -472,14 +472,14 @@ async fn test_json_single_object_with_bracket_in_text() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_json_array_bracket_in_text_after_tools() {
|
async fn test_json_array_bracket_in_text_after_tools() {
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
// Test that ] in normal text AFTER array tools is preserved
|
// Test that ] in normal text AFTER array tools is preserved
|
||||||
let mut parser = JsonParser::new();
|
let mut parser = JsonParser::new();
|
||||||
|
|
||||||
let tools = vec![Tool {
|
let tools = vec![Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_weather".to_string(),
|
name: "get_weather".to_string(),
|
||||||
description: Some("Get weather".to_string()),
|
description: Some("Get weather".to_string()),
|
||||||
parameters: serde_json::json!({}),
|
parameters: serde_json::json!({}),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! Kimi K2 Parser Integration Tests
|
//! Kimi K2 Parser Integration Tests
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{KimiK2Parser, ToolParser};
|
use smg::tool_parser::{KimiK2Parser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::create_test_tools;
|
use common::create_test_tools;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Tests for the Llama parser which handles <|python_tag|> format and plain JSON
|
//! Tests for the Llama parser which handles <|python_tag|> format and plain JSON
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{LlamaParser, ToolParser};
|
use smg::tool_parser::{LlamaParser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::{create_test_tools, streaming_helpers::*};
|
use common::{create_test_tools, streaming_helpers::*};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! MiniMax M2 Parser Integration Tests
|
//! MiniMax M2 Parser Integration Tests
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{MinimaxM2Parser, ToolParser};
|
use smg::tool_parser::{MinimaxM2Parser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::create_test_tools;
|
use common::create_test_tools;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! Tests for the Mistral parser which handles [TOOL_CALLS] format
|
//! Tests for the Mistral parser which handles [TOOL_CALLS] format
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::tool_parser::{MistralParser, ToolParser};
|
use smg::tool_parser::{MistralParser, ToolParser};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_mistral_single_tool() {
|
async fn test_mistral_single_tool() {
|
||||||
@@ -158,14 +158,14 @@ Let me execute these searches for you."#;
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_mistral_streaming_closing_bracket() {
|
async fn test_mistral_streaming_closing_bracket() {
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
// Test that closing ] is stripped for Mistral array format
|
// Test that closing ] is stripped for Mistral array format
|
||||||
let mut parser = MistralParser::new();
|
let mut parser = MistralParser::new();
|
||||||
|
|
||||||
let tools = vec![Tool {
|
let tools = vec![Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_weather".to_string(),
|
name: "get_weather".to_string(),
|
||||||
description: Some("Get weather".to_string()),
|
description: Some("Get weather".to_string()),
|
||||||
parameters: json!({}),
|
parameters: json!({}),
|
||||||
@@ -218,14 +218,14 @@ async fn test_mistral_streaming_closing_bracket() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_mistral_streaming_bracket_in_text_after_tools() {
|
async fn test_mistral_streaming_bracket_in_text_after_tools() {
|
||||||
use sgl_model_gateway::protocols::common::Tool;
|
use smg::protocols::common::Tool;
|
||||||
|
|
||||||
// Test that ] in normal text AFTER tool calls is preserved
|
// Test that ] in normal text AFTER tool calls is preserved
|
||||||
let mut parser = MistralParser::new();
|
let mut parser = MistralParser::new();
|
||||||
|
|
||||||
let tools = vec![Tool {
|
let tools = vec![Tool {
|
||||||
tool_type: "function".to_string(),
|
tool_type: "function".to_string(),
|
||||||
function: sgl_model_gateway::protocols::common::Function {
|
function: smg::protocols::common::Function {
|
||||||
name: "get_weather".to_string(),
|
name: "get_weather".to_string(),
|
||||||
description: Some("Get weather".to_string()),
|
description: Some("Get weather".to_string()),
|
||||||
parameters: json!({}),
|
parameters: json!({}),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! Tests for edge cases across parsers and mixed format scenarios
|
//! Tests for edge cases across parsers and mixed format scenarios
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::tool_parser::{
|
use smg::tool_parser::{
|
||||||
JsonParser, LlamaParser, MistralParser, PythonicParser, QwenParser, ToolParser,
|
JsonParser, LlamaParser, MistralParser, PythonicParser, QwenParser, ToolParser,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Tests for the partial JSON parser with allow_partial_strings flag behavior
|
//! Tests for the partial JSON parser with allow_partial_strings flag behavior
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::partial_json::PartialJson;
|
use smg::tool_parser::partial_json::PartialJson;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_partial_string_flag_disallows_incomplete_strings() {
|
fn test_partial_string_flag_disallows_incomplete_strings() {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! Tests for the Pythonic parser which handles Python function call syntax
|
//! Tests for the Pythonic parser which handles Python function call syntax
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::tool_parser::{PythonicParser, ToolParser};
|
use smg::tool_parser::{PythonicParser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::create_test_tools;
|
use common::create_test_tools;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! Tests for the Qwen parser which handles <tool_call>...</tool_call> format
|
//! Tests for the Qwen parser which handles <tool_call>...</tool_call> format
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sgl_model_gateway::tool_parser::{QwenParser, ToolParser};
|
use smg::tool_parser::{QwenParser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::{create_test_tools, streaming_helpers::*};
|
use common::{create_test_tools, streaming_helpers::*};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! Step3 Parser Integration Tests
|
//! Step3 Parser Integration Tests
|
||||||
|
|
||||||
use sgl_model_gateway::tool_parser::{Step3Parser, ToolParser};
|
use smg::tool_parser::{Step3Parser, ToolParser};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::create_test_tools;
|
use common::create_test_tools;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
use std::{fs::File, io::Read, path::Path};
|
use std::{fs::File, io::Read, path::Path};
|
||||||
|
|
||||||
use ndarray::{Array4, Array5};
|
use ndarray::{Array4, Array5};
|
||||||
use sgl_model_gateway::multimodal::vision::{
|
use smg::multimodal::vision::{
|
||||||
image_processor::ModelSpecificValue, ImagePreProcessor, Llama4VisionProcessor, LlavaProcessor,
|
image_processor::ModelSpecificValue, ImagePreProcessor, Llama4VisionProcessor, LlavaProcessor,
|
||||||
Phi3VisionProcessor, Phi4VisionProcessor, PixtralProcessor, PreProcessorConfig,
|
Phi3VisionProcessor, Phi4VisionProcessor, PixtralProcessor, PreProcessorConfig,
|
||||||
Qwen2VLProcessor, Qwen3VLProcessor,
|
Qwen2VLProcessor, Qwen3VLProcessor,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use axum::{
|
|||||||
extract::Request,
|
extract::Request,
|
||||||
http::{header::CONTENT_TYPE, StatusCode},
|
http::{header::CONTENT_TYPE, StatusCode},
|
||||||
};
|
};
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
app_context::AppContext,
|
app_context::AppContext,
|
||||||
config::RouterConfig,
|
config::RouterConfig,
|
||||||
core::{
|
core::{
|
||||||
@@ -101,17 +101,14 @@ async fn create_test_context_with_wasm() -> Arc<AppContext> {
|
|||||||
|
|
||||||
// Initialize JobQueue after AppContext is created
|
// Initialize JobQueue after AppContext is created
|
||||||
let weak_context = Arc::downgrade(&app_context);
|
let weak_context = Arc::downgrade(&app_context);
|
||||||
let job_queue = sgl_model_gateway::core::JobQueue::new(
|
let job_queue = smg::core::JobQueue::new(smg::core::JobQueueConfig::default(), weak_context);
|
||||||
sgl_model_gateway::core::JobQueueConfig::default(),
|
|
||||||
weak_context,
|
|
||||||
);
|
|
||||||
app_context
|
app_context
|
||||||
.worker_job_queue
|
.worker_job_queue
|
||||||
.set(job_queue)
|
.set(job_queue)
|
||||||
.expect("JobQueue should only be initialized once");
|
.expect("JobQueue should only be initialized once");
|
||||||
|
|
||||||
// Initialize WorkflowEngine and register workflows
|
// Initialize WorkflowEngine and register workflows
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::steps::{create_worker_registration_workflow, create_worker_removal_workflow},
|
core::steps::{create_worker_registration_workflow, create_worker_removal_workflow},
|
||||||
workflow::WorkflowEngine,
|
workflow::WorkflowEngine,
|
||||||
};
|
};
|
||||||
@@ -134,7 +131,7 @@ async fn create_test_context_with_wasm() -> Arc<AppContext> {
|
|||||||
.expect("WorkflowEngine should only be initialized once");
|
.expect("WorkflowEngine should only be initialized once");
|
||||||
|
|
||||||
// Initialize MCP manager with empty config
|
// Initialize MCP manager with empty config
|
||||||
use sgl_model_gateway::mcp::{McpConfig, McpManager};
|
use smg::mcp::{McpConfig, McpManager};
|
||||||
let empty_config = McpConfig {
|
let empty_config = McpConfig {
|
||||||
servers: vec![],
|
servers: vec![],
|
||||||
pool: Default::default(),
|
pool: Default::default(),
|
||||||
@@ -206,7 +203,7 @@ async fn create_test_app_with_wasm() -> (axum::Router, Arc<AppContext>, TempDir)
|
|||||||
|
|
||||||
let app = build_app(
|
let app = build_app(
|
||||||
app_state,
|
app_state,
|
||||||
sgl_model_gateway::middleware::AuthConfig { api_key: None },
|
smg::middleware::AuthConfig { api_key: None },
|
||||||
None, // No control plane auth for tests
|
None, // No control plane auth for tests
|
||||||
256 * 1024 * 1024,
|
256 * 1024 * 1024,
|
||||||
request_id_headers,
|
request_id_headers,
|
||||||
@@ -231,7 +228,7 @@ async fn test_wasm_api_add_module() {
|
|||||||
file_path: wasm_file_path.clone(),
|
file_path: wasm_file_path.clone(),
|
||||||
module_type: WasmModuleType::Middleware,
|
module_type: WasmModuleType::Middleware,
|
||||||
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
smg::wasm::module::MiddlewareAttachPoint::OnRequest,
|
||||||
)],
|
)],
|
||||||
add_result: None,
|
add_result: None,
|
||||||
}],
|
}],
|
||||||
@@ -257,7 +254,7 @@ async fn test_wasm_api_add_module() {
|
|||||||
let module_result = &response_json.modules[0].add_result;
|
let module_result = &response_json.modules[0].add_result;
|
||||||
|
|
||||||
// Print error for debugging
|
// Print error for debugging
|
||||||
if let Some(sgl_model_gateway::wasm::module::WasmModuleAddResult::Error(err)) = module_result {
|
if let Some(smg::wasm::module::WasmModuleAddResult::Error(err)) = module_result {
|
||||||
eprintln!("Module registration failed: {}", err);
|
eprintln!("Module registration failed: {}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,9 +275,7 @@ async fn test_wasm_api_add_module() {
|
|||||||
let modules = wasm_manager.get_modules().expect("Failed to get modules");
|
let modules = wasm_manager.get_modules().expect("Failed to get modules");
|
||||||
assert!(!modules.is_empty(), "Module should be registered");
|
assert!(!modules.is_empty(), "Module should be registered");
|
||||||
|
|
||||||
if let Some(sgl_model_gateway::wasm::module::WasmModuleAddResult::Success(uuid)) =
|
if let Some(smg::wasm::module::WasmModuleAddResult::Success(uuid)) = module_result {
|
||||||
module_result
|
|
||||||
{
|
|
||||||
let module = wasm_manager
|
let module = wasm_manager
|
||||||
.get_module(*uuid)
|
.get_module(*uuid)
|
||||||
.expect("Failed to get module");
|
.expect("Failed to get module");
|
||||||
@@ -299,7 +294,7 @@ async fn test_wasm_api_add_module_invalid_file() {
|
|||||||
file_path: "/nonexistent/path/to/module.component.wasm".to_string(),
|
file_path: "/nonexistent/path/to/module.component.wasm".to_string(),
|
||||||
module_type: WasmModuleType::Middleware,
|
module_type: WasmModuleType::Middleware,
|
||||||
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
smg::wasm::module::MiddlewareAttachPoint::OnRequest,
|
||||||
)],
|
)],
|
||||||
add_result: None,
|
add_result: None,
|
||||||
}],
|
}],
|
||||||
@@ -331,7 +326,7 @@ async fn test_wasm_api_add_module_invalid_file() {
|
|||||||
assert!(module_result.is_some());
|
assert!(module_result.is_some());
|
||||||
|
|
||||||
// Verify it's an error result
|
// Verify it's an error result
|
||||||
if let Some(sgl_model_gateway::wasm::module::WasmModuleAddResult::Error(_)) = module_result {
|
if let Some(smg::wasm::module::WasmModuleAddResult::Error(_)) = module_result {
|
||||||
// Expected error
|
// Expected error
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected error result for invalid file path");
|
panic!("Expected error result for invalid file path");
|
||||||
@@ -354,7 +349,7 @@ async fn test_wasm_api_add_module_invalid_wasm() {
|
|||||||
file_path: invalid_wasm_path.to_str().unwrap().to_string(),
|
file_path: invalid_wasm_path.to_str().unwrap().to_string(),
|
||||||
module_type: WasmModuleType::Middleware,
|
module_type: WasmModuleType::Middleware,
|
||||||
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
smg::wasm::module::MiddlewareAttachPoint::OnRequest,
|
||||||
)],
|
)],
|
||||||
add_result: None,
|
add_result: None,
|
||||||
}],
|
}],
|
||||||
@@ -386,7 +381,7 @@ async fn test_wasm_api_add_module_invalid_wasm() {
|
|||||||
assert!(module_result.is_some());
|
assert!(module_result.is_some());
|
||||||
|
|
||||||
// Verify it's an error result
|
// Verify it's an error result
|
||||||
if let Some(sgl_model_gateway::wasm::module::WasmModuleAddResult::Error(_)) = module_result {
|
if let Some(smg::wasm::module::WasmModuleAddResult::Error(_)) = module_result {
|
||||||
// Expected error
|
// Expected error
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected error result for invalid WASM file");
|
panic!("Expected error result for invalid WASM file");
|
||||||
@@ -405,7 +400,7 @@ async fn test_wasm_api_list_modules() {
|
|||||||
file_path: wasm_file_path.clone(),
|
file_path: wasm_file_path.clone(),
|
||||||
module_type: WasmModuleType::Middleware,
|
module_type: WasmModuleType::Middleware,
|
||||||
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
smg::wasm::module::MiddlewareAttachPoint::OnRequest,
|
||||||
)],
|
)],
|
||||||
add_result: None,
|
add_result: None,
|
||||||
}],
|
}],
|
||||||
@@ -473,7 +468,7 @@ async fn test_wasm_api_remove_module() {
|
|||||||
file_path: wasm_file_path.clone(),
|
file_path: wasm_file_path.clone(),
|
||||||
module_type: WasmModuleType::Middleware,
|
module_type: WasmModuleType::Middleware,
|
||||||
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
smg::wasm::module::MiddlewareAttachPoint::OnRequest,
|
||||||
)],
|
)],
|
||||||
add_result: None,
|
add_result: None,
|
||||||
}],
|
}],
|
||||||
@@ -503,8 +498,7 @@ async fn test_wasm_api_remove_module() {
|
|||||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||||
|
|
||||||
// Get the module UUID
|
// Get the module UUID
|
||||||
let module_uuid =
|
let module_uuid = if let Some(smg::wasm::module::WasmModuleAddResult::Success(uuid)) =
|
||||||
if let Some(sgl_model_gateway::wasm::module::WasmModuleAddResult::Success(uuid)) =
|
|
||||||
&response_json.modules[0].add_result
|
&response_json.modules[0].add_result
|
||||||
{
|
{
|
||||||
*uuid
|
*uuid
|
||||||
@@ -599,7 +593,7 @@ async fn test_wasm_module_duplicate_sha256() {
|
|||||||
file_path: wasm_file_path.clone(),
|
file_path: wasm_file_path.clone(),
|
||||||
module_type: WasmModuleType::Middleware,
|
module_type: WasmModuleType::Middleware,
|
||||||
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
smg::wasm::module::MiddlewareAttachPoint::OnRequest,
|
||||||
)],
|
)],
|
||||||
add_result: None,
|
add_result: None,
|
||||||
}],
|
}],
|
||||||
@@ -630,7 +624,7 @@ async fn test_wasm_module_duplicate_sha256() {
|
|||||||
file_path: wasm_file_path.clone(), // Same file
|
file_path: wasm_file_path.clone(), // Same file
|
||||||
module_type: WasmModuleType::Middleware,
|
module_type: WasmModuleType::Middleware,
|
||||||
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
smg::wasm::module::MiddlewareAttachPoint::OnRequest,
|
||||||
)],
|
)],
|
||||||
add_result: None,
|
add_result: None,
|
||||||
}],
|
}],
|
||||||
@@ -662,9 +656,7 @@ async fn test_wasm_module_duplicate_sha256() {
|
|||||||
assert!(module_result.is_some());
|
assert!(module_result.is_some());
|
||||||
|
|
||||||
// Verify it's an error result (duplicate)
|
// Verify it's an error result (duplicate)
|
||||||
if let Some(sgl_model_gateway::wasm::module::WasmModuleAddResult::Error(err_msg)) =
|
if let Some(smg::wasm::module::WasmModuleAddResult::Error(err_msg)) = module_result {
|
||||||
module_result
|
|
||||||
{
|
|
||||||
assert!(
|
assert!(
|
||||||
err_msg.contains("duplicate")
|
err_msg.contains("duplicate")
|
||||||
|| err_msg.contains("Duplicate")
|
|| err_msg.contains("Duplicate")
|
||||||
@@ -692,7 +684,7 @@ async fn test_wasm_module_execution() {
|
|||||||
.expect("Workflow engine should be initialized");
|
.expect("Workflow engine should be initialized");
|
||||||
|
|
||||||
// Create workflow context for registration
|
// Create workflow context for registration
|
||||||
use sgl_model_gateway::{
|
use smg::{
|
||||||
core::steps::WasmModuleConfigRequest,
|
core::steps::WasmModuleConfigRequest,
|
||||||
workflow::{WorkflowContext, WorkflowId, WorkflowInstanceId},
|
workflow::{WorkflowContext, WorkflowId, WorkflowInstanceId},
|
||||||
};
|
};
|
||||||
@@ -702,7 +694,7 @@ async fn test_wasm_module_execution() {
|
|||||||
file_path: wasm_file_path.clone(),
|
file_path: wasm_file_path.clone(),
|
||||||
module_type: WasmModuleType::Middleware,
|
module_type: WasmModuleType::Middleware,
|
||||||
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
attach_points: vec![WasmModuleAttachPoint::Middleware(
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
smg::wasm::module::MiddlewareAttachPoint::OnRequest,
|
||||||
)],
|
)],
|
||||||
add_result: None,
|
add_result: None,
|
||||||
};
|
};
|
||||||
@@ -736,14 +728,14 @@ async fn test_wasm_module_execution() {
|
|||||||
.expect("Failed to get workflow status");
|
.expect("Failed to get workflow status");
|
||||||
|
|
||||||
match state.status {
|
match state.status {
|
||||||
sgl_model_gateway::workflow::WorkflowStatus::Completed => {
|
smg::workflow::WorkflowStatus::Completed => {
|
||||||
// Extract module UUID from context
|
// Extract module UUID from context
|
||||||
if let Some(uuid_arc) = state.context.get::<Uuid>("module_uuid") {
|
if let Some(uuid_arc) = state.context.get::<Uuid>("module_uuid") {
|
||||||
module_uuid = Some(*uuid_arc.as_ref());
|
module_uuid = Some(*uuid_arc.as_ref());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sgl_model_gateway::workflow::WorkflowStatus::Failed => {
|
smg::workflow::WorkflowStatus::Failed => {
|
||||||
panic!("Workflow failed: {:?}", state);
|
panic!("Workflow failed: {:?}", state);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@@ -764,7 +756,7 @@ async fn test_wasm_module_execution() {
|
|||||||
let (initial_total, initial_success, initial_failed, _, _) = wasm_manager.get_metrics();
|
let (initial_total, initial_success, initial_failed, _, _) = wasm_manager.get_metrics();
|
||||||
|
|
||||||
// Execute the module
|
// Execute the module
|
||||||
use sgl_model_gateway::wasm::{
|
use smg::wasm::{
|
||||||
spec::sgl::model_gateway::middleware_types,
|
spec::sgl::model_gateway::middleware_types,
|
||||||
types::{WasmComponentInput, WasmComponentOutput},
|
types::{WasmComponentInput, WasmComponentOutput},
|
||||||
};
|
};
|
||||||
@@ -780,9 +772,8 @@ async fn test_wasm_module_execution() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let input = WasmComponentInput::MiddlewareRequest(request);
|
let input = WasmComponentInput::MiddlewareRequest(request);
|
||||||
let attach_point = WasmModuleAttachPoint::Middleware(
|
let attach_point =
|
||||||
sgl_model_gateway::wasm::module::MiddlewareAttachPoint::OnRequest,
|
WasmModuleAttachPoint::Middleware(smg::wasm::module::MiddlewareAttachPoint::OnRequest);
|
||||||
);
|
|
||||||
|
|
||||||
// Execute the module
|
// Execute the module
|
||||||
let result = wasm_manager
|
let result = wasm_manager
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use sgl_model_gateway::workflow::*;
|
use smg::workflow::*;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
// Test step that counts invocations
|
// Test step that counts invocations
|
||||||
|
|||||||
Reference in New Issue
Block a user