a2a-source-edit: write agent.py
This commit is contained in:
11
agent.py
11
agent.py
@@ -12,7 +12,6 @@ import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from typing import Annotated, Any
|
||||
@@ -31,7 +30,6 @@ from a2a_pack import (
|
||||
Pricing,
|
||||
Resources,
|
||||
RunContext,
|
||||
State,
|
||||
UploadedFile,
|
||||
)
|
||||
|
||||
@@ -95,7 +93,6 @@ class CsvAnswersStudioV1(A2AAgent[CsvAnswersStudioV1Config, PlatformUserAuth]):
|
||||
config_model = CsvAnswersStudioV1Config
|
||||
auth_model = PlatformUserAuth
|
||||
|
||||
state = State.DURABLE
|
||||
resources = Resources(cpu="500m", memory="512Mi", max_runtime_seconds=120)
|
||||
pricing = Pricing(
|
||||
price_per_call_usd=0.0,
|
||||
@@ -329,19 +326,21 @@ def _analyze_csv_text(*, analysis_id: str, csv_text: str, question: str) -> CsvA
|
||||
numeric_column = _choose_numeric_column(question, numeric_columns)
|
||||
row_label_column = _choose_label_column(header, numeric_columns)
|
||||
|
||||
best_index = -1
|
||||
best_record: dict[str, str] | None = None
|
||||
best_value: Decimal | None = None
|
||||
for record in records:
|
||||
for idx, record in enumerate(records):
|
||||
value = _parse_number(record.get(numeric_column, ""))
|
||||
if value is None:
|
||||
continue
|
||||
if best_value is None or value > best_value:
|
||||
best_value = value
|
||||
best_record = record
|
||||
best_index = idx
|
||||
if best_record is None or best_value is None:
|
||||
return _error(analysis_id, "no_numeric_values", f"Column {numeric_column!r} does not contain numeric values.")
|
||||
|
||||
label = best_record.get(row_label_column) or f"row {records.index(best_record) + 1}"
|
||||
label = best_record.get(row_label_column) or f"row {best_index + 1}"
|
||||
value_text = _format_decimal(best_value)
|
||||
answer = f"{label} has the highest {numeric_column} at {value_text}."
|
||||
chart_data = []
|
||||
@@ -357,7 +356,7 @@ def _analyze_csv_text(*, analysis_id: str, csv_text: str, question: str) -> CsvA
|
||||
)
|
||||
source_rows = [
|
||||
{
|
||||
"row_number": records.index(best_record) + 1,
|
||||
"row_number": best_index + 1,
|
||||
"values": best_record,
|
||||
"matched_column": numeric_column,
|
||||
"matched_value": float(best_value),
|
||||
|
||||
Reference in New Issue
Block a user