mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
MORE VERBOSEEEEEEEE
This commit is contained in:
parent
e48a76ac85
commit
e31ad17d7e
1 changed files with 4 additions and 6 deletions
|
@ -90,8 +90,6 @@ except Exception as _pyttsx3_err:
|
||||||
async def ollama_stream_reader(response: httpx.Response) -> typing.AsyncGenerator[
|
async def ollama_stream_reader(response: httpx.Response) -> typing.AsyncGenerator[
|
||||||
dict[str, str | int | bool], None
|
dict[str, str | int | bool], None
|
||||||
]:
|
]:
|
||||||
log = logging.getLogger("ollama_stream_reader")
|
|
||||||
log.setLevel(logging.DEBUG)
|
|
||||||
stream = response.aiter_bytes(1)
|
stream = response.aiter_bytes(1)
|
||||||
_buffer = b""
|
_buffer = b""
|
||||||
while not response.is_stream_consumed:
|
while not response.is_stream_consumed:
|
||||||
|
@ -100,9 +98,9 @@ async def ollama_stream_reader(response: httpx.Response) -> typing.AsyncGenerato
|
||||||
async for char in stream:
|
async for char in stream:
|
||||||
_buffer += char
|
_buffer += char
|
||||||
_buffer = _buffer.rstrip()
|
_buffer = _buffer.rstrip()
|
||||||
log.debug("Resolving %r", _buffer.decode())
|
print("[ollama stream reader] Resolving %r" % (_buffer.decode()))
|
||||||
chunk = json.loads(_buffer.decode("utf-8", "replace"))
|
chunk = json.loads(_buffer.decode("utf-8", "replace"))
|
||||||
log.debug("%r -> %r", _buffer.decode(), chunk)
|
print("[ollama stream reader] %r -> %r" % (_buffer.decode(), chunk))
|
||||||
yield chunk
|
yield chunk
|
||||||
|
|
||||||
|
|
||||||
|
@ -1862,7 +1860,7 @@ class OtherCog(commands.Cog):
|
||||||
colour=discord.Colour.blurple(),
|
colour=discord.Colour.blurple(),
|
||||||
)
|
)
|
||||||
output.set_footer(text="Powered by Ollama")
|
output.set_footer(text="Powered by Ollama")
|
||||||
|
await msg.edit(content="Starting generation. Please wait.")
|
||||||
async with ctx.channel.typing():
|
async with ctx.channel.typing():
|
||||||
async with client.stream(
|
async with client.stream(
|
||||||
"POST",
|
"POST",
|
||||||
|
@ -1881,7 +1879,7 @@ class OtherCog(commands.Cog):
|
||||||
return await msg.edit(content="Failed to generate text: `%s`" % response.text)
|
return await msg.edit(content="Failed to generate text: `%s`" % response.text)
|
||||||
last_edit = msg.edited_at.timestamp() if msg.edited_at else msg.created_at.timestamp()
|
last_edit = msg.edited_at.timestamp() if msg.edited_at else msg.created_at.timestamp()
|
||||||
async for chunk in ollama_stream_reader(response):
|
async for chunk in ollama_stream_reader(response):
|
||||||
if "done" not in chunk or "response" not in chunk:
|
if "done" not in chunk.keys() or "response" not in chunk.keys():
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
content = "Response is still being generated..."
|
content = "Response is still being generated..."
|
||||||
|
|
Loading…
Reference in a new issue