Spaces:
Paused
Paused
| # Model Call Examples | |
| This directory contains example scripts for the major LLM providers supported by AgentScope, together with a unified test runner `run_tests.py`. | |
| These scripts are designed to verify that AgentScope's chat model components function correctly across various input scenarios. | |
| --- | |
| ## Directory Layout | |
| ``` | |
| scripts/model_examples/ | |
| βββ run_tests.py # Unified test runner | |
| βββ _utils.py # Shared helpers (stream_and_collect) | |
| βββ test.jpeg # Sample image for multimodal tests | |
| β | |
| βββ openai_chat_call.py # OpenAI Chat Completions β basic + tool call + structured output | |
| βββ openai_chat_multiagent.py # OpenAI Chat Completions β multi-agent conversation | |
| βββ openai_chat_multimodal.py # OpenAI Chat Completions β image/text multimodal | |
| βββ openai_chat_multiagent_multimodal.py | |
| β | |
| βββ openai_response_call.py # OpenAI Responses API β reasoning models (o1/o3) | |
| βββ openai_response_multiagent.py | |
| βββ openai_response_multimodal.py | |
| βββ openai_response_multiagent_multimodal.py | |
| β | |
| βββ anthropic_call.py # Anthropic Claude | |
| βββ anthropic_multiagent.py | |
| βββ anthropic_multimodal.py | |
| βββ anthropic_multiagent_multimodal.py | |
| β | |
| βββ dashscope_call.py # Alibaba DashScope / Qwen | |
| βββ dashscope_multiagent.py | |
| βββ dashscope_multimodal.py | |
| βββ dashscope_multiagent_multimodal.py | |
| β | |
| βββ deepseek_call.py # DeepSeek (no multimodal support) | |
| βββ deepseek_multiagent.py | |
| β | |
| βββ gemini_call.py # Google Gemini | |
| βββ gemini_multiagent.py | |
| βββ gemini_multimodal.py | |
| βββ gemini_multiagent_multimodal.py | |
| β | |
| βββ moonshot_call.py # Moonshot AI (Kimi) | |
| βββ moonshot_multiagent.py | |
| βββ moonshot_multimodal.py | |
| βββ moonshot_multiagent_multimodal.py | |
| β | |
| βββ xai_call.py # xAI Grok | |
| βββ xai_multiagent.py | |
| βββ xai_multimodal.py | |
| βββ xai_multiagent_multimodal.py | |
| β | |
| βββ ollama_call.py # Ollama local models (requires a running server) | |
| βββ ollama_multiagent.py | |
| βββ ollama_multimodal.py | |
| βββ ollama_multiagent_multimodal.py | |
| ``` | |
| --- | |
| ## Test Types | |
| | Suffix | File Pattern | What it covers | | |
| |---|---|---| | |
| | `call` | `*_call.py` | Basic text call + two-round tool calling + structured output | | |
| | `multiagent` | `*_multiagent.py` | Multi-agent scenario using `MultiAgentFormatter` | | |
| | `multimodal` | `*_multimodal.py` | Image + text multimodal input (some providers also test audio/video) | | |
| | `multiagent_multimodal` | `*_multiagent_multimodal.py` | Multi-agent + multimodal combined | | |
| --- | |
| ## Providers and Their Environment Variables | |
| | Provider | Env Variable | Notes | | |
| |---|---|---| | |
| | `openai_chat` | `OPENAI_API_KEY` | Chat Completions API β gpt-4.1, etc. | | |
| | `openai_response` | `OPENAI_API_KEY` | Responses API β o1, o3, o4-mini, etc. | | |
| | `anthropic` | `ANTHROPIC_API_KEY` | Claude models, supports extended thinking | | |
| | `dashscope` | `DASHSCOPE_API_KEY` | Qwen series, supports `thinking_enable` | | |
| | `deepseek` | `DEEPSEEK_API_KEY` | Supports only `call` / `multiagent` (no multimodal) | | |
| | `gemini` | `GEMINI_API_KEY` | Gemini models, supports `thinking_budget` | | |
| | `moonshot` | `MOONSHOT_API_KEY` | Moonshot AI kimi-k2.6, etc. | | |
| | `xai` | `XAI_API_KEY` | Grok models, supports `reasoning_effort` | | |
| | `ollama` | *(none β auto-detect)* | Local server, default `http://localhost:11434` | | |
| --- | |
| ## Quick Start | |
| ### 1. Export API Keys | |
| Set the environment variables for the providers you want to test: | |
| ```bash | |
| export OPENAI_API_KEY="sk-..." | |
| export ANTHROPIC_API_KEY="sk-ant-..." | |
| export DASHSCOPE_API_KEY="sk-..." | |
| export DEEPSEEK_API_KEY="sk-..." | |
| export GEMINI_API_KEY="AIza..." | |
| export MOONSHOT_API_KEY="sk-..." | |
| export XAI_API_KEY="xai-..." | |
| ``` | |
| For Ollama, no API key is required. Just make sure the server is running: | |
| ```bash | |
| ollama serve | |
| ollama pull qwen3:14b # pull the default model used in the scripts | |
| ``` | |
| ### 2. Check Provider Availability | |
| ```bash | |
| python scripts/model_examples/run_tests.py --list | |
| ``` | |
| Sample output: | |
| ``` | |
| Provider Env Var Available Description | |
| openai_chat OPENAI_API_KEY YES OpenAI Chat Completions API | |
| anthropic ANTHROPIC_API_KEY NO Anthropic Claude models | |
| ... | |
| ``` | |
| ### 3. Run All Available Tests | |
| ```bash | |
| python scripts/model_examples/run_tests.py | |
| ``` | |
| The runner auto-detects which providers have credentials, skips those that do not, and runs all test types for the rest. | |
| --- | |
| ## `run_tests.py` Reference | |
| ``` | |
| usage: run_tests.py [-h] [--providers NAME[,NAME...]] [--tests TYPE[,TYPE...]] | |
| [--timeout SECONDS] [--list] [--verbose] | |
| ``` | |
| ### Options | |
| | Option | Short | Default | Description | | |
| |---|---|---|---| | |
| | `--providers` | `-p` | all | Comma-separated list of providers to run | | |
| | `--tests` | `-t` | all | Comma-separated list of test types to run | | |
| | `--timeout` | | `120` | Per-script timeout in seconds | | |
| | `--list` | `-l` | | Print provider status table and exit | | |
| | `--verbose` | `-v` | | Stream each script's output in real time. By default output is suppressed and shown only when a test fails. | | |
| ### Examples | |
| ```bash | |
| # Only test specific providers | |
| python scripts/model_examples/run_tests.py --providers openai_chat,anthropic | |
| # Only run a specific test type (across all available providers) | |
| python scripts/model_examples/run_tests.py --tests call | |
| # Combine: run call + multiagent tests for dashscope and deepseek | |
| python scripts/model_examples/run_tests.py -p dashscope,deepseek -t call,multiagent | |
| # Only run multimodal tests | |
| python scripts/model_examples/run_tests.py --tests multimodal,multiagent_multimodal | |
| # Increase per-script timeout | |
| python scripts/model_examples/run_tests.py --timeout 180 | |
| # Check provider status | |
| python scripts/model_examples/run_tests.py --list | |
| ``` | |
| ### Summary Table | |
| At the end of a run, a summary table is printed: | |
| ``` | |
| Provider Test Type Status Time | |
| ---------------------- ---------------------------- -------- ------- | |
| openai_chat call PASS 12.3s | |
| openai_chat multiagent PASS 8.1s | |
| anthropic call SKIP (env var ANTHROPIC_API_KEY not set) | |
| deepseek call PASS 15.7s | |
| deepseek multimodal SKIP (not supported) | |
| Total: 12 | PASS: 8 | FAIL: 0 | SKIP: 4 | |
| ``` | |
| | Status | Meaning | | |
| |---|---| | |
| | **PASS** | Script exited with code 0 | | |
| | **FAIL** | Script exited with a non-zero code or timed out | | |
| | **SKIP** | API key missing, test type not supported, or script file absent | | |
| The runner exits with code `1` if any test fails. | |
| --- | |
| ## Running a Single Script | |
| Every script can be executed independently once the relevant environment variable is set: | |
| ```bash | |
| python scripts/model_examples/openai_chat_call.py | |
| python scripts/model_examples/dashscope_multiagent.py | |
| python scripts/model_examples/ollama_multimodal.py | |
| ``` | |
| Each script typically defines two or more async functions: | |
| - `example_simple_call()` β basic text call with streaming | |
| - `example_tool_call()` β two-round conversation with tool/function calling | |
| - `example_structured_output()` β force a Pydantic-validated JSON output (in `_call.py` variants, uses a thinking-enabled model) | |
| - `example_image_url()` / `example_image_local_path()` / `example_image_base64()` β image + text input (in `_multimodal.py` variants) | |
| - `example_audio()` β audio input (e.g. `openai_chat_multimodal.py`, `dashscope_multimodal.py`) | |
| - `example_video()` β video input (e.g. `dashscope_multimodal.py`) | |
| --- | |
| ## Ollama Notes | |
| Ollama runs locally and requires no API key, but you must: | |
| 1. Start the service: `ollama serve` | |
| 2. Pull the model used by the scripts: `ollama pull qwen3:14b` | |
| 3. If the service runs on a non-default address, set: `export OLLAMA_HOST=http://your-host:11434` | |
| `run_tests.py` pings the Ollama host before running any test. If the server is unreachable, all Ollama tests are automatically skipped. | |