Skip to content

Commit

Permalink
Add support cli to display tool_calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kxtran committed Jun 26, 2024
1 parent db3093e commit fc07081
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions log10/completions/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def _render_completions_table(completions_data, total_completions):
first_choice = response_choices[0]
if "message" in first_choice:
response = first_choice["message"].get("content", "")
if not response:
tool_calls = first_choice["message"].get("tool_calls", [])
if tool_calls:
last_tool_call = tool_calls[-1]
response = last_tool_call.get("function", {}).get("arguments", "")
elif "function_call" in first_choice:
response = json.dumps(first_choice.get("function_call", {}))
else:
Expand Down Expand Up @@ -129,9 +134,8 @@ def _render_completions_table(completions_data, total_completions):
if isinstance(item["prompt"], list):
item["prompt"] = " ".join(item["prompt"])
short_prompt = item["prompt"][:max_len] + "..." if len(item["prompt"]) > max_len else item["prompt"]
short_completion = (
item["completion"][:max_len] + "..." if len(item["completion"]) > max_len else item["completion"]
)
completion = item.get("completion", "")
short_completion = completion[:max_len] + "..." if len(completion) > max_len else completion
table.add_row(item["id"], item["status"], item["created_at"], short_prompt, short_completion, tags)

console = Console()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from log10.cli.cli_commands import cli


completion_id = "fb891d4e-f99c-4d8d-a95c-24d2ed7a0807"
feedback_id = "0e43b537-5f0c-4f47-ba83-4938514477c3"
feedback_task_id = "1c84079e-a7bb-47e1-86c7-e32b51045e8e"
completion_id = "fe3c10f0-df31-4a42-b224-233adfe1eb7f"
feedback_id = "58b8d9b7-1d6a-4b7d-952e-bc97a649dc94"
feedback_task_id = "890bda39-2232-4cde-ba95-7c501afc4b95"


@pytest.fixture
Expand Down

0 comments on commit fc07081

Please sign in to comment.