Commit f6affca
committed
fix(studio): count an MLX prompt with the resident model's own tokenizer
Studio's chat header prices a conversation against the model's context window, and the recount behind it had a llama.cpp branch only. For an MLX-served model the endpoint answered "No GGUF model loaded", so the bar showed a dash for the whole conversation until the first reply reported its own usage -- the case unslothai#8882 made visible by rendering the bar as soon as the window is known.
The endpoint now asks MLX after finding no GGUF backend, below the refusals that are about the request rather than the backend and above llama.cpp's own render concerns.
A count is only worth showing if it renders what the completion for the same request would render, so this answers the questions that completion answers rather than the ones the request makes easy. Which of its two paths claims the request: the tool loop, or the relay that a client catalog or replayed tool history goes to. What each then renders: the loop's action nudge and its strip of stale call markup, the relay's rebuild that keeps structured tool_calls through templating, the launcher's tools-on default where a request stated no intent of its own and its withdrawal where the request did, the catalog a named template's tool_use branch advertises, and a zero tool budget suppressing the loop entirely. Where a helper carries one of those decisions it is called rather than restated.
Three shapes are refused rather than priced short: a pending turn whose retrieval would reach the document store, since only running the search would say what it adds; an image, which /apply-template swaps for a short marker; and an empty prompt, whose bare generation marker reads as a started conversation.
A vision model is counted rather than skipped. It serves text turns through the processor render its generation uses, so counting shares that render, and asks mlx_vlm which special markers tokenization should add -- a per-model answer, and on the releases from before mlx_vlm exported it, the rule those releases inline.
Both store questions on this path -- the enabled MCP servers and whether retrieval can run -- open SQLite, and the second can load an extension and create the schema, so they run on the worker thread and only where their answer decides something.1 parent dabcc28 commit f6affca
4 files changed
Lines changed: 409 additions & 52 deletions
File tree
- studio/backend
- core/inference
- models
- routes
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1127 | 1127 | | |
1128 | 1128 | | |
1129 | 1129 | | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
1130 | 1139 | | |
1131 | 1140 | | |
1132 | 1141 | | |
| |||
1724 | 1733 | | |
1725 | 1734 | | |
1726 | 1735 | | |
1727 | | - | |
1728 | | - | |
1729 | | - | |
1730 | | - | |
1731 | | - | |
1732 | 1736 | | |
1733 | 1737 | | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
1734 | 1767 | | |
1735 | 1768 | | |
1736 | 1769 | | |
| |||
1988 | 2021 | | |
1989 | 2022 | | |
1990 | 2023 | | |
1991 | | - | |
| 2024 | + | |
1992 | 2025 | | |
1993 | 2026 | | |
1994 | | - | |
1995 | | - | |
1996 | | - | |
1997 | | - | |
1998 | | - | |
1999 | | - | |
2000 | | - | |
2001 | | - | |
| 2027 | + | |
2002 | 2028 | | |
2003 | 2029 | | |
2004 | 2030 | | |
2005 | 2031 | | |
2006 | 2032 | | |
2007 | 2033 | | |
2008 | | - | |
2009 | | - | |
2010 | 2034 | | |
2011 | | - | |
| 2035 | + | |
2012 | 2036 | | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
2013 | 2040 | | |
2014 | 2041 | | |
2015 | 2042 | | |
| |||
2021 | 2048 | | |
2022 | 2049 | | |
2023 | 2050 | | |
2024 | | - | |
2025 | | - | |
2026 | 2051 | | |
2027 | 2052 | | |
2028 | 2053 | | |
| |||
2104 | 2129 | | |
2105 | 2130 | | |
2106 | 2131 | | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
| 2156 | + | |
| 2157 | + | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
2107 | 2166 | | |
2108 | 2167 | | |
2109 | 2168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2044 | 2044 | | |
2045 | 2045 | | |
2046 | 2046 | | |
2047 | | - | |
2048 | | - | |
2049 | | - | |
2050 | | - | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
2051 | 2052 | | |
2052 | 2053 | | |
2053 | 2054 | | |
2054 | 2055 | | |
2055 | 2056 | | |
2056 | 2057 | | |
2057 | 2058 | | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
2058 | 2071 | | |
2059 | 2072 | | |
2060 | 2073 | | |
2061 | 2074 | | |
2062 | 2075 | | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
2063 | 2082 | | |
2064 | 2083 | | |
2065 | 2084 | | |
| |||
2068 | 2087 | | |
2069 | 2088 | | |
2070 | 2089 | | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
2071 | 2095 | | |
2072 | 2096 | | |
2073 | 2097 | | |
| |||
0 commit comments