I hate the word "thread" now.
This commit is contained in:
parent
b0c25254ea
commit
14237b8f5f
1 changed files with 15 additions and 4 deletions
|
@ -170,6 +170,13 @@ class ChatHistory:
|
||||||
"""Gets a copy of an entire thread"""
|
"""Gets a copy of an entire thread"""
|
||||||
return self._internal.get(thread, {}).copy()
|
return self._internal.get(thread, {}).copy()
|
||||||
|
|
||||||
|
def find_thread(self, thread_id: str):
|
||||||
|
"""Attempts to find a thread."""
|
||||||
|
if c := self.get_thread(thread_id):
|
||||||
|
return c
|
||||||
|
if d := self.load_thread(thread_id):
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
SERVER_KEYS = list(CONFIG["ollama"].keys())
|
SERVER_KEYS = list(CONFIG["ollama"].keys())
|
||||||
|
|
||||||
|
@ -467,10 +474,11 @@ class Ollama(commands.Cog):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = self.history.create_thread(ctx.user)
|
context = self.history.create_thread(ctx.user)
|
||||||
elif context is not None and self.history.get_thread(context) is None:
|
elif context is not None and self.history.get_thread(context) is None:
|
||||||
if not self.history.load_thread(context):
|
__thread = self.history.find_thread(context)
|
||||||
|
if not __thread:
|
||||||
return await ctx.respond("Invalid thread ID.")
|
return await ctx.respond("Invalid thread ID.")
|
||||||
else:
|
else:
|
||||||
context = self.history.create_thread(ctx.user)
|
context = list(__thread.keys())[0]
|
||||||
|
|
||||||
messages = self.history.get_history(context)
|
messages = self.history.get_history(context)
|
||||||
user_message = {
|
user_message = {
|
||||||
|
@ -570,7 +578,7 @@ class Ollama(commands.Cog):
|
||||||
async def ollama_history(
|
async def ollama_history(
|
||||||
self,
|
self,
|
||||||
ctx: discord.ApplicationContext,
|
ctx: discord.ApplicationContext,
|
||||||
thread: typing.Annotated[
|
thread_id: typing.Annotated[
|
||||||
str,
|
str,
|
||||||
discord.Option(
|
discord.Option(
|
||||||
name="thread_id",
|
name="thread_id",
|
||||||
|
@ -584,7 +592,10 @@ class Ollama(commands.Cog):
|
||||||
await ctx.defer(ephemeral=True)
|
await ctx.defer(ephemeral=True)
|
||||||
paginator = commands.Paginator("", "", 4000, "\n\n")
|
paginator = commands.Paginator("", "", 4000, "\n\n")
|
||||||
|
|
||||||
history = self.history.get_history(thread)
|
thread = self.history.load_thread(thread_id)
|
||||||
|
if not thread:
|
||||||
|
return await ctx.respond("No thread with that ID exists.")
|
||||||
|
history = self.history.get_history(thread_id)
|
||||||
if not history:
|
if not history:
|
||||||
return await ctx.respond("No history or invalid context key.")
|
return await ctx.respond("No history or invalid context key.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue