Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/openai_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ pub struct Model {
pub object: String,
pub created: u64,
pub owned_by: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub permission: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub root: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parent: Option<String>,
}

pub async fn models(State(state): State<Arc<AppState>>) -> impl IntoResponse {
Expand All @@ -85,10 +91,13 @@ pub async fn models(State(state): State<Arc<AppState>>) -> impl IntoResponse {
.list_all_available()
.into_iter()
.map(|name| Model {
id: name,
id: name.clone(),
object: "model".to_string(),
created: 0, // Fixed timestamp for simplicity
owned_by: "shimmy".to_string(),
permission: None, // No fine-grained permissions for local models
root: Some(name), // The model itself is the root
parent: None, // Local models don't have parent models
})
.collect();

Expand Down
15 changes: 14 additions & 1 deletion tests/regression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,18 @@ mod regression_tests {
object: "model".to_string(),
created: 0,
owned_by: "shimmy".to_string(),
permission: None,
root: Some("qwen3-4b-instruct".to_string()),
parent: None,
},
Model {
id: "llama-7b".to_string(),
object: "model".to_string(),
created: 0,
owned_by: "shimmy".to_string(),
permission: None,
root: Some("llama-7b".to_string()),
parent: None,
},
],
};
Expand Down Expand Up @@ -316,12 +322,15 @@ mod regression_tests {
// Test the fix for Issue #113 - OpenAI API compatibility for frontends
use shimmy::openai_compat::{Model, ModelsResponse};

// Test basic Model structure (enhanced fields are on PR branch)
// Test enhanced Model structure with frontend compatibility fields
let model = Model {
id: "test-model".to_string(),
object: "model".to_string(),
created: 1640995200,
owned_by: "shimmy".to_string(),
permission: None,
root: Some("test-model".to_string()),
parent: None,
};

// Test serialization works correctly
Expand All @@ -330,6 +339,10 @@ mod regression_tests {
assert_eq!(json["owned_by"], "shimmy");
assert_eq!(json["object"], "model");
assert_eq!(json["created"], 1640995200);
assert_eq!(json["root"], "test-model");
// Optional fields should be omitted when None (due to skip_serializing_if)
assert!(json.get("permission").is_none());
assert!(json.get("parent").is_none());

// Test ModelsResponse structure
let response = ModelsResponse {
Expand Down
Loading