|
As in the LocalAI webUI, after each (e.g openai) api or cli response, together with the tokens, I would expect to also receive the time it took for the prompt/generation. So, I could eventually calculate the tokens/second. If I understand it correctly, In the code this is mentioned as: Do I need to enable a flag? I am not seeing this anywhere! |
Replies: 1 comment 1 reply
|
It is a request header, not a config flag. Send curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Extra-Usage: true" \
-d '{"model":"your-model","messages":[{"role":"user","content":"hi"}]}'"usage": {
"prompt_tokens": 12,
"completion_tokens": 40,
"total_tokens": 52,
"timing_prompt_processing": 84.2,
"timing_token_generation": 512.7
}The gate is // Extra timing data, disabled by default as is't not a part of OpenAI specification
TimingPromptProcessing float64 `json:"timing_prompt_processing,omitempty"`
TimingTokenGeneration float64 `json:"timing_token_generation,omitempty"`Both are milliseconds, straight from llama.cpp's own timings, For streaming you need both the header and an opt in to the usage chunk, since usage only rides in the trailer, {"model":"...","stream":true,"stream_options":{"include_usage":true},"messages":[...]}It is documented, just easy to miss, Read at commit 0a89fdb. I did not run a model to capture a live response, the header plumbing above is from source and the docs. |
It is a request header, not a config flag. Send
Extra-Usagewith any non-empty value and the two timing fields appear insideusage.The gate is
extraUsage := c.Request().Header.Get("Extra-Usage") != ""atcore/http/endpoints/openai/chat.go:143, and the same line exists incompletion.go:90andedit.go:36. Without it the fields are dropped, because th…