代理
按需开启代理,使用反向代理
mitmdump -p 8081 -m reverse:http://x.x.x.x --flow-detail 4
openai命令行安装
pip install -U openai
参数使用
-b 参数后面的url必须要有,不然会报错,做的比较傻
openai -b http://127.0.0.1:8081/chatgpt/v1/ api chat.completions.create -m gpt-4o-mini -g user hello
帮助
(base) hogwarts: ~ seveniruby$ openai --help
usage: openai [-h] [-v] [-b API_BASE] [-k API_KEY] [-p PROXY [PROXY ...]] [-o ORGANIZATION] [-t {openai,azure}]
[--api-version API_VERSION] [--azure-endpoint AZURE_ENDPOINT] [--azure-ad-token AZURE_AD_TOKEN]
[-V]
{api,tools,migrate,grit} ...
positional arguments:
{api,tools,migrate,grit}
api Direct API calls
tools Client side tools for convenience
options:
-h, --help show this help message 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)
-t {openai,azure}, --api-type {openai,azure}
The backend API to call, must be `openai` or `azure`
--api-version API_VERSION
The Azure API version, e.g. 'https://learn.microsoft.com/en-us/azure/ai-
services/openai/reference#rest-api-versioning'
--azure-endpoint AZURE_ENDPOINT
The Azure endpoint, e.g. 'https://endpoint.openai.azure.com'
--azure-ad-token AZURE_AD_TOKEN
A token from Azure Active Directory, https://www.microsoft.com/en-
us/security/business/identity-access/microsoft-entra-id
-V, --version show program's version number and exit
(base) hogwarts: ~ seveniruby$ openai api --help
usage: openai api [-h]
{chat.completions.create,images.generate,images.edit,images.create_variation,audio.transcriptions.create,audio.translations.create,files.create,files.retrieve,files.delete,files.list,models.list,models.retrieve,models.delete,completions.create}
...
positional arguments:
{chat.completions.create,images.generate,images.edit,images.create_variation,audio.transcriptions.create,audio.translations.create,files.create,files.retrieve,files.delete,files.list,models.list,models.retrieve,models.delete,completions.create}
All API subcommands
options:
-h, --help show this help message and exit
(base) hogwarts: ~ seveniruby$ openai api chat.completions.create -h
usage: openai api chat.completions.create [-h] -g ROLE CONTENT -m MODEL [-n N] [-M MAX_TOKENS] [-t TEMPERATURE]
[-P TOP_P] [--stop STOP] [--stream]
required arguments:
-g ROLE CONTENT, --message ROLE CONTENT
A message in `{role} {content}` format. Use this argument multiple times to add multiple
messages.
-m MODEL, --model MODEL
The model to use.
optional arguments:
-n N, --n N How many completions to generate for the conversation.
-M MAX_TOKENS, --max-tokens MAX_TOKENS
The maximum number of tokens to generate.
-t TEMPERATURE, --temperature TEMPERATURE
What sampling temperature to use. Higher values means the model will take more risks. Try
0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined
answer. Mutually exclusive with `top_p`.
-P TOP_P, --top_p TOP_P
An alternative to sampling with temperature, called nucleus sampling, where the considers
the results of the tokens with top_p probability mass. So 0.1 means only the tokens
comprising the top 10% probability mass are considered. Mutually exclusive with
`temperature`.
--stop STOP A stop sequence at which to stop generating tokens for the message.
--stream Stream messages as they're ready.
(base) hogwarts: ~ seveniruby$ openai api images.generate -h
usage: openai api images.generate [-h] [-m MODEL] -p PROMPT [-n NUM_IMAGES] [-s SIZE]
[--response-format RESPONSE_FORMAT]
options:
-h, --help show this help message and exit
-m MODEL, --model MODEL
-p PROMPT, --prompt PROMPT
-n NUM_IMAGES, --num-images NUM_IMAGES
-s SIZE, --size SIZE Size of the output image
--response-format RESPONSE_FORMAT