From c3ee88c773f8e700b60104d0745da85e1caa5d34 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Thu, 6 Mar 2025 21:04:05 -0800 Subject: [PATCH] docs for swarms api in chinese and examples --- docs/mkdocs.yml | 4 + docs/swarms/examples/swarms_api_medical.md | 125 +++++++++++++ docs/swarms_cloud/chinese_api_pricing.md | 195 +++++++++++++++++++++ 3 files changed, 324 insertions(+) create mode 100644 docs/swarms/examples/swarms_api_medical.md create mode 100644 docs/swarms_cloud/chinese_api_pricing.md diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 9fbaae94..4a643d64 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -205,6 +205,9 @@ nav: - Full API Reference: "swarms/framework/reference.md" - Examples: - Unique Swarms: "swarms/examples/unique_swarms.md" + + - Swarms API Examples: + - Medical Swarm: "swarms/examples/swarms_api_medical.md" - Various Model Providers: - OpenAI: "swarms/examples/openai_example.md" - Anthropic: "swarms/examples/claude.md" @@ -273,6 +276,7 @@ nav: # - Overview: "swarms_cloud/launch.md" - Overview: "swarms_cloud/swarms_api.md" - Swarms API Pricing: "swarms_cloud/api_pricing.md" + - Swarms API Pricing in Chinese: "swarms_cloud/chinese_api_pricing.md" # - Swarms Cloud CLI: "swarms_cloud/cli.md" - Swarm Ecosystem APIs: - MCS API: "swarms_cloud/mcs_api.md" diff --git a/docs/swarms/examples/swarms_api_medical.md b/docs/swarms/examples/swarms_api_medical.md new file mode 100644 index 00000000..dffa7ee7 --- /dev/null +++ b/docs/swarms/examples/swarms_api_medical.md @@ -0,0 +1,125 @@ +# Medical Swarm Example + +1. Get your API key from the Swarms API dashboard [HERE](https://swarms.world/platform/api-keys) +2. Create a `.env` file in the root directory and add your API key: + +```bash +SWARMS_API_KEY= +``` + +3. Create a Python script to create and trigger the medical swarm: + +```python +import os +import requests +from dotenv import load_dotenv +import json + +load_dotenv() + +# Retrieve API key securely from .env +API_KEY = os.getenv("SWARMS_API_KEY") +BASE_URL = "https://swarms-api-285321057562.us-east1.run.app" + +# Headers for secure API communication +headers = {"x-api-key": API_KEY, "Content-Type": "application/json"} + +def create_medical_swarm(patient_case: str): + """ + Constructs and triggers a full-stack medical swarm consisting of three agents: + Diagnostic Specialist, Medical Coder, and Treatment Advisor. + Each agent is provided with a comprehensive, detailed system prompt to ensure high reliability. + """ + + payload = { + "swarm_name": "Enhanced Medical Diagnostic Swarm", + "description": "A swarm of agents specialized in performing comprehensive medical diagnostics, analysis, and coding.", + "agents": [ + { + "agent_name": "Diagnostic Specialist", + "description": "Agent specialized in analyzing patient history, symptoms, lab results, and imaging data to produce accurate diagnoses.", + "system_prompt": ( + "You are an experienced, board-certified medical diagnostician with over 20 years of clinical practice. " + "Your role is to analyze all available patient information—including history, symptoms, lab tests, and imaging results—" + "with extreme attention to detail and clinical nuance. Provide a comprehensive differential diagnosis considering " + "common, uncommon, and rare conditions. Always cross-reference clinical guidelines and evidence-based medicine. " + "Explain your reasoning step by step and provide a final prioritized list of potential diagnoses along with their likelihood. " + "Consider patient demographics, comorbidities, and risk factors. Your diagnosis should be reliable, clear, and actionable." + ), + "model_name": "openai/gpt-4o", + "role": "worker", + "max_loops": 2, + "max_tokens": 4000, + "temperature": 0.3, + "auto_generate_prompt": False + }, + { + "agent_name": "Medical Coder", + "description": "Agent responsible for translating medical diagnoses and procedures into accurate standardized medical codes (ICD-10, CPT, etc.).", + "system_prompt": ( + "You are a certified and experienced medical coder, well-versed in ICD-10, CPT, and other coding systems. " + "Your task is to convert detailed medical diagnoses and treatment procedures into precise, standardized codes. " + "Consider all aspects of the clinical documentation including severity, complications, and comorbidities. " + "Provide clear explanations for the codes chosen, referencing the latest coding guidelines and payer policies where relevant. " + "Your output should be comprehensive, reliable, and fully compliant with current medical coding standards." + ), + "model_name": "openai/gpt-4o", + "role": "worker", + "max_loops": 1, + "max_tokens": 3000, + "temperature": 0.2, + "auto_generate_prompt": False + }, + { + "agent_name": "Treatment Advisor", + "description": "Agent dedicated to suggesting evidence-based treatment options, including pharmaceutical and non-pharmaceutical interventions.", + "system_prompt": ( + "You are a highly knowledgeable medical treatment specialist with expertise in the latest clinical guidelines and research. " + "Based on the diagnostic conclusions provided, your task is to recommend a comprehensive treatment plan. " + "Your suggestions should include first-line therapies, potential alternative treatments, and considerations for patient-specific factors " + "such as allergies, contraindications, and comorbidities. Explain the rationale behind each treatment option and reference clinical guidelines where applicable. " + "Your recommendations should be reliable, detailed, and clearly prioritized based on efficacy and safety." + ), + "model_name": "openai/gpt-4o", + "role": "worker", + "max_loops": 1, + "max_tokens": 5000, + "temperature": 0.3, + "auto_generate_prompt": False + } + ], + "max_loops": 3, + "swarm_type": "Sequential" # Sequential workflow: Each agent builds on the output of the previous one + } + + # Payload includes the patient case as the task to be processed by the swarm + payload = { + "task": patient_case, + "swarm": payload + } + + response = requests.post( + f"{BASE_URL}/swarm/completion", + headers=headers, + json=payload, + ) + + if response.status_code == 200: + print("Swarm successfully executed!") + return json.dumps(response.json(), indent=4) + else: + print(f"Error {response.status_code}: {response.text}") + return None + + +# Example Patient Task for the Swarm to diagnose and analyze +if __name__ == "__main__": + patient_case = ( + "Patient is a 55-year-old male presenting with severe chest pain, shortness of breath, elevated blood pressure, " + "nausea, and a family history of cardiovascular disease. Blood tests show elevated troponin levels, and EKG indicates ST-segment elevations. " + "The patient is currently unstable. Provide a detailed diagnosis, coding, and treatment plan." + ) + + diagnostic_output = create_medical_swarm(patient_case) + print(diagnostic_output) +``` \ No newline at end of file diff --git a/docs/swarms_cloud/chinese_api_pricing.md b/docs/swarms_cloud/chinese_api_pricing.md new file mode 100644 index 00000000..ca935321 --- /dev/null +++ b/docs/swarms_cloud/chinese_api_pricing.md @@ -0,0 +1,195 @@ +# Swarm Agent API 定价文档 + + +Swarm Agent API 提供了一个强大的平台,用于大规模管理多代理协作和在云端编排 LLM 代理群。本文档概述了定价模型、成本计算方式以及如何购买和管理您的积分。 + +我们的定价设计旨在透明且具有成本效益,使您能够轻松发挥代理的全部潜力。成本基于: + +- 使用的代理数量 + +- 输入和输出令牌使用量 + +- 执行时间 + +## 积分系统 + +Swarm API 采用基于积分的系统: + +- **积分**是平台内使用的货币 + +- 1积分 = 1美元 + +- 积分可以用美元或 $swarms Solana 代币购买 + +- 两种类型的积分: + + - **标准积分**:购买的积分永不过期 + + - **免费积分**:促销积分,可能有使用限制 + +## 定价结构 + +### 基本成本 + +| 成本组成 | 价格 | +|----------------|-------| +| 每个代理的基本成本 | 每个代理$0.01 | + +### 令牌使用成本 + +| 令牌类型 | 成本 | +|------------|------| +| 输入令牌 | 每百万令牌$2.00 | +| 输出令牌 | 每百万令牌$4.50 | + +### 夜间折扣 + +为了鼓励在非高峰时段高效利用资源,我们在加州夜间时段提供显著折扣: + +| 时间段(太平洋时间) | 折扣 | +|----------------------------|----------| +| 晚上8:00至早上6:00 | 令牌成本75%折扣 | + +## 成本计算 + +### 公式 + +群体执行的总成本计算如下: + +``` +总成本 = (代理数量 × $0.01) + + (总输入令牌数 / 1M × $2.00 × 代理数量) + + (总输出令牌数 / 1M × $4.50 × 代理数量) +``` + +应用夜间折扣时: +``` +输入令牌成本 = 输入令牌成本 × 0.25 +输出令牌成本 = 输出令牌成本 × 0.25 +``` + +### 示例场景 + +#### 场景1:基本工作流(白天) + +- 3个代理 + +- 总共10,000个输入令牌 + +- 总共25,000个输出令牌 + +**计算:** + +- 代理成本:3 × $0.01 = $0.03 + +- 输入令牌成本:(10,000 / 1,000,000) × $2.00 × 3 = $0.06 + +- 输出令牌成本:(25,000 / 1,000,000) × $4.50 × 3 = $0.3375 + +- **总成本:$0.4275** + +#### 场景2:复杂工作流(夜间) + +- 5个代理 + +- 总共50,000个输入令牌 + +- 总共125,000个输出令牌 + +**计算:** + +- 代理成本:5 × $0.01 = $0.05 + +- 输入令牌成本:(50,000 / 1,000,000) × $2.00 × 5 × 0.25 = $0.125 + +- 输出令牌成本:(125,000 / 1,000,000) × $4.50 × 5 × 0.25 = $0.703125 + +- **总成本:$0.878125** + +## 购买积分 + +可以通过我们的平台以两种方式购买积分: + +1. **美元支付** + - 可通过我们的[账户页面](https://swarms.world/platform/account)使用 + - 安全支付处理 + - 最低购买额:$10 + +2. **$swarms 代币支付** + - 使用基于Solana的$swarms代币 + - 可在支持的交易所购买代币 + - 在我们的[账户页面](https://swarms.world/platform/account)连接您的Solana钱包 + +## 免费积分 + +我们偶尔会向以下对象提供免费积分: + +- 新用户(欢迎奖励) + +- 促销期间 + +- 教育和研究目的 + +关于免费积分的说明: + +- 在标准积分之前使用 + +- 可能有过期日期 + +- 可能有使用限制 + +## 账单和使用跟踪 + +通过我们全面的日志和报告功能跟踪您的积分使用情况: + +1. **API日志** + + - 通过`/v1/swarm/logs`端点访问详细日志 + + - 查看每次执行的成本明细 + +2. **仪表板** + + - 实时积分余额显示 + + - 历史使用图表 + + - 详细成本分析 + + - 可在[https://swarms.world/platform/dashboard](https://swarms.world/platform/dashboard)访问 + +## 常见问题 + +**问:是否有最低积分购买要求?** +答:是的,最低积分购买额为10美元等值。 + +**问:积分会过期吗?** +答:标准积分不会过期。免费促销积分可能有过期日期。 + +**问:夜间折扣如何应用?** +答:系统会根据太平洋时间(America/Los_Angeles)自动检测执行时间,并在晚上8:00至早上6:00之间的执行应用75%的令牌成本折扣。 + +**问:如果我在执行过程中积分用完了会怎样?** +答:如果没有足够的积分,执行将失败并显示402 Payment Required错误。我们建议维持适合您使用模式的积分余额。 + +**问:我可以获得未使用积分的退款吗?** +答:请联系我们的支持团队处理未使用积分的退款请求。 + +**问:是否有批量折扣?** +答:是的,请联系我们的销售团队了解企业定价和批量折扣。 + +## 参考资料 + +- [Swarm API 文档](https://docs.swarms.world) + +- [账户管理门户](https://swarms.world/platform/account) + +- [Swarm 类型参考](https://docs.swarms.world/swarm-types) + +- [令牌使用指南](https://docs.swarms.world/token-usage) + +- [API 参考](https://docs.swarms.world/api-reference) + +--- + +如有其他问题或自定义定价选项,请联系我们的支持团队,邮箱:kye@swarms.world \ No newline at end of file