curl 请求 openai 的本地代理问题

2023-03-31 11:54:08 +08:00
 RedBeanIce

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 ,链接的是新加坡节点。

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

1597 次点击
所在节点    问与答
6 条回复
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
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
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
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
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
2023-03-31 13:19:49 +08:00
@sillydaddy 发现了,。是我的问题。。是可以的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/928720

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX