mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
switch to mdstream
This commit is contained in:
parent
e50a0e8b09
commit
b143bc56ac
2 changed files with 18 additions and 17 deletions
|
@ -13,13 +13,13 @@ from pathlib import Path
|
|||
import openai
|
||||
from jsonschema import Draft7Validator
|
||||
from rich.console import Console, Text
|
||||
from rich.live import Live
|
||||
from rich.markdown import Markdown
|
||||
|
||||
from aider import models, prompts, utils
|
||||
from aider.commands import Commands
|
||||
from aider.history import ChatSummary
|
||||
from aider.io import InputOutput
|
||||
from aider.mdstream import MarkdownStream
|
||||
from aider.repo import GitRepo
|
||||
from aider.repomap import RepoMap
|
||||
from aider.sendchat import send_with_retries
|
||||
|
@ -725,14 +725,12 @@ class Coder:
|
|||
self.io.tool_output(tokens)
|
||||
|
||||
def show_send_output_stream(self, completion):
|
||||
live = None
|
||||
if self.show_pretty():
|
||||
live = Live(vertical_overflow="scroll")
|
||||
mdstream = MarkdownStream()
|
||||
else:
|
||||
mdstream = None
|
||||
|
||||
try:
|
||||
if live:
|
||||
live.start()
|
||||
|
||||
for chunk in completion:
|
||||
if len(chunk.choices) == 0:
|
||||
continue
|
||||
|
@ -762,22 +760,21 @@ class Coder:
|
|||
text = None
|
||||
|
||||
if self.show_pretty():
|
||||
self.live_incremental_response(live, False)
|
||||
self.live_incremental_response(mdstream, False)
|
||||
elif text:
|
||||
sys.stdout.write(text)
|
||||
sys.stdout.flush()
|
||||
finally:
|
||||
if live:
|
||||
self.live_incremental_response(live, True)
|
||||
live.stop()
|
||||
if mdstream:
|
||||
self.live_incremental_response(mdstream, True)
|
||||
|
||||
def live_incremental_response(self, live, final):
|
||||
def live_incremental_response(self, mdstream, final):
|
||||
show_resp = self.render_incremental_response(final)
|
||||
if not show_resp:
|
||||
return
|
||||
|
||||
md = Markdown(show_resp, style=self.assistant_output_color, code_theme=self.code_theme)
|
||||
live.update(md)
|
||||
mdargs = dict(style=self.assistant_output_color, code_theme=self.code_theme)
|
||||
mdstream.update(show_resp, mdargs=mdargs, final=final)
|
||||
|
||||
def render_incremental_response(self, final):
|
||||
return self.partial_response_content
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue