go-openai icon indicating copy to clipboard operation
go-openai copied to clipboard

通过代理调用 报错: malformed HTTP response

Open aehyok opened this issue 2 years ago • 1 comments

image

       config := openai.DefaultConfig(utils.OpenAIAuthToken)
	proxyUrl, err := url.Parse(utils.OpenAIUrl)
	if err != nil {
		panic(err)
	}
	transport := &http.Transport{
		Proxy: http.ProxyURL(proxyUrl),
	}
	config.HTTPClient = &http.Client{
		Transport: transport,
	}

	c := openai.NewClientWithConfig(config)
	ctxx := context.Background()
	req := openai.AudioRequest{
		Model:    openai.Whisper1,
		FilePath: "test.m4a",
	}
	resp, err := c.CreateTranscription(ctxx, req)
	if err != nil {
		fmt.Printf("Transcription error: %v\n", err)
		return dto.SetResponseFailure("error")
	}
	fmt.Println(resp.Text)
	return dto.SetResponseData(resp.Text)

aehyok avatar Mar 10 '23 04:03 aehyok

use like this:

config.BaseURL = "https://service-aaaaa.hk.apigw.tencentcs.com/v1"

A11Might avatar Mar 15 '23 14:03 A11Might

Closing this due to lack of comments for an extended period. Hopefully, the proposed solution has resolved your issue.

vvatanabe avatar Jul 01 '23 21:07 vvatanabe

transport := &http.Transport{ Proxy: http.ProxyURL(proxyUrl), } config.HTTPClient = &http.Client{ Transport: transport, } 注释掉全局代理这段代码

mfkgef avatar May 26 '24 14:05 mfkgef