/ pkg / whisper / init.go
init.go
 1  package whisper
 2  
 3  import (
 4  	"github.com/sashabaranov/go-openai"
 5  	"krillin-ai/config"
 6  	"net/http"
 7  )
 8  
 9  type Client struct {
10  	client *openai.Client
11  }
12  
13  func NewClient(baseUrl, apiKey, proxyAddr string) *Client {
14  	cfg := openai.DefaultConfig(apiKey)
15  	if baseUrl != "" {
16  		cfg.BaseURL = baseUrl
17  	}
18  
19  	if proxyAddr != "" {
20  		transport := &http.Transport{
21  			Proxy: http.ProxyURL(config.Conf.App.ParsedProxy),
22  		}
23  		cfg.HTTPClient = &http.Client{
24  			Transport: transport,
25  		}
26  	}
27  
28  	client := openai.NewClientWithConfig(cfg)
29  	return &Client{client: client}
30  }