Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

fix: can not use without proxy config

沈浩8b6e90de8ece
diff --git a/internal/service/init.go b/internal/service/init.go
index da11b0b5..7b676942 100644
--- a/internal/service/init.go
+++ b/internal/service/init.go
@@ -23,7 +23,7 @@ func NewService() *Service {
switch config.Conf.App.TranscribeProvider {
case "openai":
- transcriber = openai.NewClient(config.Conf.Openai.ApiKey, config.Conf.App.ParsedProxy)
+ transcriber = openai.NewClient(config.Conf.Openai.ApiKey, config.Conf.App.Proxy)
case "aliyun":
transcriber = aliyun.NewClient()
}
@@ -31,14 +31,14 @@ func NewService() *Service {
switch config.Conf.App.LlmProvider {
case "openai":
- chatCompleter = openai.NewClient(config.Conf.Openai.ApiKey, config.Conf.App.ParsedProxy)
+ chatCompleter = openai.NewClient(config.Conf.Openai.ApiKey, config.Conf.App.Proxy)
case "aliyun":
chatCompleter = aliyun.NewChatClient(config.Conf.Aliyun.Bailian.ApiKey)
}
log.GetLogger().Info("当前选择的LLM源: ", zap.String("llm", config.Conf.App.LlmProvider))
return &Service{
- OpenaiClient: openai.NewClient(config.Conf.Openai.ApiKey, config.Conf.App.ParsedProxy),
+ OpenaiClient: openai.NewClient(config.Conf.Openai.ApiKey, config.Conf.App.Proxy),
CosyCloneClient: aliyun.NewClient(),
Transcriber: transcriber,
diff --git a/pkg/openai/init.go b/pkg/openai/init.go
index 8c918066..0865c96c 100644
--- a/pkg/openai/init.go
+++ b/pkg/openai/init.go
@@ -2,20 +2,20 @@ package openai
import (
"github.com/sashabaranov/go-openai"
+ "krillin-ai/config"
"net/http"
- "net/url"
)
type Client struct {
client *openai.Client
}
-func NewClient(apiKey string, proxyUrl *url.URL) *Client {
+func NewClient(apiKey string, proxyAddr string) *Client {
cfg := openai.DefaultConfig(apiKey)
- if proxyUrl != nil {
+ if proxyAddr != "" {
transport := &http.Transport{
- Proxy: http.ProxyURL(proxyUrl),
+ Proxy: http.ProxyURL(config.Conf.App.ParsedProxy),
}
cfg.HTTPClient = &http.Client{
Transport: transport,
diff --git a/pkg/util/base.go b/pkg/util/base.go
index e86fdaa9..06f1cad0 100644
--- a/pkg/util/base.go
+++ b/pkg/util/base.go
@@ -79,16 +79,10 @@ func IsNumber(s string) bool {
// DownloadFile 下载文件并保存到指定路径,支持代理
func DownloadFile(urlStr, filepath, proxyAddr string) error {
- proxyURL, err := url.Parse(proxyAddr)
- if err != nil {
- return err
- }
-
client := &http.Client{}
-
- if proxyURL != nil {
+ if proxyAddr != "" {
client.Transport = &http.Transport{
- Proxy: http.ProxyURL(proxyURL),
+ Proxy: http.ProxyURL(config.Conf.App.ParsedProxy),
}
}