MCPcopy Create free account
hub / github.com/SenseTime-Copilot/raccoon-dataanalysis-skill / example_data_analysis_flow

Function example_data_analysis_flow

scripts/main.py:526–586  ·  view source on GitHub ↗

数据分析完整流程示例

()

Source from the content-addressed store, hash-verified

524
525
526def example_data_analysis_flow():
527 """数据分析完整流程示例"""
528 print("=" * 60)
529 print("示例2: 数据分析完整流程")
530 print("=" * 60)
531
532 host = os.environ.get("RACCOON_API_HOST", "")
533 token = os.environ.get("RACCOON_API_TOKEN", "")
534 headers = {
535 "Content-Type": "application/json",
536 "Authorization": f"Bearer {token}",
537 }
538
539 print("\n[步骤1] 创建会话...")
540 resp = requests.post(
541 f"{host}/api/open/office/v2/sessions",
542 headers=headers,
543 json={"name": "Python示例会话"},
544 timeout=10,
545 )
546 session_data = resp.json().get("data", {})
547 session_id = session_data.get("id")
548 if not session_id:
549 print("创建会话失败")
550 return
551 print(f" 会话ID: {session_id}")
552
553 print("\n[步骤2] 上传临时文件...")
554 batch_id = str(uuid.uuid4())
555 csv_content = "name,age,score\nAlice,25,88\nBob,30,92\nCarol,28,85\nDave,35,95\nEve,22,78"
556 upload_headers = {k: v for k, v in headers.items() if k != "Content-Type"}
557 resp = requests.post(
558 f"{host}/api/open/office/v2/sessions/default_session/{batch_id}/files",
559 headers=upload_headers,
560 files={"file": ("sample_data.csv", csv_content.encode(), "text/csv")},
561 timeout=30,
562 )
563 upload_result = resp.json().get("data", {})
564 file_list = upload_result.get("file_list", [])
565 if not file_list:
566 print("上传文件失败")
567 return
568 file_id = file_list[0]["id"]
569 print(f" 文件ID: {file_id}, 文件名: {file_list[0]['file_name']}")
570
571 print("\n[步骤3] 发起对话分析...")
572 chat_data = {
573 "content": "帮我分析这份数据,画一个成绩分布柱状图",
574 "verbose": True,
575 "enable_web_search": False,
576 "deep_think": False,
577 "message_uuid": str(uuid.uuid4()),
578 "upload_file_id": [file_id],
579 }
580 stream_request_example(
581 host, headers, "POST",
582 f"/api/open/office/v2/sessions/{session_id}/chat/conversations",
583 chat_data,

Callers

nothing calls this directly

Calls 1

stream_request_exampleFunction · 0.85

Tested by

no test coverage detected