langchaingo icon indicating copy to clipboard operation
langchaingo copied to clipboard

Post "https://api.openai.com/v1/chat/completions": dial tcp 31.13.75.12:443: i/o timeout

Open timeisgoing opened this issue 2 years ago • 1 comments

Post "https://api.openai.com/v1/chat/completions": dial tcp 31.13.75.12:443: i/o timeout

这个啥情况,我本地已经科学上网了

timeisgoing avatar Jan 25 '24 04:01 timeisgoing


func main() {

	// set proxy 
	proxyUrl, err := url.Parse("http://127.0.0.1:7890")
	if err != nil {
		log.Fatalf("proxy url error %v\n", err)
	}

	httpClient := &http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyURL(proxyUrl),
		},
	}

	ctx := context.Background()
	llm, err := openai.New(openai.WithHTTPClient(httpClient))
	if err != nil {
		panic(err)
	}
	prompt := "What would be a good company name for a company that makes colorful socks?"
	completion, err := llms.GenerateFromSinglePrompt(ctx, llm, prompt)
	if err != nil {
		panic(err)
	}
	fmt.Println(completion)
}

This code works.

proaholic avatar Mar 11 '24 06:03 proaholic