V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
RedBeanIce
V2EX  ›  问与答

curl 请求 openai 的本地代理问题

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

    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 好像不行,,奇怪

    ```
    $ 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
    > }'
    bash: curl https://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   ·   实用小工具   ·   1043 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:09 · PVG 04:09 · LAX 12:09 · JFK 15:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.