feat(gui): Implement per-response token metrics and AI discussion compression
- Display token metrics (input/output/cache) per response in Discussion Hub. - Add total Discussion Token usage in the panel header. - Implement 'Compress' feature to intelligently summarize and replace exhausted discussion histories using an AI subagent.
This commit is contained in:
@@ -2623,4 +2623,39 @@ def run_subagent_summarization(file_path: str, content: str, is_code: bool, outl
|
||||
return resp_data.get("text", "")
|
||||
return "ERROR: Unsupported provider for sub-agent summarization"
|
||||
|
||||
def run_discussion_compression(discussion_text: str) -> str:
|
||||
prompt = f"The following is a long conversation history.\\nPlease provide a highly compact, dense summary of the key facts, decisions, bugs encountered, and outcomes that should be retained for context going forward. Categorize into User intent, Tool outputs, and AI reasoning. Omit pleasantries and redundant thoughts.\\n\\n[HISTORY]\\n{discussion_text}"
|
||||
if _provider == "gemini":
|
||||
_ensure_gemini_client()
|
||||
if _gemini_client:
|
||||
resp = _gemini_client.models.generate_content(
|
||||
model=_model,
|
||||
contents=prompt,
|
||||
config=types.GenerateContentConfig(temperature=0.0, max_output_tokens=2048)
|
||||
)
|
||||
return resp.text or ""
|
||||
elif _provider == "anthropic":
|
||||
_ensure_anthropic_client()
|
||||
if _anthropic_client:
|
||||
resp = _anthropic_client.messages.create(
|
||||
model=_model, max_tokens=2048,
|
||||
messages=[{"role": "user", "content": prompt}]
|
||||
)
|
||||
return "".join([b.text for b in resp.content if hasattr(b, "text") and b.text])
|
||||
elif _provider == "deepseek":
|
||||
creds = _load_credentials()
|
||||
api_key = creds.get("deepseek", {}).get("api_key")
|
||||
if not api_key: return "ERROR: DeepSeek API key missing"
|
||||
try:
|
||||
r = requests.post("https://api.deepseek.com/chat/completions", headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}, json={"model": _model, "messages": [{"role": "user", "content": prompt}], "temperature": 0.0}, timeout=60)
|
||||
r.raise_for_status()
|
||||
return r.json()["choices"][0]["message"]["content"]
|
||||
except Exception as e:
|
||||
return f"ERROR: DeepSeek compression failed: {e}"
|
||||
elif _provider == "gemini_cli":
|
||||
adapter = GeminiCliAdapter(binary_path="gemini")
|
||||
resp_data = adapter.send(prompt, model=_model)
|
||||
return resp_data.get("text", "")
|
||||
return "ERROR: Unsupported provider for discussion compression"
|
||||
|
||||
#endregion: Subagent Summarization
|
||||
|
||||
Reference in New Issue
Block a user