Skip to content

Commit

Permalink
include content in function call results (#897)
Browse files Browse the repository at this point in the history
Co-authored-by: Théo Monnom <[email protected]>
  • Loading branch information
martin-purplefish and theomonnom authored Oct 15, 2024
1 parent a95dd8f commit 5a0f994
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-suits-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-agents": patch
---

Include chat context on collected tool calls
5 changes: 5 additions & 0 deletions .changeset/strong-lobsters-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-plugins-openai": patch
---

Fix functions to include content
4 changes: 3 additions & 1 deletion livekit-agents/livekit/agents/llm/chat_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def create_tool_from_called_function(
@staticmethod
def create_tool_calls(
called_functions: list[function_context.FunctionCallInfo],
*,
text: str = "",
) -> "ChatMessage":
return ChatMessage(role="assistant", tool_calls=called_functions, content="")
return ChatMessage(role="assistant", tool_calls=called_functions, content=text)

@staticmethod
def create(
Expand Down
4 changes: 3 additions & 1 deletion livekit-agents/livekit/agents/pipeline/pipeline_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,9 @@ def _commit_user_question_if_needed() -> None:
)

if tool_calls:
extra_tools_messages.append(ChatMessage.create_tool_calls(tool_calls))
extra_tools_messages.append(
ChatMessage.create_tool_calls(tool_calls, content=collected_text)
)
extra_tools_messages.extend(tool_calls_results_msg)

chat_ctx = speech_handle.source.chat_ctx.copy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,11 @@ def _try_run_function(self, choice: Choice) -> llm.ChatChunk | None:
return llm.ChatChunk(
choices=[
llm.Choice(
delta=llm.ChoiceDelta(role="assistant", tool_calls=[fnc_info]),
delta=llm.ChoiceDelta(
role="assistant",
tool_calls=[fnc_info],
content=choice.delta.content,
),
index=choice.index,
)
]
Expand Down

0 comments on commit 5a0f994

Please sign in to comment.