Files
data-ge/test/data_import_analysis_example.py

43 lines
1.1 KiB
Python

"""Minimal example for hitting the /v1/import/analyze endpoint with Excel data."""
from __future__ import annotations
import asyncio
from pathlib import Path
import httpx
import pandas as pd
API_URL = "http://localhost:8000/v1/import/analyze"
CALLBACK_URL = "http://localhost:8000/__mock__/import-callback"
EXCEL_PATH = Path(__file__).resolve().parents[1] / "file" / "全国品牌.xlsx"
async def main() -> None:
excel = pd.ExcelFile(EXCEL_PATH)
sheet_name = excel.sheet_names[0]
df = excel.parse(sheet_name)
sampled = df.head(10)
rows = sampled.to_dict(orient="records")
headers = [str(column) for column in sampled.columns]
payload = {
"import_record_id": "demo-import-001",
"rows": rows,
"struce": headers,
"llm_model": "deepseek:deepseek-chat",
"temperature": 0.2,
"callback_url": CALLBACK_URL,
}
async with httpx.AsyncClient(timeout=httpx.Timeout(15.0)) as client:
response = await client.post(API_URL, json=payload)
print("Status:", response.status_code)
print("Body:", response.json())
if __name__ == "__main__":
asyncio.run(main())