Skip to content

Commit ca7a974

Browse files
committed
Save llm settings into the chat sessions
1 parent 266b0d1 commit ca7a974

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

prompts/topic.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ Your purpose is to read the whole conversation in the current session and summar
88

99
Follow these rules to respond:
1010

11-
- Respond only with a single short sentence.
12-
- Do not introduce the response
13-
- Do not add extra details
14-
- Be concise and clear, use less than 5 words
15-
- Do not use "The conversation focuses.."
16-
- Use minimum words as possible
11+
- You **MUST** respond only a single short sentence.
12+
- Be concise and clear, use less than 5 words.
13+
- The sentence must be about the actual chat contents.
14+
15+
What's you should not do:
16+
17+
- Dont introduce the response, only respond the summary sentence.
18+
- Avoid using colons, newlines or markdown.
19+
- Do not add any extra details or explanations.
20+
- Do not use markdown, use only plain text.

src/repl/repl.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,14 @@ func (r *REPL) handleChatCommand(args []string) error {
942942
}
943943
}
944944

945+
// sessionData holds messages plus session-specific settings saved to disk.
946+
type sessionData struct {
947+
Messages []Message `json:"messages"`
948+
Provider string `json:"provider"`
949+
Model string `json:"model"`
950+
BaseURL string `json:"baseurl"`
951+
}
952+
945953
// handleSessionCommand handles the /session command and its subcommands
946954
func (r *REPL) handleSessionCommand(args []string) error {
947955
if len(args) < 2 {
@@ -1011,7 +1019,14 @@ func (r *REPL) saveSession(sessionName string) error {
10111019
sessionFile := filepath.Join(homeDir, ".mai", "chat", sessionName+".json")
10121020
topicFile := filepath.Join(homeDir, ".mai", "chat", sessionName+".topic")
10131021

1014-
data, err := json.MarshalIndent(r.messages, "", " ")
1022+
// Save messages plus current provider/model/baseurl
1023+
sess := sessionData{
1024+
Messages: r.messages,
1025+
Provider: r.config.PROVIDER,
1026+
Model: r.config.options.Get("model"),
1027+
BaseURL: r.config.BaseURL,
1028+
}
1029+
data, err := json.MarshalIndent(sess, "", " ")
10151030
if err != nil {
10161031
return fmt.Errorf("cannot marshal session: %v", err)
10171032
}
@@ -1045,10 +1060,21 @@ func (r *REPL) loadSession(sessionName string) error {
10451060
return fmt.Errorf("cannot read session file: %v", err)
10461061
}
10471062

1048-
if err := json.Unmarshal(data, &r.messages); err != nil {
1063+
// Load messages and settings
1064+
var sess sessionData
1065+
if err := json.Unmarshal(data, &sess); err != nil {
10491066
return fmt.Errorf("cannot unmarshal session: %v", err)
10501067
}
1051-
fmt.Printf("Session loaded from %s\n\r", sessionFile)
1068+
r.messages = sess.Messages
1069+
// Restore provider, model, baseurl
1070+
r.config.PROVIDER = sess.Provider
1071+
r.config.options.Set("provider", sess.Provider)
1072+
setModelForProvider(r.config, sess.Model)
1073+
r.config.options.Set("model", sess.Model)
1074+
r.config.BaseURL = sess.BaseURL
1075+
r.config.options.Set("baseurl", sess.BaseURL)
1076+
fmt.Printf("Session '%s' loaded (provider=%s, model=%s, baseurl=%s)\r\n",
1077+
sessionName, sess.Provider, sess.Model, sess.BaseURL)
10521078
return nil
10531079
}
10541080

0 commit comments

Comments
 (0)