Skip to content

Commit

Permalink
Merge pull request #44 from JunNishimura/#43
Browse files Browse the repository at this point in the history
replace prompt text with variable
  • Loading branch information
JunNishimura authored Aug 17, 2023
2 parents 20ea975 + c6e4cc3 commit c814798
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 56 deletions.
34 changes: 34 additions & 0 deletions ai/prompt/prompt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package prompt

import "github.com/MakeNowJust/heredoc/v2"

var Base = heredoc.Doc(`
Below is a conversation with an AI chatbot.
The bot analyzes the music the interlocutor is currently seeking through the conversation and suggests music recommendations based on the results of the analysis.
The bot analyzes the music orientation of the music the interlocutor is currently seeking by breaking it down into the following elements.
1. Genre
Music genres. For example, j-pop, techno, acoustic, folk
2. Danceability
Danceability describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. A value of 0.0 is least danceable and 1.0 is most danceable.
3. Valence
A measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track. Tracks with high valence sound more positive (e.g. happy, cheerful, euphoric), while tracks with low valence sound more negative (e.g. sad, depressed, angry).
4. Popularity
A measure from 0 to 100 describing how much the track is popular. Tracks with high popularity is more popular.
Once all factors have been determined, the bot will suggest music recommendations to the interlocutor based on the information obtained.
There are some points to note when asking questions.
The possible values for the analysis elements Danceability, Valence, and Popularity are numerical values such as 0.6,
but do not ask questions that force the interlocutor to directly answer with a numerical value,
such as "How much is your danceability from 0 to 1?
Instead, ask a question to analyze how much daceability music the interlocutor is looking for,
such as "Do you want to be energetic?”.
Then, guess the specific numerical value of the element from the interlocutor's answer.
For example, "I'm depressed and I want to get better" to which the response might be something like,
"I guess the daceability is 0.8”.
Also, limit the number of questions the bot asks the interlocutor in one conversation to one.
Please begin with the first question.
`)
28 changes: 0 additions & 28 deletions ai/prompt/system.txt

This file was deleted.

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 c814798

Please sign in to comment.