|
|
|
@ -329,7 +329,9 @@ func completions(c *gin.Context) {
|
|
|
|
if err == io.EOF {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
log.Printf("httpError1 %v", err.Error())
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
//return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var chatResponse ChatResponse
|
|
|
|
var chatResponse ChatResponse
|
|
|
|
//去除回应中的data:前缀
|
|
|
|
//去除回应中的data:前缀
|
|
|
|
@ -345,6 +347,7 @@ func completions(c *gin.Context) {
|
|
|
|
// 写回数据
|
|
|
|
// 写回数据
|
|
|
|
_, err = c.Writer.Write([]byte(string(chunk) + "\n"))
|
|
|
|
_, err = c.Writer.Write([]byte(string(chunk) + "\n"))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Printf("httpError2 %v", err.Error())
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Writer.(http.Flusher).Flush()
|
|
|
|
c.Writer.(http.Flusher).Flush()
|
|
|
|
@ -390,7 +393,7 @@ func completions(c *gin.Context) {
|
|
|
|
func handleGetModels(c *gin.Context) {
|
|
|
|
func handleGetModels(c *gin.Context) {
|
|
|
|
// BUGFIX: fix options request, see https://github.com/diemus/azure-openai-proxy/issues/3
|
|
|
|
// BUGFIX: fix options request, see https://github.com/diemus/azure-openai-proxy/issues/3
|
|
|
|
//models := []string{"gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301", "text-davinci-003", "text-embedding-ada-002"}
|
|
|
|
//models := []string{"gpt-4", "gpt-4-0314", "gpt-4-32k", "gpt-4-32k-0314", "gpt-3.5-turbo", "gpt-3.5-turbo-0301", "text-davinci-003", "text-embedding-ada-002"}
|
|
|
|
models := []string{"gpt-3.5-turbo", "gpt-3.5-turbo-0301"}
|
|
|
|
models := []string{"gpt-3.5-turbo", "gpt-3.5-turbo-0301", "text-davinci-003", "text-embedding-ada-002"}
|
|
|
|
result := ListModelResponse{
|
|
|
|
result := ListModelResponse{
|
|
|
|
Object: "list",
|
|
|
|
Object: "list",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -501,57 +504,57 @@ func main() {
|
|
|
|
Redis = InitRedis()
|
|
|
|
Redis = InitRedis()
|
|
|
|
|
|
|
|
|
|
|
|
//添加reids测试数据
|
|
|
|
//添加reids测试数据
|
|
|
|
var serverInfo ServerInfo = ServerInfo{
|
|
|
|
// var serverInfo ServerInfo = ServerInfo{
|
|
|
|
ServerAddress: "https://gptp.any-door.cn",
|
|
|
|
// ServerAddress: "https://gptp.any-door.cn",
|
|
|
|
AvailableKey: "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,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,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",
|
|
|
|
// AvailableKey: "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,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,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",
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
var serverInfo2 ServerInfo = ServerInfo{
|
|
|
|
// var serverInfo2 ServerInfo = ServerInfo{
|
|
|
|
ServerAddress: "https://azure.any-door.cn",
|
|
|
|
// ServerAddress: "https://azure.any-door.cn",
|
|
|
|
AvailableKey: "6c4d2c65970b40e482e7cd27adb0d119",
|
|
|
|
// AvailableKey: "6c4d2c65970b40e482e7cd27adb0d119",
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
serverInfoStr, _ := json.Marshal(&serverInfo)
|
|
|
|
// serverInfoStr, _ := json.Marshal(&serverInfo)
|
|
|
|
serverInfoStr2, _ := json.Marshal(&serverInfo2)
|
|
|
|
// serverInfoStr2, _ := json.Marshal(&serverInfo2)
|
|
|
|
Redis.Set(context.Background(), "server:1", serverInfoStr, 0)
|
|
|
|
// Redis.Set(context.Background(), "server:1", serverInfoStr, 0)
|
|
|
|
Redis.Set(context.Background(), "server:2", serverInfoStr2, 0)
|
|
|
|
// Redis.Set(context.Background(), "server:2", serverInfoStr2, 0)
|
|
|
|
|
|
|
|
|
|
|
|
var modelInfo ModelInfo = ModelInfo{
|
|
|
|
// var modelInfo ModelInfo = ModelInfo{
|
|
|
|
ModelName: "gpt-3.5-turbo",
|
|
|
|
// ModelName: "gpt-3.5-turbo",
|
|
|
|
ModelPrice: 0.0001,
|
|
|
|
// ModelPrice: 0.0001,
|
|
|
|
ModelPrepayment: 4000,
|
|
|
|
// ModelPrepayment: 4000,
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
modelInfoStr, _ := json.Marshal(&modelInfo)
|
|
|
|
// modelInfoStr, _ := json.Marshal(&modelInfo)
|
|
|
|
var modelInfo2 ModelInfo = ModelInfo{
|
|
|
|
// var modelInfo2 ModelInfo = ModelInfo{
|
|
|
|
ModelName: "text-davinci-003",
|
|
|
|
// ModelName: "text-davinci-003",
|
|
|
|
ModelPrice: 0.001,
|
|
|
|
// ModelPrice: 0.001,
|
|
|
|
ModelPrepayment: 4000,
|
|
|
|
// ModelPrepayment: 4000,
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
modelInfoStr2, _ := json.Marshal(&modelInfo2)
|
|
|
|
// modelInfoStr2, _ := json.Marshal(&modelInfo2)
|
|
|
|
var modelInfo3 ModelInfo = ModelInfo{
|
|
|
|
// var modelInfo3 ModelInfo = ModelInfo{
|
|
|
|
ModelName: "text-davinci-003",
|
|
|
|
// ModelName: "text-davinci-003",
|
|
|
|
ModelPrice: 0.001,
|
|
|
|
// ModelPrice: 0.001,
|
|
|
|
ModelPrepayment: 4000,
|
|
|
|
// ModelPrepayment: 4000,
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
modelInfoStr3, _ := json.Marshal(&modelInfo3)
|
|
|
|
// modelInfoStr3, _ := json.Marshal(&modelInfo3)
|
|
|
|
Redis.Set(context.Background(), "model:gpt-3.5-turbo", modelInfoStr, 0)
|
|
|
|
// Redis.Set(context.Background(), "model:gpt-3.5-turbo", modelInfoStr, 0)
|
|
|
|
Redis.Set(context.Background(), "model:gpt-3.5-turbo-0301", modelInfoStr, 0)
|
|
|
|
// Redis.Set(context.Background(), "model:gpt-3.5-turbo-0301", modelInfoStr, 0)
|
|
|
|
Redis.Set(context.Background(), "model:text-davinci-003", modelInfoStr2, 0)
|
|
|
|
// Redis.Set(context.Background(), "model:text-davinci-003", modelInfoStr2, 0)
|
|
|
|
Redis.Set(context.Background(), "model:text-embedding-ada-002", modelInfoStr3, 0)
|
|
|
|
// Redis.Set(context.Background(), "model:text-embedding-ada-002", modelInfoStr3, 0)
|
|
|
|
|
|
|
|
|
|
|
|
var userInfo UserInfo = UserInfo{
|
|
|
|
// var userInfo UserInfo = UserInfo{
|
|
|
|
UID: "1",
|
|
|
|
// UID: "1",
|
|
|
|
SID: "1",
|
|
|
|
// SID: "1",
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
var userInfo2 UserInfo = UserInfo{
|
|
|
|
// var userInfo2 UserInfo = UserInfo{
|
|
|
|
UID: "2",
|
|
|
|
// UID: "2",
|
|
|
|
SID: "2",
|
|
|
|
// SID: "2",
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
userInfoStr, _ := json.Marshal(&userInfo)
|
|
|
|
// userInfoStr, _ := json.Marshal(&userInfo)
|
|
|
|
userInfoStr2, _ := json.Marshal(&userInfo2)
|
|
|
|
// userInfoStr2, _ := json.Marshal(&userInfo2)
|
|
|
|
Redis.Set(context.Background(), "user:8aeb3747-715c-48e8-8b80-aec815949f22", userInfoStr, 0)
|
|
|
|
// Redis.Set(context.Background(), "user:8aeb3747-715c-48e8-8b80-aec815949f22", userInfoStr, 0)
|
|
|
|
Redis.Set(context.Background(), "user:key2", userInfoStr2, 0)
|
|
|
|
// Redis.Set(context.Background(), "user:AK-7d8ab782-a152-4cc1-9972-568713465c96", userInfoStr2, 0)
|
|
|
|
|
|
|
|
|
|
|
|
Redis.IncrByFloat(context.Background(), "user:1:balance", 1000).Result()
|
|
|
|
// Redis.IncrByFloat(context.Background(), "user:1:balance", 1000).Result()
|
|
|
|
Redis.IncrByFloat(context.Background(), "user:2:balance", 1000).Result()
|
|
|
|
// Redis.IncrByFloat(context.Background(), "user:2:balance", 1000).Result()
|
|
|
|
|
|
|
|
|
|
|
|
//r.Run("127.0.0.1:8080")
|
|
|
|
//r.Run("127.0.0.1:8080")
|
|
|
|
//docker下使用
|
|
|
|
//docker下使用
|
|
|
|
|