gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

question about set the HTTP_PROXY for client

Open zjtv opened this issue 1 year ago • 10 comments

hey @eliben:
Due to some reasons, I had to set up an HTTP proxy to access Google's related services. But when run this project, I tried several methods to modify the source code to pass in the proxy, but none of them were successful. Please provide a brief code example to overcome this problem. Thank you!

zjtv avatar Apr 30 '24 08:04 zjtv

I'll take a look at this. Traveling now so it may take a few days

eliben avatar Apr 30 '24 12:04 eliben

There are some example folks used in https://github.com/google/generative-ai-go/issues/17, but you will have to modify the source code. It's not currently supported out of the box.

eliben avatar May 04 '24 13:05 eliben

thx, maybe we can add a api for : https://github.com/google/generative-ai-go/issues/17#issuecomment-1870768732. imo, setting up a proxy is a mandatory option for the regions where it is not convenient to directly access google's services

zjtv avatar May 05 '24 01:05 zjtv

Which proxy are you using?

eliben avatar May 05 '24 01:05 eliben

Which proxy are you using?

I don't know what you meaning about "which proxy"

zjtv avatar May 05 '24 01:05 zjtv

Which proxy are you using?

I don't know what you meaning about "which proxy"

Which proxy server - what is the value of HTTP_PROXY you're setting?

eliben avatar May 05 '24 01:05 eliben

http://127.0.0.1:xyz

zjtv avatar May 05 '24 02:05 zjtv

I've added a --proxy flag in the latest tag (0.5.0)

Please try it and let me know if it works for you

eliben avatar May 06 '24 17:05 eliben

thx, it's work

zjtv avatar May 07 '24 02:05 zjtv

if we can output more error log information for GenerateContentStream likes GenerateContent that would be even better(perhaps this requires modifying the genai).

if stream := mustGetBoolFlag(cmd, "stream"); stream {
		iter := model.GenerateContentStream(ctx, promptParts...)
		for {
			resp, err := iter.Next()
			if err == iterator.Done {
				break
			}
			if err != nil {
				log.Fatal(err) // HERE: 2024/05/07 10:48:39 googleapi: Error 400:
			}
			if len(resp.Candidates) < 1 {
				fmt.Println("<empty response from model>")
			} else {
				c := resp.Candidates[0]
				if c.Content != nil {
					for _, part := range c.Content.Parts {
						fmt.Print(part)
					}
				} else {
					fmt.Println("<empty response from model>")
				}
			}
		}
		fmt.Println()
	} else {
		resp, err := model.GenerateContent(ctx, promptParts...)
		if err != nil {
			log.Fatal(err) //  HERE: 2024/05/07 10:40:26 googleapi: Error 400: User location is not supported for the API use.
		}
		if len(resp.Candidates) < 1 {
			fmt.Println("<empty response from model>")
		} else {
			c := resp.Candidates[0]
			if c.Content != nil {
				for _, part := range c.Content.Parts {
					fmt.Println(part)
				}
			} else {
				fmt.Println("<empty response from model>")
			}
		}
	}

zjtv avatar May 07 '24 02:05 zjtv