mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-12-25 01:25:59 +08:00
重构主体工作完成
This commit is contained in:
@@ -88,7 +88,7 @@ type apiErrRes struct {
|
||||
} `json:"error"`
|
||||
}
|
||||
|
||||
func OpenAIRequest(db *gorm.DB, prompt string, proxy string) (string, error) {
|
||||
func OpenAIRequest(db *gorm.DB, prompt string) (string, error) {
|
||||
var apiKey model.ApiKey
|
||||
res := db.Where("platform = ?", types.OpenAI).Where("type = ?", "chat").Where("enabled = ?", true).First(&apiKey)
|
||||
if res.Error != nil {
|
||||
@@ -104,8 +104,8 @@ func OpenAIRequest(db *gorm.DB, prompt string, proxy string) (string, error) {
|
||||
var response apiRes
|
||||
var errRes apiErrRes
|
||||
client := req.C()
|
||||
if apiKey.UseProxy && proxy != "" {
|
||||
client.SetProxyURL(proxy)
|
||||
if apiKey.ProxyURL != "" {
|
||||
client.SetProxyURL(apiKey.ApiURL)
|
||||
}
|
||||
r, err := client.R().SetHeader("Content-Type", "application/json").
|
||||
SetHeader("Authorization", "Bearer "+apiKey.Value).
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/sha3"
|
||||
@@ -59,7 +60,7 @@ func Str2stamp(str string) int64 {
|
||||
if len(str) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
layout := "2006-01-02 15:04:05"
|
||||
t, err := time.Parse(layout, str)
|
||||
if err != nil {
|
||||
@@ -92,3 +93,11 @@ func InterfaceToString(value interface{}) string {
|
||||
}
|
||||
return JsonEncode(value)
|
||||
}
|
||||
|
||||
func Str2Float(str string) float64 {
|
||||
num, err := strconv.ParseFloat(str, 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user