Merge commit '1c2654320e5b6268b13b6efca40ce37a523d032b'

This commit is contained in:
Laisky.Cai
2024-04-28 01:53:31 +00:00
162 changed files with 1351 additions and 731 deletions

View File

@@ -10,7 +10,7 @@ import (
"sync"
"time"
"github.com/Laisky/one-api/common/env"
"github.com/songquanpeng/one-api/common/env"
)
func init() {

View File

@@ -1,13 +0,0 @@
package ctxkey
const (
ConfigPrefix = "cfg_"
ConfigAPIVersion = ConfigPrefix + "api_version"
ConfigLibraryID = ConfigPrefix + "library_id"
ConfigPlugin = ConfigPrefix + "plugin"
ConfigSK = ConfigPrefix + "sk"
ConfigAK = ConfigPrefix + "ak"
ConfigRegion = ConfigPrefix + "region"
ConfigUserID = ConfigPrefix + "user_id"
)

View File

@@ -1,6 +1,7 @@
package ctxkey
const (
Config = "config"
Id = "id"
RequestId = "X-Oneapi-Request-Id"
Username = "username"

View File

@@ -1,7 +1,7 @@
package common
import (
"github.com/Laisky/one-api/common/env"
"github.com/songquanpeng/one-api/common/env"
)
var UsingSQLite = false

View File

@@ -10,7 +10,8 @@ import (
"strconv"
"strings"
"github.com/Laisky/one-api/common/random"
"github.com/songquanpeng/one-api/common/random"
"github.com/gin-gonic/gin"
)
func OpenBrowser(url string) {
@@ -106,6 +107,11 @@ func GenRequestID() string {
return GetTimeString() + random.GetRandomNumberString(8)
}
func GetResponseID(c *gin.Context) string {
logID := c.GetString(RequestIdKey)
return fmt.Sprintf("chatcmpl-%s", logID)
}
func Max(a int, b int) int {
if a >= b {
return a

5
common/helper/key.go Normal file
View File

@@ -0,0 +1,5 @@
package helper
const (
RequestIdKey = "X-Oneapi-Request-Id"
)

View File

@@ -12,7 +12,7 @@ import (
"strings"
"testing"
img "github.com/Laisky/one-api/common/image"
img "github.com/songquanpeng/one-api/common/image"
"github.com/stretchr/testify/assert"
_ "golang.org/x/image/webp"

View File

@@ -3,8 +3,8 @@ package common
import (
"flag"
"fmt"
"github.com/Laisky/one-api/common/config"
"github.com/Laisky/one-api/common/logger"
"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/common/logger"
"log"
"os"
"path/filepath"
@@ -20,7 +20,7 @@ var (
func printHelp() {
fmt.Println("One API " + Version + " - All in one API service for OpenAI API.")
fmt.Println("Copyright (C) 2023 JustSong. All rights reserved.")
fmt.Println("GitHub: https://github.com/Laisky/one-api")
fmt.Println("GitHub: https://github.com/songquanpeng/one-api")
fmt.Println("Usage: one-api [--port <port>] [--log-dir <log directory>] [--version] [--help]")
}

View File

@@ -10,9 +10,8 @@ import (
"sync"
"time"
"github.com/Laisky/one-api/common/config"
"github.com/Laisky/one-api/common/ctxkey"
"github.com/Laisky/one-api/common/helper"
"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/common/helper"
"github.com/gin-gonic/gin"
)
@@ -88,7 +87,7 @@ func logHelper(ctx context.Context, level string, msg string) {
if level == loggerINFO {
writer = gin.DefaultWriter
}
id := ctx.Value(ctxkey.RequestId)
id := ctx.Value(helper.RequestIdKey)
if id == nil {
id = helper.GenRequestID()
}

View File

@@ -10,7 +10,7 @@ import (
"time"
"github.com/Laisky/errors/v2"
"github.com/Laisky/one-api/common/config"
"github.com/songquanpeng/one-api/common/config"
)
func SendEmail(subject string, receiver string, content string) error {

View File

@@ -2,7 +2,7 @@ package message
import (
"github.com/Laisky/errors/v2"
"github.com/Laisky/one-api/common/config"
"github.com/songquanpeng/one-api/common/config"
)
const (

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"github.com/Laisky/errors/v2"
"github.com/Laisky/one-api/common/config"
"github.com/songquanpeng/one-api/common/config"
"net/http"
)

View File

@@ -3,7 +3,7 @@ package network
import (
"context"
"fmt"
"github.com/Laisky/one-api/common/logger"
"github.com/songquanpeng/one-api/common/logger"
"net"
"strings"
)

View File

@@ -2,7 +2,7 @@ package common
import (
"context"
"github.com/Laisky/one-api/common/logger"
"github.com/songquanpeng/one-api/common/logger"
"github.com/go-redis/redis/v8"
"os"
"time"

View File

@@ -2,7 +2,7 @@ package common
import (
"fmt"
"github.com/Laisky/one-api/common/config"
"github.com/songquanpeng/one-api/common/config"
)
func LogQuota(quota int64) string {