1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-29 23:38:14 +02:00

сделал NewClient_proxy()

This commit is contained in:
Nikitin Aleksandr
2024-06-11 15:46:35 +03:00
parent bf88663d69
commit 2b7af1a4b0
2 changed files with 10 additions and 31 deletions

View File

@@ -38,6 +38,8 @@ CHATGPT_API_KEY=
CHATGPT_NAME= CHATGPT_NAME=
CHATGPT_START_TEXT= CHATGPT_START_TEXT=
CHATGPT_END_TEXT= CHATGPT_END_TEXT=
CHATGPT_PROXY_API_URL=
CHATGPT_PROXY_API_KEY=
EMAIL_SMTP_SERVER="" EMAIL_SMTP_SERVER=""
EMAIL_IMAP_SERVER="" EMAIL_IMAP_SERVER=""

View File

@@ -52,6 +52,13 @@ func Connect() {
} }
// NewClient_proxy creates new OpenAI API client.
func NewClient_proxy(authToken string) *gogpt.Client {
config := gogpt.DefaultConfig(authToken)
config.BaseURL = Settings.CHATGPT_PROXY_API_URL
return gogpt.NewClientWithConfig(config)
}
// Connect_err - подключается к базе данных // Connect_err - подключается к базе данных
func Connect_err() error { func Connect_err() error {
var err error var err error
@@ -61,7 +68,7 @@ func Connect_err() error {
} }
if Settings.CHATGPT_PROXY_API_KEY != "" { if Settings.CHATGPT_PROXY_API_KEY != "" {
Conn = gogpt.NewClient(Settings.CHATGPT_PROXY_API_KEY) Conn = NewClient_proxy(Settings.CHATGPT_PROXY_API_KEY)
} else { } else {
Conn = gogpt.NewClient(Settings.CHATGPT_API_KEY) Conn = gogpt.NewClient(Settings.CHATGPT_API_KEY)
} }
@@ -202,36 +209,6 @@ func SendMessage(Text string, user string) (string, error) {
} else { } else {
err = errors.New("error: no response") err = errors.New("error: no response")
} }
//fmt.Println("Otvet: ", resp.Choices[0].Text)
//req := gogpt.CompletionRequest{
// Model: gogpt.GPT3Ada,
// MaxTokens: 5,
// Prompt: Text,
// Stream: true,
//}
//stream, err := Conn.CreateCompletionStream(ctx, req)
//if err != nil {
// return Otvet, err
//}
//defer stream.Close()
//
//for {
// response, err := stream.Recv()
// Otvet = response
// if errors.Is(err, io.EOF) {
// fmt.Println("Stream finished")
// err = nil
// return Otvet, err
// }
//
// if err != nil {
// fmt.Printf("Stream error: %v\n", err)
// return Otvet, err
// }
//
// fmt.Printf("Stream response: %v\n", response)
//}
return Otvet, err return Otvet, err
} }