Skip to content

Commit ded59c8

Browse files
authored
Merge pull request #51 from BalanceBalls/bug-fixes
More refactoring
2 parents 97958db + 2c068bf commit ded59c8

File tree

11 files changed

+309
-187
lines changed

11 files changed

+309
-187
lines changed

clients/gemini.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func (c GeminiClient) RequestCompletion(
115115
processResultID++
116116
}
117117
sendCompensationChunk(resultChan, processResultID)
118+
break
118119
}
119120
}
120121

@@ -204,7 +205,7 @@ func sendCompensationChunk(resultChan chan util.ProcessApiCompletionResponse, id
204205
resultChan <- util.ProcessApiCompletionResponse{
205206
ID: id,
206207
Result: chunk,
207-
Final: false,
208+
Final: true,
208209
}
209210
util.Slog.Debug("Gemini: compensation chunk sent")
210211
}
@@ -327,15 +328,25 @@ func buildChatHistory(msgs []util.MessageToSend) []*genai.Content {
327328
role = "model"
328329
}
329330

331+
messageContent := ""
332+
if singleMessage.Resoning != "" {
333+
messageContent += singleMessage.Resoning
334+
}
330335
if singleMessage.Content != "" {
336+
messageContent += singleMessage.Content
337+
}
338+
339+
if messageContent != "" {
331340
message := genai.Content{
332341
Parts: []genai.Part{
333-
genai.Text(singleMessage.Content),
342+
genai.Text(messageContent),
334343
},
335344
Role: role,
336345
}
337346
chat = append(chat, &message)
338347
}
348+
349+
util.Slog.Debug("constructed turn", "data", messageContent)
339350
}
340351

341352
return chat

clients/openai.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ func (c OpenAiClient) RequestModelsList(ctx context.Context) util.ProcessModelsR
8080
return processModelsListResponse(resp)
8181
}
8282

83-
func ConstructUserMessage(content string) util.MessageToSend {
84-
return util.MessageToSend{
83+
func ConstructUserMessage(content string) util.OpenAIConversationTurn {
84+
return util.OpenAIConversationTurn{
8585
Role: "user",
8686
Content: content,
8787
}
8888
}
8989

90-
func constructSystemMessage(content string) util.MessageToSend {
91-
return util.MessageToSend{
90+
func constructSystemMessage(content string) util.OpenAIConversationTurn {
91+
return util.OpenAIConversationTurn{
9292
Role: "system",
9393
Content: content,
9494
}
@@ -99,7 +99,7 @@ func (c OpenAiClient) constructCompletionRequestPayload(
9999
cfg config.Config,
100100
settings util.Settings,
101101
) ([]byte, error) {
102-
messages := []util.MessageToSend{}
102+
messages := []util.OpenAIConversationTurn{}
103103

104104
if util.IsSystemMessageSupported(c.provider, settings.Model) {
105105
if cfg.SystemMessage != "" || settings.SystemPrompt != nil {
@@ -113,8 +113,24 @@ func (c OpenAiClient) constructCompletionRequestPayload(
113113
}
114114

115115
for _, singleMessage := range chatMsgs {
116+
messageContent := ""
117+
if singleMessage.Resoning != "" {
118+
messageContent += singleMessage.Resoning
119+
}
120+
116121
if singleMessage.Content != "" {
117-
messages = append(messages, singleMessage)
122+
messageContent += singleMessage.Content
123+
}
124+
125+
if messageContent != "" {
126+
conversationTurn := util.OpenAIConversationTurn{
127+
Model: singleMessage.Model,
128+
Role: singleMessage.Role,
129+
Content: messageContent,
130+
}
131+
132+
util.Slog.Debug("constructed turn", "data", conversationTurn)
133+
messages = append(messages, conversationTurn)
118134
}
119135
}
120136

panes/chat-pane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (p ChatPane) Update(msg tea.Msg) (ChatPane, tea.Cmd) {
157157
return p, nil
158158

159159
case sessions.LoadDataFromDB:
160-
util.Slog.Debug("case LoadDataFromDB: ", "message", msg)
160+
// util.Slog.Debug("case LoadDataFromDB: ", "message", msg)
161161
return p.initializePane(msg.Session)
162162

163163
case sessions.UpdateCurrentSession:

panes/prompt-pane.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
const ResponseWaitingMsg = "> Please wait ..."
1818
const InitializingMsg = "Components initializing ..."
19-
const PlaceholderMsg = "Press i to type. Use ctrl+e to expand/collapse editor"
19+
const PlaceholderMsg = "Press i to type ctrl+e expand/collapse editor • ctrl+r clear"
2020

2121
type keyMap struct {
2222
insert key.Binding
@@ -277,6 +277,10 @@ func (p PromptPane) Update(msg tea.Msg) (PromptPane, tea.Cmd) {
277277

278278
switch p.viewMode {
279279
case util.TextEditMode:
280+
if strings.TrimSpace(p.textEditor.Value()) == "" {
281+
break
282+
}
283+
280284
if !p.textEditor.Focused() {
281285
promptText := p.textEditor.Value()
282286
p.textEditor.SetValue("")
@@ -299,6 +303,10 @@ func (p PromptPane) Update(msg tea.Msg) (PromptPane, tea.Cmd) {
299303
util.SendViewModeChangedMsg(util.NormalMode))
300304
}
301305
default:
306+
if strings.TrimSpace(p.input.Value()) == "" {
307+
break
308+
}
309+
302310
promptText := p.input.Value()
303311
p.input.SetValue("")
304312
p.input.Blur()

panes/sessions-pane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (p SessionsPane) Update(msg tea.Msg) (SessionsPane, tea.Cmd) {
129129
p.updateSessionsList()
130130

131131
case sessions.LoadDataFromDB:
132-
util.Slog.Debug("case LoadDataFromDB: ", "message", msg)
132+
// util.Slog.Debug("case LoadDataFromDB: ", "message", msg)
133133
p.currentSession = msg.Session
134134
p.sessionsListData = msg.AllSessions
135135
p.currentSessionId = msg.CurrentActiveSessionID

0 commit comments

Comments
 (0)