Skip to content

Commit

Permalink
fix hey/update.go (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Aug 17, 2023
1 parent bfc6995 commit c6e4cc3
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions ui/hey/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package hey

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/JunNishimura/Chatify/ai/functions"
"github.com/JunNishimura/Chatify/ai/model"
"github.com/JunNishimura/Chatify/ai/prompt"
"github.com/JunNishimura/Chatify/auth"
"github.com/JunNishimura/Chatify/config"
"github.com/JunNishimura/spotify/v2"
Expand Down Expand Up @@ -64,7 +62,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.chatCompMessages = []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: msg.prompt,
Content: prompt.Base,
},
}

Expand Down Expand Up @@ -157,42 +155,18 @@ func (m Model) setupSpotify() tea.Msg {

type openaiMsg struct {
client *openai.Client
prompt string
functions []openai.FunctionDefinition
}

func (m Model) setupOpenAI() tea.Msg {
openaiAPIKey := m.cfg.GetClientValue(config.OpenAIAPIKey)

prompt, err := readPrompt()
if err != nil {
return errMsg{err: err}
}

return openaiMsg{
client: openai.NewClient(openaiAPIKey),
prompt: prompt,
functions: functions.GetFunctionDefinitions(m.availableGenres),
}
}

const promptPath = "ai/prompt/system.txt"

func readPrompt() (string, error) {
curPath, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("fail to get current path: %v", err)
}

promptPath := filepath.Join(curPath, promptPath)
promptB, err := os.ReadFile(promptPath)
if err != nil {
return "", fmt.Errorf("fail to read %s: %v", promptPath, err)
}

return string(promptB), nil
}

type responseMsg struct{ resp openai.ChatCompletionResponse }

func (m Model) generate() tea.Msg {
Expand Down

0 comments on commit c6e4cc3

Please sign in to comment.