anse-app / chatgpt-demo

Minimal web UI for ChatGPT.
https://chatgpt.ddiu.me
MIT License
8.01k stars 3.8k forks source link

fetch failed when run program #390

Open cailei0596 opened 1 year ago

cailei0596 commented 1 year ago

ubuntu22

leo@leo-virtual-machine:~/chatgpt-demo$ node -v v20.0.0 leo@leo-virtual-machine:~/chatgpt-demo$ npm -v 9.6.4

确认不是网络问题,用代理和不用代理都试过了

chatgpt-api-demo@0.0.1 dev /home/leo/chatgpt-demo

astro dev

🚀 astro v2.1.3 started in 429ms

┃ Local http://localhost:3000/ ┃ Network use --host to expose

fetch failed (https://esm.sh/@iconify-json/ph/icons.json) error fetch failed (https://esm.sh/@iconify-json/ph/icons.json) File: /home/leo/chatgpt-demo/node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/shared/ofetch.f223b849.cjs:182:24 Code: 181 | }

182 | context.response = await fetch( | ^ 183 | context.request, 184 | context.options 185 | ).catch(async (error) => { Stacktrace: FetchError: fetch failed (https://esm.sh/@iconify-json/ph/icons.json) at async $fetchRaw2 (/home/leo/chatgpt-demo/node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/shared/ofetch.f223b849.cjs:182:24)

error fetch failed (https://esm.sh/@iconify-json/ph/icons.json) File: /home/leo/chatgpt-demo/node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/shared/ofetch.f223b849.cjs:182:24 Code: 181 | }

182 | context.response = await fetch( | ^ 183 | context.request, 184 | context.options 185 | ).catch(async (error) => { Stacktrace: FetchError: fetch failed (https://esm.sh/@iconify-json/ph/icons.json) at async $fetchRaw2 (/home/leo/chatgpt-demo/node_modules/.pnpm/ofetch@1.0.1/node_modules/ofetch/dist/shared/ofetch.f223b849.cjs:182:24) (x2) ^C ELIFECYCLE  Command failed.

ddiu8081 commented 1 year ago

The network request is initiated in the node layer and not in the browser, make sure you have a proxy enabled for node? (e.g. TUN mode for proxy software, or enable terminal proxy).

One way to verify this is to run ping api.openai.com in the terminal to see if the proxy is set up correctly.

ladypiapia commented 1 year ago

I have encountered the same problem when deploying with Docker ,"fetch failed",I know it’s probably because of proxy. my trojan config.json on my server like this:

    "run_type": "client",
    "local_addr": "0.0.0.0",
    "local_port": 1080,
    "remote_addr": "61.172.229.205",
    "remote_port": 28101,
    "password": [
        "edfdfaad"
    ]

my docker-compose.yml like this:

version: '3'

services:
  chatgpt-demo:
    image: ddiu8081/chatgpt-demo:latest
    container_name: chatgpt-demo
    restart: always
    ports:
      - '8000:3000'
    environment:
      - OPENAI_API_KEY=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
      - HTTP_PROXY=http://127.0.0.1:1080

I use proxychains when I run proxychains ping api.openai.comin the terminal ,I get wrong response.But in my other app on my server, I can use openai api normally and proxychains curl api.openai.com command also gets right response .Anithing wrong in my config.json or docker-compose.yml ? Every thing is fine when running this project on my Mac with Docker Desktop,while on my CentOS server is invalid.Please give me some advice,thanks so much ! @ddiu8081

xyxbc-git commented 1 year ago

遇到了同样的问题 ,无法解决

chenyhd commented 1 year ago

@cailei0596 @ladypiapia @xyxbc-git
If you are running the app on your host machine, try using the curl command to access api.open.com and ensure that the network is functioning properly.

If you are running the app on Docker, make sure to configure the proxy settings for Docker. Login to docker and curl api.open.com make sure your setting is correct.

DylanWyc1 commented 1 year ago

I can ping the api.openai.com well. But still got this error, any thoughts or solutions?

PHIKN1GHT commented 1 year ago

Replace

cdn: 'https://esm.sh/',

in unocss.config.ts with

cdn: 'http://esm.sh/',

can solve this error in my case.