AgentGPT icon indicating copy to clipboard operation
AgentGPT copied to clipboard

OpenAI API & Serp API fetch does not support proxy server yet for beta 0.4.0

Open yhyu13 opened this issue 2 years ago • 0 comments

⚠️ Please check that this feature request hasn't been suggested before.

  • [X] I searched previous Ideas in Discussions didn't find any similar feature requests.
  • [X] I searched previous Issues didn't find any similar feature requests.

🔖 Feature description

For the beta 0.4.0 release, it seems openai and serp web search do not support proxy anymore. The previous release v0.3 seems fine.

HTTP_PROXY=xxx
HTTPS_PROXY=xxx

✔️ Solution

I am not sure what changes has made to open ai API call.

For Serp.ts, we should be able to fetch through proxy agent like this

async callSerper(input: string) {
  const HttpsProxyAgent = require('https-proxy-agent');
  const proxyAgent = new HttpsProxyAgent('http://your-proxy-server-url.com:port');
  
  const options = {
    method: "POST",
    headers: {
      "X-API-KEY": this.key,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      q: input,
    }),
    agent: proxyAgent,
  };

  const res = await fetch("https://google.serper.dev/search", options);

  if (!res.ok) {
    console.error(`Got ${res.status} error from serper: ${res.statusText}`);
  }

  return res;
}

❓ Alternatives

No response

📝 Additional Context

No response

Acknowledgements

  • [X] My issue title is concise, descriptive, and in title casing.
  • [X] I have searched the existing issues to make sure this feature has not been requested yet.
  • [X] I have provided enough information for the maintainers to understand and evaluate this request.

yhyu13 avatar May 16 '23 13:05 yhyu13