ghostdrive1's picture
Upload folder using huggingface_hub
0b9dc2e verified
|
Raw
History Blame Contribute Delete
8.59 kB

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:

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:

ollama serve
ollama pull qwen3:14b   # pull the default model used in the scripts

2. Check Provider Availability

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

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

# 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:

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.