Skip to content

Commit

Permalink
refactor structure
Browse files Browse the repository at this point in the history
  • Loading branch information
juzeon committed Nov 21, 2023
1 parent 7f7a0e0 commit a84aa60
Show file tree
Hide file tree
Showing 11 changed files with 609 additions and 577 deletions.
10 changes: 6 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/wailsapp/wails/v2/pkg/runtime"
"log"
"strings"
sydney2 "sydneyqt/sydney"
"sydneyqt/util"
"sync"
)

Expand Down Expand Up @@ -61,27 +63,27 @@ const (

func (a *App) askSydney(options AskOptions) {
currentWorkspace := a.settings.config.GetCurrentWorkspace()
sydney := NewSydney(a.debug, ReadCookiesFile(), a.settings.config.Proxy,
sydney := sydney2.NewSydney(a.debug, util.ReadCookiesFile(), a.settings.config.Proxy,
currentWorkspace.ConversationStyle, currentWorkspace.Locale, a.settings.config.WssDomain,
a.settings.config.NoSearch)
conversation, err := sydney.CreateConversation()
if err != nil {
runtime.EventsEmit(a.ctx, EventChatAlert, err.Error())
return
}
stopCtx, cancel := CreateCancelContext()
stopCtx, cancel := util.CreateCancelContext()
defer cancel()
go func() {
runtime.EventsOn(a.ctx, EventChatStop, func(optionalData ...interface{}) {
cancel()
})
}()
ch := sydney.AskStream(stopCtx, conversation, options.Prompt, options.ChatContext, options.ImageURL)
ch := sydney.AskStreamRaw(stopCtx, conversation, options.Prompt, options.ChatContext, options.ImageURL)
defer runtime.EventsEmit(a.ctx, EventChatFinish)
sendSuggestedResponses := func(message gjson.Result) {
if message.Get("suggestedResponses").Exists() {
runtime.EventsEmit(a.ctx, EventChatSuggestedResponses,
Map(message.Get("suggestedResponses").Array(), func(v gjson.Result) string {
util.Map(message.Get("suggestedResponses").Array(), func(v gjson.Result) string {
return v.Get("text").String()
}),
)
Expand Down
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/pkg/errors"
"os"
"sydneyqt/util"
)

type Preset struct {
Expand Down Expand Up @@ -57,7 +58,7 @@ func fillDefault[T comparable](pointer *T, defaultValue T) {
}
}
func (o *Config) GetCurrentWorkspace() Workspace {
workspace, exist := FindFirst(o.Workspaces, func(value Workspace) bool {
workspace, exist := util.FindFirst(o.Workspaces, func(value Workspace) bool {
return value.ID == o.CurrentWorkspaceID
})
if !exist {
Expand Down
Loading

0 comments on commit a84aa60

Please sign in to comment.