mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-08 09:43:42 +08:00
Merge commit '1c2654320e5b6268b13b6efca40ce37a523d032b'
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Laisky/one-api/common/env"
|
||||
"github.com/songquanpeng/one-api/common/env"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -1,6 +1,7 @@
|
||||
package ctxkey
|
||||
|
||||
const (
|
||||
Config = "config"
|
||||
Id = "id"
|
||||
RequestId = "X-Oneapi-Request-Id"
|
||||
Username = "username"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/Laisky/one-api/common/env"
|
||||
"github.com/songquanpeng/one-api/common/env"
|
||||
)
|
||||
|
||||
var UsingSQLite = false
|
||||
|
||||
@@ -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
5
common/helper/key.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package helper
|
||||
|
||||
const (
|
||||
RequestIdKey = "X-Oneapi-Request-Id"
|
||||
)
|
||||
@@ -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"
|
||||
|
||||
@@ -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]")
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user