Skip to content

Commit

Permalink
Merge pull request #5 from go-zoox/bug/fix-env-chatgpt-language-does-…
Browse files Browse the repository at this point in the history
…not-work

fix: env CHATGPT_LANGUAGE does not work
  • Loading branch information
whatwewant authored Mar 10, 2023
2 parents 8bff62e + 5606eb2 commit a04eeba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ const DefaultMaxConversations = 10000
// default: 30 day
const DefaultConversationMaxAge = 30 * 24 * time.Hour

// DefaultContextIntl is the default context for instructions to ChatGPT.
var DefaultContextIntl = map[string]string{
"EN_US": "Instructions:\nYou are {{.chatgpt_name}}, a large language model trained by OpenAI.\nCurrent date: {{.date}}",
"ZH_CN": "引导:\n你是 {{.chatgpt_name}},一个由 OpenAI 训练的大语言模型。\n当前日期: {{.date}}",
}

// DefaultContext is the default context for instructions to ChatGPT.
const DefaultContext = "Instructions:\nYou are {{.chatgpt_name}}, a large language model trained by OpenAI.\nCurrent date: {{.date}}"
var DefaultContext = DefaultContextIntl["EN_US"]
11 changes: 11 additions & 0 deletions conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/go-zoox/core-utils/safe"
"github.com/go-zoox/core-utils/strings"
"github.com/go-zoox/logger"
"github.com/go-zoox/uuid"
)
Expand Down Expand Up @@ -53,6 +54,16 @@ func NewConversation(client *client, cfg *ConversationConfig) (Conversation, err
if cfg.ID == "" {
cfg.ID = uuid.V4()
}

// ensure language
if cfg.Language != "" {
cfg.Language = strings.ToUpper(cfg.Language)
// @TODO
if vc, ok := DefaultContextIntl[cfg.Language]; ok {
DefaultContext = vc
}
}

if cfg.Context == "" {
cfg.Context = DefaultContext
if cfg.Language != "" {
Expand Down

0 comments on commit a04eeba

Please sign in to comment.