add custom api key
This commit is contained in:
@@ -127,6 +127,9 @@ python main.py --base-url http://localhost:8000/v1 --model "autoglm-phone-9b"
|
||||
# 指定模型端点
|
||||
python main.py --base-url http://localhost:8000/v1 "打开美团搜索附近的火锅店"
|
||||
|
||||
# 使用 API Key 进行认证
|
||||
python main.py --apikey sk-xxxxx
|
||||
|
||||
# 使用英文 system prompt
|
||||
python main.py --lang en --base-url http://localhost:8000/v1 "Open Chrome browser"
|
||||
|
||||
@@ -255,6 +258,7 @@ conn.disconnect("192.168.1.100:5555")
|
||||
|-------------------------|------------------|----------------------------|
|
||||
| `PHONE_AGENT_BASE_URL` | 模型 API 地址 | `http://localhost:8000/v1` |
|
||||
| `PHONE_AGENT_MODEL` | 模型名称 | `autoglm-phone-9b` |
|
||||
| `PHONE_AGENT_API_KEY` | 模型认证 API Key | `EMPTY` |
|
||||
| `PHONE_AGENT_MAX_STEPS` | 每个任务最大步数 | `100` |
|
||||
| `PHONE_AGENT_DEVICE_ID` | ADB 设备 ID | (自动检测) |
|
||||
| `PHONE_AGENT_LANG` | 语言 (`cn` 或 `en`) | `cn` |
|
||||
|
||||
@@ -52,7 +52,7 @@ Python 3.10 or higher is recommended.
|
||||
|
||||
**Please carefully check the relevant permissions**
|
||||
|
||||

|
||||

|
||||
|
||||
### 4. Install ADB Keyboard (for Text Input)
|
||||
|
||||
@@ -121,6 +121,9 @@ python main.py --base-url http://localhost:8000/v1 --model "autoglm-phone-9b"
|
||||
# Specify model endpoint
|
||||
python main.py --base-url http://localhost:8000/v1 "Open Meituan and search for nearby hotpot restaurants"
|
||||
|
||||
# Use API key for authentication
|
||||
python main.py --apikey sk-xxxxx
|
||||
|
||||
# Use English system prompt
|
||||
python main.py --lang en --base-url http://localhost:8000/v1 "Open Chrome browser"
|
||||
|
||||
@@ -158,7 +161,7 @@ Phone Agent supports remote ADB debugging via WiFi/network, allowing device cont
|
||||
|
||||
Ensure the phone and computer are on the same WiFi network, as shown below:
|
||||
|
||||

|
||||

|
||||
|
||||
#### Use Standard ADB Commands on Computer
|
||||
|
||||
@@ -248,6 +251,7 @@ You can directly modify the corresponding config files to enhance model capabili
|
||||
|---------------------------|---------------------------|------------------------------|
|
||||
| `PHONE_AGENT_BASE_URL` | Model API URL | `http://localhost:8000/v1` |
|
||||
| `PHONE_AGENT_MODEL` | Model name | `autoglm-phone-9b` |
|
||||
| `PHONE_AGENT_API_KEY` | API key for authentication| `EMPTY` |
|
||||
| `PHONE_AGENT_MAX_STEPS` | Maximum steps per task | `100` |
|
||||
| `PHONE_AGENT_DEVICE_ID` | ADB device ID | (auto-detect) |
|
||||
| `PHONE_AGENT_LANG` | Language (`cn` or `en`) | `cn` |
|
||||
|
||||
21
main.py
21
main.py
@@ -8,6 +8,7 @@ Usage:
|
||||
Environment Variables:
|
||||
PHONE_AGENT_BASE_URL: Model API base URL (default: http://localhost:8000/v1)
|
||||
PHONE_AGENT_MODEL: Model name (default: autoglm-phone-9b)
|
||||
PHONE_AGENT_API_KEY: API key for model authentication (default: EMPTY)
|
||||
PHONE_AGENT_MAX_STEPS: Maximum steps per task (default: 100)
|
||||
PHONE_AGENT_DEVICE_ID: ADB device ID for multi-device setups
|
||||
"""
|
||||
@@ -166,7 +167,7 @@ def check_system_requirements() -> bool:
|
||||
return all_passed
|
||||
|
||||
|
||||
def check_model_api(base_url: str, model_name: str) -> bool:
|
||||
def check_model_api(base_url: str, model_name: str, api_key: str = "EMPTY") -> bool:
|
||||
"""
|
||||
Check if the model API is accessible and the specified model exists.
|
||||
|
||||
@@ -177,6 +178,7 @@ def check_model_api(base_url: str, model_name: str) -> bool:
|
||||
Args:
|
||||
base_url: The API base URL
|
||||
model_name: The model name to check
|
||||
api_key: The API key for authentication
|
||||
|
||||
Returns:
|
||||
True if all checks pass, False otherwise.
|
||||
@@ -193,7 +195,7 @@ def check_model_api(base_url: str, model_name: str) -> bool:
|
||||
parsed = urlparse(base_url)
|
||||
|
||||
# Create OpenAI client
|
||||
client = OpenAI(base_url=base_url, api_key="EMPTY", timeout=10.0)
|
||||
client = OpenAI(base_url=base_url, api_key=api_key, timeout=10.0)
|
||||
|
||||
# Try to list models (this tests connectivity)
|
||||
models_response = client.models.list()
|
||||
@@ -202,6 +204,7 @@ def check_model_api(base_url: str, model_name: str) -> bool:
|
||||
print("✅ OK")
|
||||
|
||||
# Check 2: Model exists
|
||||
'''
|
||||
print(f"2. Checking model '{model_name}'...", end=" ")
|
||||
if model_name in available_models:
|
||||
print("✅ OK")
|
||||
@@ -214,6 +217,7 @@ def check_model_api(base_url: str, model_name: str) -> bool:
|
||||
if len(available_models) > 10:
|
||||
print(f" ... and {len(available_models) - 10} more")
|
||||
all_passed = False
|
||||
'''
|
||||
|
||||
except Exception as e:
|
||||
print("❌ FAILED")
|
||||
@@ -267,6 +271,9 @@ Examples:
|
||||
# Specify model endpoint
|
||||
python main.py --base-url http://localhost:8000/v1
|
||||
|
||||
# Use API key for authentication
|
||||
python main.py --apikey sk-xxxxx
|
||||
|
||||
# Run with specific device
|
||||
python main.py --device-id emulator-5554
|
||||
|
||||
@@ -299,6 +306,13 @@ Examples:
|
||||
help="Model name",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--apikey",
|
||||
type=str,
|
||||
default=os.getenv("PHONE_AGENT_API_KEY", "EMPTY"),
|
||||
help="API key for model authentication",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--max-steps",
|
||||
type=int,
|
||||
@@ -462,13 +476,14 @@ def main():
|
||||
sys.exit(1)
|
||||
|
||||
# Check model API connectivity and model availability
|
||||
if not check_model_api(args.base_url, args.model):
|
||||
if not check_model_api(args.base_url, args.model, args.apikey):
|
||||
sys.exit(1)
|
||||
|
||||
# Create configurations
|
||||
model_config = ModelConfig(
|
||||
base_url=args.base_url,
|
||||
model_name=args.model,
|
||||
api_key=args.apikey,
|
||||
)
|
||||
|
||||
agent_config = AgentConfig(
|
||||
|
||||
BIN
resources/screenshot-20251210-120416.png
Normal file
BIN
resources/screenshot-20251210-120416.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 268 KiB |
BIN
resources/screenshot-20251210-120630.png
Normal file
BIN
resources/screenshot-20251210-120630.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 228 KiB |
Reference in New Issue
Block a user