MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / mock_response

Function mock_response

crates/openshell-router/src/mock.rs:20–49  ·  view source on GitHub ↗

Generate a canned HTTP response appropriate for the route's protocol. The response is protocol-aware: for `openai_chat_completions` it returns a valid `OpenAI` chat completion JSON, for `anthropic_messages` a valid Anthropic response, etc. The route's `model` field is echoed in the response.

(route: &ResolvedRoute, source_protocol: &str)

Source from the content-addressed store, hash-verified

18/// a valid `OpenAI` chat completion JSON, for `anthropic_messages` a valid
19/// Anthropic response, etc. The route's `model` field is echoed in the response.
20pub fn mock_response(route: &ResolvedRoute, source_protocol: &str) -> ProxyResponse {
21 tracing::warn!(
22 endpoint = %route.endpoint,
23 "Serving mock response — mock:// routes should only be used in development/testing"
24 );
25
26 let protocol = if route.protocols.iter().any(|p| p == source_protocol) {
27 source_protocol
28 } else {
29 route.protocols.first().map_or("", String::as_str)
30 };
31
32 let body = match protocol {
33 "openai_chat_completions" => openai_chat_completion_body(&route.model),
34 "openai_completions" => openai_completion_body(&route.model),
35 "openai_embeddings" => openai_embeddings_body(&route.model),
36 "anthropic_messages" => anthropic_messages_body(&route.model),
37 _ => generic_body(&route.model),
38 };
39
40 let body_bytes = bytes::Bytes::from(body);
41 ProxyResponse {
42 status: 200,
43 headers: vec![
44 ("content-type".to_string(), "application/json".to_string()),
45 ("x-openshell-mock".to_string(), "true".to_string()),
46 ],
47 body: body_bytes,
48 }
49}
50
51fn openai_chat_completion_body(model: &str) -> Vec<u8> {
52 serde_json::to_vec(&serde_json::json!({

Calls 5

openai_completion_bodyFunction · 0.85
openai_embeddings_bodyFunction · 0.85
anthropic_messages_bodyFunction · 0.85
generic_bodyFunction · 0.85

Tested by 5

mock_anthropic_messagesFunction · 0.68
mock_openai_embeddingsFunction · 0.68
mock_generic_protocolFunction · 0.68