curl 请求 openai 的本地代理问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
RedBeanIce
V2EX    问与答

curl 请求 openai 的本地代理问题

  •  
  •   RedBeanIce 2023-03-31 11:54:08 +08:00 2308 次点击
    这是一个创建于 927 天前的主题,其中的信息可能已经有所发展或是发生改变。

    request

    curl https://api.openai.com/v1/chat/completions \ -X POST \ -H "Content-Type: application/json" \ --proxy-pass "127.0.0.1:7890" "https://api.openai.com" \ -H "Authorization: Bearer {your key}" \ -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7 }' 

    response

    $ curl https://api.openai.com/v1/chat/completions \ > -X POST \ > -H "Content-Type: application/json" \ > --proxy-pass "127.0.0.1:7890" "https://api.openai.com" \ > -H "Authorization: Bearer {your key}" \ > -d '{ > "model": "gpt-3.5-turbo", > "messages": [{"role": "user", "content": "Say this is a test!"}], > "temperature": 0.7 > }' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:21 --:--:-- 0 curl: (28) Failed to connect to api.openai.com port 443 after 21051 ms: Timed out curl: (3) URL using bad/illegal format or missing URL % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:21 --:--:-- 0 curl: (28) Failed to connect to api.openai.com port 443 after 21041 ms: Timed out curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL 

    我本地在使用 clash for windows ,链接的是新加坡节点。

    请问我应该如何做,才能够在本地可以正常的请求呢。

    6 条回复    2023-03-31 13:19:49 +08:00
    sillydaddy
        1
    sillydaddy  
       2023-03-31 12:25:39 +08:00
    直接改成
    curl https://api.openai.com/v1/chat/completions \
    -X POST \
    -H "Content-Type: application/json" \
    --proxy "127.0.0.1:7890"
    -H "Authorization: Bearer {your key}" \
    -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Say this is a test!"}],
    "temperature": 0.7
    }'
    呢。你的本地代理还需要用户名密码吗?我试了一下我的可以成功。我用的 shadowsocks ,不知道 clash 是怎么开的代理。
    maltoze
        2
    maltoze  
       2023-03-31 12:35:27 +08:00
    ```bash
    https_proxy=http://127.0.0.1:7890 curl https://api.openai.com/v1/chat/completions \
    -X POST \
    -H "Content-Type: application/json" \
    --proxy-pass "127.0.0.1:7890" "https://api.openai.com" \
    -H "Authorization: Bearer {your key}" \
    -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Say this is a test!"}],
    "temperature": 0.7
    }'
    ```
    RedBeanIce
        3
    RedBeanIce  
    OP
       2023-03-31 12:43:04 +08:00
    @sillydaddy 好像不行,,奇怪

    ```
    $ curlhttps://api.openai.com/v1/chat/completions\
    > -X POST \
    > -H "Content-Type: application/json" \
    > --proxy "127.0.0.1:7890" \
    > -H "Authorization: Bearer {your key}" \
    > -d '{
    > "model": "gpt-3.5-turbo",
    > "messages": [{"role": "user", "content": "Say this is a test!"}],
    > "temperature": 0.7
    > }'
    bash: curlhttps://api.openai.com/v1/chat/completions-X: No such file or directory


    ```
    RedBeanIce
        4
    RedBeanIce  
    OP
       2023-03-31 12:44:15 +08:00
    @maltoze

    ```
    $ https_proxy=http://127.0.0.1:7890 curl openapi 的地址 \
    > --X POST \
    > -H "Content-Type: application/json" \
    > --proxy-pass "127.0.0.1:7890" "openai 的地址" \
    > -H "Authorization: Bearer {your key}" \
    > -d '{
    > "model": "gpt-3.5-turbo",
    > "messages": [{"role": "user", "content": "Say this is a test!"}],
    > "temperature": 0.7
    > }'
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 414 100 300 100 114 64 24 0:00:04 0:00:04 --:--:-- 89{"id":"chatcmpl-700qIbFXszd2jF1O9EOaqaStAYRlx","object":"chat.completion","created":1680237594,"model":"gpt-3.5-turbo-0301","usage":{"prompt_tokens":14,"completion_tokens":5,"total_tokens":19},"choices":[{"message":{"role":"assistant","content":"This is a test!"},"finish_reason":"stop","index":0}]}

    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 247 100 133 100 114 76 65 0:00:01 0:00:01 --:--:-- 142{
    "error": {
    "message": "Invalid URL (POST /)",
    "type": "invalid_request_error",
    "param": null,
    "code": null
    }
    }


    ```

    好像可以!!!!感谢。。。。。

    虽然第二个失败了
    RedBeanIce
        5
    RedBeanIce  
    OP
       2023-03-31 13:10:30 +08:00
    https_proxy=http://127.0.0.1:7890 curl --raw -----/v1/chat/completions \
    -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer {your key}" \
    -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "how match now date"}],
    "temperature": 0.7
    }'

    这样子就 ok 了。请将---替换一下。
    RedBeanIce
        6
    RedBeanIce  
    OP
       2023-03-31 13:19:49 +08:00
    @sillydaddy 发现了,。是我的问题。。是可以的。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2705 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 15:15 PVG 23:15 LAX 08:15 JFK 11:15
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86