feat(gui): Implement RAG context visualization in Discussion history
This commit is contained in:
@@ -2710,6 +2710,26 @@ def hello():
|
||||
if read_mode:
|
||||
content = entry["content"]
|
||||
if content.strip():
|
||||
if '## Retrieved Context' in content:
|
||||
rag_match = re.search(r'## Retrieved Context\n\n([\s\S]*?)(?=\n\n#|\Z)', content)
|
||||
if rag_match:
|
||||
rag_section = rag_match.group(1)
|
||||
if imgui.collapsing_header('Retrieved Context'):
|
||||
chunks = re.finditer(r'### Chunk (\d+) \(Source: (.*?)\)\n([\s\S]*?)(?=\n### Chunk|\Z)', rag_section)
|
||||
for chunk_match in chunks:
|
||||
idx = chunk_match.group(1)
|
||||
path = chunk_match.group(2)
|
||||
chunk_content = chunk_match.group(3)
|
||||
if imgui.collapsing_header(f'Chunk {idx}: {path}'):
|
||||
if imgui.button(f'[Source]##rag_{i}_{idx}'):
|
||||
res = mcp_client.read_file(path)
|
||||
if res:
|
||||
self.text_viewer_title = path
|
||||
self.text_viewer_content = res
|
||||
self.text_viewer_type = Path(path).suffix.lstrip('.') if Path(path).suffix else 'text'
|
||||
self.show_text_viewer = True
|
||||
imgui.text_unformatted(chunk_content)
|
||||
content = content[:rag_match.start()] + content[rag_match.end():]
|
||||
pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?")
|
||||
matches = list(pattern.finditer(content))
|
||||
is_nerv = theme.is_nerv_active()
|
||||
|
||||
Reference in New Issue
Block a user