Fix the space strip and JSON output

This commit is contained in:
Nexus 2024-01-09 00:42:12 +00:00
parent 7d2173aeb7
commit 9146d1cda9
2 changed files with 17 additions and 9 deletions

View file

@ -4,10 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="aa6d62a8-d64d-4a60-a85f-8d9fa52b6b49" name="Changes" comment="Fix ollama streaming">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cogs/ollama.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cogs/ollama.py" afterDir="false" />
</list>
<list default="true" id="aa6d62a8-d64d-4a60-a85f-8d9fa52b6b49" name="Changes" comment="Set output to TTY because why not" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -80,7 +77,7 @@
<workItem from="1704317484555" duration="1407000" />
<workItem from="1704572901106" duration="125000" />
<workItem from="1704573038888" duration="7749000" />
<workItem from="1704760229948" duration="286000" />
<workItem from="1704760229948" duration="589000" />
</task>
<task id="LOCAL-00001" summary="Update gitignore">
<option name="closed" value="true" />
@ -226,7 +223,15 @@
<option name="project" value="LOCAL" />
<updated>1704760514718</updated>
</task>
<option name="localTasksCounter" value="19" />
<task id="LOCAL-00019" summary="Set output to TTY because why not">
<option name="closed" value="true" />
<created>1704760592118</created>
<option name="number" value="00019" />
<option name="presentableId" value="LOCAL-00019" />
<option name="project" value="LOCAL" />
<updated>1704760592118</updated>
</task>
<option name="localTasksCounter" value="20" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -252,6 +257,7 @@
<MESSAGE value="Better log ollama" />
<MESSAGE value="Fix screenshot errors" />
<MESSAGE value="Fix ollama streaming" />
<option name="LAST_COMMIT_MESSAGE" value="Fix ollama streaming" />
<MESSAGE value="Set output to TTY because why not" />
<option name="LAST_COMMIT_MESSAGE" value="Set output to TTY because why not" />
</component>
</project>

View file

@ -226,7 +226,7 @@ class Ollama(commands.Cog):
json={
"model": model,
"prompt": query,
"format": "json",
# "format": "json",
"system": system_prompt,
"stream": True
}
@ -244,7 +244,9 @@ class Ollama(commands.Cog):
last_update = time.time()
async for line in self.ollama_stream(response.content):
embed.description += line["response"].strip()
if not line["response"].strip("\n\r"):
continue
embed.description += line["response"]
embed.timestamp = discord.utils.utcnow()
if len(embed.description) >= 4096:
embed.description = embed.description[:4093] + "..."