Skip to content

Commit 65430ad

Browse files
committed
Assistant - updates for local llms, include names for collab convos
1 parent fdaa1fc commit 65430ad

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,4 @@ locallm/
195195
llm/
196196
bedrocktools/
197197
kingdoms/
198+
dungeon/

assistant/assistant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Assistant(
5454
"""
5555

5656
__author__ = "[vertyco](https://github.com/vertyco/vrt-cogs)"
57-
__version__ = "6.12.20"
57+
__version__ = "6.12.21"
5858

5959
def format_help_for_context(self, ctx):
6060
helpcmd = super().format_help_for_context(ctx)

assistant/common/calls.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,28 @@ async def request_chat_completion_raw(
6666
if seed and model in SUPPORTS_SEED:
6767
kwargs["seed"] = seed
6868

69-
if functions and model not in NO_DEVELOPER_ROLE:
70-
if model in SUPPORTS_TOOLS:
71-
tools = []
72-
for func in functions:
73-
function = {"type": "function", "function": func, "name": func["name"]}
74-
tools.append(function)
75-
if tools:
76-
kwargs["tools"] = tools
77-
# If passing tools, make sure the messages payload has no "function_call" key
78-
for idx, message in enumerate(messages):
79-
if "function_call" in message:
80-
# Remove the message from the payload
81-
del kwargs["messages"][idx]
82-
83-
else:
84-
kwargs["functions"] = functions
85-
# If passing functions, make sure the messages payload has no tool calls
69+
if functions and model not in NO_DEVELOPER_ROLE:
70+
if model in SUPPORTS_TOOLS:
71+
tools = []
72+
for func in functions:
73+
function = {"type": "function", "function": func, "name": func["name"]}
74+
tools.append(function)
75+
if tools:
76+
kwargs["tools"] = tools
77+
# If passing tools, make sure the messages payload has no "function_call" key
8678
for idx, message in enumerate(messages):
87-
if "tool_calls" in message:
79+
if "function_call" in message:
8880
# Remove the message from the payload
8981
del kwargs["messages"][idx]
9082

83+
else:
84+
kwargs["functions"] = functions
85+
# If passing functions, make sure the messages payload has no tool calls
86+
for idx, message in enumerate(messages):
87+
if "tool_calls" in message:
88+
# Remove the message from the payload
89+
del kwargs["messages"][idx]
90+
9191
add_breadcrumb(
9292
category="api",
9393
message=f"Calling request_chat_completion_raw: {model}",

assistant/common/chat.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ async def handle_message(
132132
else:
133133
question += f"\n\n### Uploaded File ({i.filename}):\n{text}\n"
134134

135-
mem_id = message.channel.id if conf.collab_convos else message.author.id
135+
if conf.collab_convos:
136+
mem_id = message.channel.id
137+
if message.author.name == message.author.display_name:
138+
question = f"@{message.author.name}: {question}"
139+
else:
140+
question = f"@{message.author.name}({message.author.display_name}): {question}"
141+
else:
142+
mem_id = message.author.id
143+
136144
conversation = self.db.get_conversation(mem_id, message.channel.id, message.guild.id)
137145

138146
# If referencing a message that isnt part of the user's conversation, include the context
@@ -148,7 +156,12 @@ async def handle_message(
148156
include = False
149157

150158
if include:
151-
question = f"# {ref.author.name} SAID:\n{ref.content}\n\n# REPLY\n{question}"
159+
ref_author: discord.User | discord.Member = ref.author
160+
if ref_author.display_name == ref_author.name:
161+
name = f"@{ref_author.name}"
162+
else:
163+
name = f"@{ref_author.name}({ref_author.display_name})"
164+
question = f"{name}: {ref.content}\n\n# REPLY\n{question}"
152165

153166
if get_last_message:
154167
reply = conversation.messages[-1]["content"] if conversation.messages else _("No message history!")
@@ -267,6 +280,9 @@ async def get_chat_response(
267280
functions.extend(prepped_function_calls)
268281
mapping.update(prepped_function_map)
269282

283+
if not conf.use_function_calls and functions:
284+
functions = []
285+
270286
mem_id = author if isinstance(author, int) else author.id
271287
chan_id = channel if isinstance(channel, int) else channel.id
272288
if conf.collab_convos:

0 commit comments

Comments
 (0)