File size: 8,594 Bytes
0b9dc2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# 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.