Skip to content

Commit

Permalink
fix #142 & add debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
juzeon committed Dec 12, 2023
1 parent 739cfe4 commit e6195d7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
3 changes: 1 addition & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion app_chatbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 7 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
}
}
7 changes: 6 additions & 1 deletion frontend/src/pages/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function onRevokeReplyCountChanged(v: string) {
if (isNaN(i) || i < 0) return
config.value.revoke_reply_count = i
}
let developerSettings = ref(false)
</script>

<template>
Expand All @@ -60,10 +62,13 @@ function onRevokeReplyCountChanged(v: string) {
<template #default>
<div v-if="!loading" class="fill-height overflow-y-auto">
<v-container class="d-flex flex-column">
<p class="text-h4 mb-3">Settings</p>
<p class="text-h4 mb-3" @dblclick="developerSettings=true">Settings</p>
<v-card title="Application" class="my-3">
<v-card-text>
<update-card></update-card>
<div v-if="developerSettings">
<v-switch v-model="config.debug" label="Debug Mode" color="primary"></v-switch>
</div>
</v-card-text>
</v-card>
<v-card title="Network" class="my-3">
Expand Down
2 changes: 2 additions & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export namespace main {
}
}
export class Config {
debug: boolean;
presets: Preset[];
enter_mode: string;
proxy: string;
Expand Down Expand Up @@ -181,6 +182,7 @@ export namespace main {

constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.debug = source["debug"];
this.presets = this.convertValues(source["presets"], Preset);
this.enter_mode = source["enter_mode"];
this.proxy = source["proxy"];
Expand Down

0 comments on commit e6195d7

Please sign in to comment.