go-openai
go-openai copied to clipboard
通过代理调用 报错: malformed HTTP response

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)
use like this:
config.BaseURL = "https://service-aaaaa.hk.apigw.tencentcs.com/v1"
Closing this due to lack of comments for an extended period. Hopefully, the proposed solution has resolved your issue.
transport := &http.Transport{ Proxy: http.ProxyURL(proxyUrl), } config.HTTPClient = &http.Client{ Transport: transport, } 注释掉全局代理这段代码