From e6195d77dab4c270f03fb5bb7c37de024d3b994c Mon Sep 17 00:00:00 2001 From: juzeon <812312770@qq.com> Date: Tue, 12 Dec 2023 14:11:38 +0800 Subject: [PATCH] fix #142 & add debug mode --- app.go | 3 +-- app_chatbot.go | 8 +++++++- config.go | 10 +++++++--- frontend/src/pages/SettingsPage.vue | 7 ++++++- frontend/wailsjs/go/models.ts | 2 ++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app.go b/app.go index 5a04cf6..c473f8c 100644 --- a/app.go +++ b/app.go @@ -29,14 +29,13 @@ var version string // App struct type App struct { - debug bool settings *Settings ctx context.Context } // NewApp creates a new App application struct func NewApp(settings *Settings) *App { - return &App{debug: false, settings: settings} + return &App{settings: settings} } // startup is called when the app starts. The context is saved diff --git a/app_chatbot.go b/app_chatbot.go index b255af9..24ffde3 100644 --- a/app_chatbot.go +++ b/app_chatbot.go @@ -68,7 +68,7 @@ func (a *App) createSydney() (*sydney.Sydney, error) { return nil, err } return sydney.NewSydney(sydney.Options{ - Debug: a.debug, + Debug: a.settings.config.Debug, Cookies: cookies, Proxy: a.settings.config.Proxy, ConversationStyle: currentWorkspace.ConversationStyle, @@ -241,6 +241,12 @@ func (a *App) askOpenAI(options AskOptions) { handleErr(err) return } + if a.settings.config.Debug { + slog.Info("Received OpenAI delta", "v", response) + } + if len(response.Choices) == 0 { + continue + } textToAppend := response.Choices[0].Delta.Content fullMessage += textToAppend runtime.EventsEmit(a.ctx, EventChatToken, a.CountToken(fullMessage)) diff --git a/config.go b/config.go index bb26065..6cfd36f 100644 --- a/config.go +++ b/config.go @@ -42,6 +42,7 @@ type OpenAIBackend struct { MaxTokens int `json:"max_tokens"` } type Config struct { + Debug bool `json:"debug"` Presets []Preset `json:"presets"` EnterMode string `json:"enter_mode"` Proxy string `json:"proxy"` @@ -214,8 +215,11 @@ func (o *Settings) checkMutex() { util.GracefulPanic(err) } if time.Now().Sub(timeRead) <= 4*time.Second { - dialog.Message("An instance is already running or the lock is not yet released.\n" + - "Please wait up to 4 seconds.").Error() - os.Exit(-1) + _, err = os.ReadFile("wails.json") + if err != nil { // not dev + dialog.Message("An instance is already running or the lock is not yet released.\n" + + "Please wait up to 4 seconds.").Error() + os.Exit(-1) + } } } diff --git a/frontend/src/pages/SettingsPage.vue b/frontend/src/pages/SettingsPage.vue index 39299cf..f380cf3 100644 --- a/frontend/src/pages/SettingsPage.vue +++ b/frontend/src/pages/SettingsPage.vue @@ -45,6 +45,8 @@ function onRevokeReplyCountChanged(v: string) { if (isNaN(i) || i < 0) return config.value.revoke_reply_count = i } + +let developerSettings = ref(false)