Open-source AI penetration testing tool to find and fix your app’s vulnerabilities.
Python agentsai-hackingai-penetration-testingai-pentestingai-securityartificial-intelligencebug-bountycode-qualityctf-toolscybersecuritycybersecurity-toolsethical-hackinghackingllm-securityoffensive-securitypenetration-testingpentesting-toolsred-teamingsecuritysecurity-automation
fix(llm): collect usage stats from final stream chunk
0xallamb456a4ed8c2f
diff --git a/strix/llm/llm.py b/strix/llm/llm.pyindex 778e27fc..311de35e 100644--- a/strix/llm/llm.py+++ b/strix/llm/llm.py@@ -128,12 +128,18 @@ class LLM:async def _stream(self, messages: list[dict[str, Any]]) -> AsyncIterator[LLMResponse]:accumulated = ""chunks: list[Any] = []+ done_streaming = 0self._total_stats.requests += 1response = await acompletion(**self._build_completion_args(messages), stream=True)async for chunk in response:chunks.append(chunk)+ if done_streaming:+ done_streaming += 1+ if getattr(chunk, "usage", None) or done_streaming > 5:+ break+ continuedelta = self._get_chunk_content(chunk)if delta:accumulated += delta@@ -142,7 +148,8 @@ class LLM:: accumulated.find("</function>") + len("</function>")]yield LLMResponse(content=accumulated)- break+ done_streaming = 1+ continueyield LLMResponse(content=accumulated)if chunks: