From fc07081bae76ee2b6c2bcd59032310d4ea106897 Mon Sep 17 00:00:00 2001 From: Kim Tran Date: Wed, 26 Jun 2024 15:42:27 -0400 Subject: [PATCH] Add support cli to display tool_calls --- log10/completions/completions.py | 10 +++++++--- tests/test_cli.py | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/log10/completions/completions.py b/log10/completions/completions.py index 0bad042..4caea1a 100644 --- a/log10/completions/completions.py +++ b/log10/completions/completions.py @@ -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: @@ -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() diff --git a/tests/test_cli.py b/tests/test_cli.py index 289054a..acdda48 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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