50 lines
1.3 KiB
Python
50 lines
1.3 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
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
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,
|
|
"headers": headers,
|
|
"table_schema": {
|
|
"source": "excel",
|
|
"file_name": EXCEL_PATH.name,
|
|
"sheet_name": sheet_name,
|
|
},
|
|
"llm_model": "deepseek:deepseek-chat",
|
|
"temperature": 0.2,
|
|
"callback_url": CALLBACK_URL,
|
|
}
|
|
|
|
async with httpx.AsyncClient(timeout=httpx.Timeout(60.0)) as client:
|
|
response = await client.post(API_URL, json=payload)
|
|
print("Status:", response.status_code)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|