Skip to content

Commit 4adac43

Browse files
server: tests: fetch random media marker via /apply-template (#21962) (#21980)
* server: tests: fetch random media marker via /apply-template (#21962 fix) * server: allow pinning media marker via LLAMA_MEDIA_MARKER env var get_media_marker() checks LLAMA_MEDIA_MARKER at first call and uses it as-is if set, falling back to the random marker otherwise. Tests no longer need to fetch the marker dynamically via /apply-template: the fixture sets LLAMA_MEDIA_MARKER=<__media__> so the hardcoded prompts work as before. Address review feedback from ngxson * server: make get_media_marker() thread-safe via magic statics Use a C++11 static local with a lambda initializer instead of a global static with an empty-check. The runtime guarantees initialization exactly once without explicit locking. Address review feedback from ggerganov * nits * nits
1 parent 9db77a0 commit 4adac43

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

tools/server/server-common.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@ std::string gen_tool_call_id() {
8484
return random_string();
8585
}
8686

87-
static std::string media_marker = "";
8887
const char * get_media_marker() {
89-
if (media_marker.empty()) {
90-
media_marker = "<__media_" + random_string() + "__>";
91-
}
92-
return media_marker.c_str();
88+
static const std::string marker = []() {
89+
// allow user to pin a reproducible marker via env var
90+
const char * env = getenv("LLAMA_MEDIA_MARKER");
91+
if (env && env[0] != '\0') {
92+
return std::string(env);
93+
}
94+
return std::string("<__media_") + random_string() + "__>";
95+
}();
96+
return marker.c_str();
9397
}
9498

9599
//

tools/server/tests/unit/test_vision_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def get_img_url(id: str) -> str:
3737
@pytest.fixture(autouse=True)
3838
def create_server():
3939
global server
40+
os.environ['LLAMA_MEDIA_MARKER'] = '<__media__>'
4041
server = ServerPreset.tinygemma3()
4142

4243
def test_models_supports_multimodal_capability():

0 commit comments

Comments
 (0)