positional arguments: {api,tools,wandb} api Direct API calls tools Client side tools for convenience wandb Logging with Weights & Biases
optional arguments: -h, --help show this help message and exit -V, --version show program's version number and exit -v, --verbose Set verbosity. -b API_BASE, --api-base API_BASE What API base url to use. -k API_KEY, --api-key API_KEY What API key to use. -p PROXY [PROXY ...], --proxy PROXY [PROXY ...] What proxy to use. -o ORGANIZATION, --organization ORGANIZATION Which organization to run as (will use your default organization if not specified)
3.2. Hello world
1 2 3
export OPENAI_API_KEY="sk-xxx"
openai api chat_completions.create -m gpt-3.5-turbo -g user "Hello world"
3.3. 测试OPENAI API是否畅通
1 2 3 4 5
# 测试官方OPENAI API openai api chat_completions.create -m gpt-3.5-turbo -g user "Hello world"
# 测试OPENAI API代理 openai -b "https://api.openai-forward.com/v1" api chat_completions.create -m gpt-3.5-turbo -g user "Hello world"
3.4. 可能的问题
3.4.1. 配置KEY问题
执行openai命令前,需要先配置KEY,否则会报错:
1
Error: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://platform.openai.com/account/api-keys for details.
或者,执行openai命令时,使用参数-k配置KEY。
3.4.2. 网络问题
执行可能会卡住一段时间后报错:
1
[2023-08-05 08:55:26,852] Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f94afde5d30>: Failed to establish a new connection: [Errno 110] Connection timed out')': /v1/chat/completions
也可能会直接报错:
1
Error: Error communicating with OpenAI: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))