Skip to content

Commit

Permalink
refacto: Tools customer message
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Dec 12, 2024
1 parent b3d6f2e commit ff08922
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 167 deletions.
16 changes: 11 additions & 5 deletions app/helpers/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async def _stop_callback() -> None:

async def _commit_answer(
wait: bool,
tool_blacklist: set[str] | None = None,
tool_blacklist: set[str] = set(),
) -> None:
"""
Process the response.
Expand Down Expand Up @@ -289,9 +289,9 @@ async def _continue_chat( # noqa: PLR0915, PLR0913
client: CallAutomationClient,
post_callback: Callable[[CallStateModel], Awaitable[None]],
scheduler: Scheduler,
tool_blacklist: set[str] | None,
training_callback: Callable[[CallStateModel], Awaitable[None]],
tts_client: SpeechSynthesizer,
tool_blacklist: set[str] = set(),
_iterations_remaining: int = 3,
) -> CallStateModel:
"""
Expand Down Expand Up @@ -482,7 +482,7 @@ async def _generate_chat_completion( # noqa: PLR0913, PLR0911, PLR0912, PLR0915
client: CallAutomationClient,
post_callback: Callable[[CallStateModel], Awaitable[None]],
scheduler: Scheduler,
tool_blacklist: set[str] | None,
tool_blacklist: set[str],
tts_callback: Callable[[str, MessageStyleEnum], Awaitable[None]],
tts_client: SpeechSynthesizer,
use_tools: bool,
Expand Down Expand Up @@ -539,7 +539,7 @@ async def _content_callback(buffer: str) -> None:
if not use_tools:
logger.warning("Tools disabled for this chat")
else:
tools = await plugins.to_openai(tool_blacklist)
tools = await plugins.to_openai(frozenset(tool_blacklist))
# logger.debug("Tools: %s", tools)

# Execute LLM inference
Expand Down Expand Up @@ -626,7 +626,13 @@ async def _content_callback(buffer: str) -> None:
scheduler=scheduler,
):
await asyncio.gather(
*[plugins.execute_tool(tool_call) for tool_call in tool_calls]
*[
plugins.execute(
blacklist=tool_blacklist,
tool=tool_call,
)
for tool_call in tool_calls
]
)

# Update call model if object reference changed
Expand Down
Loading

0 comments on commit ff08922

Please sign in to comment.