Skip to content

Commit

Permalink
add independent channel
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Oct 30, 2023
1 parent ebc5edc commit 60e096f
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 45 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ openai:
endpoint: https://api.openai.com
apikey: sk-...|sk-...

reverse:
endpoint: .../imitate
hash: gpt-4-... # reverse model hash
apikey: ...

slack:
bot_id: ...
token: ...
Expand Down
16 changes: 8 additions & 8 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ import (
)

type ChatProps struct {
Model string
Reversible bool
Infinity bool
Message []globals.Message
Token int
Model string
Plan bool
Infinity bool
Message []globals.Message
Token int
}

func NewChatRequest(props *ChatProps, hook globals.Hook) error {
if globals.IsChatGPTModel(props.Model) {
instance := chatgpt.NewChatInstanceFromModel(&chatgpt.InstanceProps{
Model: props.Model,
Reversible: props.Reversible,
Model: props.Model,
Plan: props.Plan,
})
return instance.CreateStreamChatRequest(&chatgpt.ChatProps{
Model: props.Model,
Message: props.Message,
Token: utils.Multi(
props.Token == 0,
utils.Multi(globals.IsGPT4Model(props.Model) || props.Infinity, -1, 2000),
utils.Multi(globals.IsGPT4Model(props.Model) || props.Plan || props.Infinity, -1, 2000),
props.Token,
),
}, hook)
Expand Down
18 changes: 10 additions & 8 deletions adapter/chatgpt/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type ChatInstance struct {
}

type InstanceProps struct {
Model string
Reversible bool
Model string
Plan bool
}

func (c *ChatInstance) GetEndpoint() string {
Expand Down Expand Up @@ -51,20 +51,22 @@ func NewChatInstanceFromModel(props *InstanceProps) *ChatInstance {
case globals.GPT4,
globals.GPT40314,
globals.GPT40613:
if props.Reversible {
return NewChatInstanceFromConfig("reverse")
} else {
return NewChatInstanceFromConfig("gpt4")
}
return NewChatInstanceFromConfig("gpt4")

case globals.GPT432k,
globals.GPT432k0613,
globals.GPT432k0314:
return NewChatInstanceFromConfig("gpt4")

case globals.GPT3Turbo16k,
case globals.GPT3Turbo,
globals.GPT3Turbo0613,
globals.GPT3Turbo0301,
globals.GPT3Turbo16k,
globals.GPT3Turbo16k0301,
globals.GPT3Turbo16k0613:
if props.Plan {
return NewChatInstanceFromConfig("subscribe")
}
return NewChatInstanceFromConfig("gpt3")
default:
return NewChatInstanceFromConfig("gpt3")
Expand Down
8 changes: 4 additions & 4 deletions addition/generation/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func CreateGeneration(model string, prompt string, path string, plan bool, hook
buffer := utils.NewBuffer(model, message)

if err := adapter.NewChatRequest(&adapter.ChatProps{
Model: model,
Message: message,
Reversible: plan,
Infinity: true,
Model: model,
Message: message,
Plan: plan,
Infinity: true,
}, func(data string) error {
buffer.Write(data)
hook(buffer, data)
Expand Down
9 changes: 9 additions & 0 deletions app/src/components/home/ModelSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ function ModelSelector(props: ModelSelectorProps) {
} as SelectItemProps;
}

const channel = ["gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613"];
if (subscription && channel.includes(model.id)) {
return {
name: model.id,
value: model.name,
badge: { variant: "gold", name: "pro" },
} as SelectItemProps;
}

return {
name: model.id,
value: model.name,
Expand Down
2 changes: 1 addition & 1 deletion app/src/conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@/utils/env.ts";
import { getMemory } from "@/utils/memory.ts";

export const version = "3.6.1";
export const version = "3.6.2";
export const dev: boolean = getDev();
export const deploy: boolean = true;
export let rest_api: string = getRestApi(deploy);
Expand Down
4 changes: 4 additions & 0 deletions auth/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func CanEnableModel(db *sql.DB, user *User, model string) bool {

func HandleSubscriptionUsage(db *sql.DB, cache *redis.Client, user *User, model string) bool {
subscription := user.IsSubscribe(db)
if globals.IsGPT3TurboModel(model) {
// independent channel for subscription users
return subscription
}
if globals.IsGPT4NativeModel(model) {
return subscription && IncreaseSubscriptionUsage(cache, user, globals.GPT4, 50)
} else if model == globals.Claude2100k {
Expand Down
5 changes: 0 additions & 5 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ openai:
endpoint: https://api.openai.com
apikey: sk-...|sk-...

reverse:
endpoint: .../imitate
hash: gpt-4-... # reverse model hash
apikey: ...

slack:
bot_id: ...
token: ...
Expand Down
6 changes: 3 additions & 3 deletions manager/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func ChatHandler(conn *Connection, user *auth.User, instance *conversation.Conve

buffer := utils.NewBuffer(model, segment)
err := adapter.NewChatRequest(&adapter.ChatProps{
Model: model,
Message: segment,
Reversible: plan,
Model: model,
Message: segment,
Plan: plan,
}, func(data string) error {
if signal := conn.PeekWithType(StopType); signal != nil {
// stop signal from client
Expand Down
6 changes: 3 additions & 3 deletions manager/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func NativeChatHandler(c *gin.Context, user *auth.User, model string, message []

buffer := utils.NewBuffer(model, segment)
if err := adapter.NewChatRequest(&adapter.ChatProps{
Model: model,
Reversible: plan,
Message: segment,
Model: model,
Plan: plan,
Message: segment,
}, func(resp string) error {
buffer.Write(resp)
return nil
Expand Down
16 changes: 8 additions & 8 deletions manager/transhipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func TranshipmentAPI(c *gin.Context) {
func sendTranshipmentResponse(c *gin.Context, form TranshipmentForm, id string, created int64, user *auth.User, plan bool) {
buffer := utils.NewBuffer(form.Model, form.Messages)
err := adapter.NewChatRequest(&adapter.ChatProps{
Model: form.Model,
Message: form.Messages,
Reversible: plan,
Token: form.MaxTokens,
Model: form.Model,
Message: form.Messages,
Plan: plan,
Token: form.MaxTokens,
}, func(data string) error {
buffer.Write(data)
return nil
Expand Down Expand Up @@ -177,10 +177,10 @@ func sendStreamTranshipmentResponse(c *gin.Context, form TranshipmentForm, id st
go func() {
buffer := utils.NewBuffer(form.Model, form.Messages)
if err := adapter.NewChatRequest(&adapter.ChatProps{
Model: form.Model,
Message: form.Messages,
Reversible: plan,
Token: form.MaxTokens,
Model: form.Model,
Message: form.Messages,
Plan: plan,
Token: form.MaxTokens,
}, func(data string) error {
channel <- getStreamTranshipmentForm(id, created, form, buffer.Write(data), buffer, false)
return nil
Expand Down

0 comments on commit 60e096f

Please sign in to comment.