Skip to content

Commit d302fbe

Browse files
Merge pull request #14 from BalanceBalls/visual-mode
Text selection and info pane
2 parents 87e25d3 + e0cf37a commit d302fbe

24 files changed

+862
-41
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ Additional fields:
5252
You can change colorscheme using the `colorScheme` field.
5353
Possible options are `Pink` and `Blue`. Default colorscheme is `Pink`
5454

55+
## Cache invalidation
56+
57+
Models list is cached for 14 days upon loading. If you need to invalidate cache use `--purge-cache` flag:
58+
```bash
59+
./chatgpt-tui --purge-cache
60+
```
61+
5562
## Demo
5663

5764
![tui demo](./docs/images/tui-demo.gif)
@@ -71,7 +78,26 @@ Possible options are `Pink` and `Blue`. Default colorscheme is `Pink`
7178
## Chat Messages Pane
7279

7380
- `y`: Copies the last message from ChatGPT into your clipboard.
74-
- `Y`: Copies all messages from the ChatGPT session into your clipboard.
81+
- `Shift+y`: Copies all messages from the ChatGPT session into your clipboard.
82+
- `v`: Enters navigation mode when chat pane is focused (allows to move accross the chat content lines)
83+
84+
### Selection mode
85+
86+
![selection demo](./docs/images/selection-mode.gif)
87+
88+
Selection mode allows to navigate the chat pane and select lines to copy. Supports basic vim-motions.
89+
90+
<b>Navigation</b>
91+
- `j`, `k` - go down and up a line
92+
- Multiline jumps like `3j` (3 lines down), `99k` (99 lines up) are also supported
93+
- `d`, `u`, `Ctrl+d`, `Ctrl+u` - go up or down half page
94+
- `g` - go to top
95+
- `Shift+g` - go to bottom
96+
97+
<b>Selection</b>
98+
- `v`, `Shift+v` or `space` to enter or quit line selection mode
99+
- `y` to copy selected text
100+
- `Esc` to quit selection or navigation modes
75101

76102
## Settings Pane
77103

@@ -83,8 +109,15 @@ Possible options are `Pink` and `Blue`. Default colorscheme is `Pink`
83109

84110
- `Ctrl+N`: Creates a new session.
85111
- `d`: Deletes the currently selected session from the list.
112+
- `e`: Edit session name
86113
- `Enter`: Switches to the session that is currently selected.
87114

115+
## Info pane
116+
117+
Information pane displays processing state of inference (`IDLE`, `PROCESSING`) as well as token stats for the current session:
118+
- `IN`: shows the total amount of input tokens LLM consumed per session
119+
- `OUT`: shows the total amount of output tokens LLM produced per session
120+
88121
Please refer to this guide as you navigate the TUI. Happy exploring!
89122

90123
### Dev notes

clients/openai-types.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ type Choice struct {
77
}
88

99
type CompletionChunk struct {
10-
ID string `json:"id"`
11-
Object string `json:"object"`
12-
Created int `json:"created"`
13-
Model string `json:"model"`
14-
SystemFingerpint string `json:"system_fingerprint"`
15-
Choices []Choice `json:"choices"`
10+
ID string `json:"id"`
11+
Object string `json:"object"`
12+
Created int `json:"created"`
13+
Model string `json:"model"`
14+
SystemFingerpint string `json:"system_fingerprint"`
15+
Choices []Choice `json:"choices"`
16+
Usage *TokenUsage `json:"usage"`
17+
}
18+
19+
type TokenUsage struct {
20+
Prompt int `json:"prompt_tokens"`
21+
Completion int `json:"completion_tokens"`
22+
Total int `json:"total_tokens"`
1623
}
1724

1825
type CompletionResponse struct {

clients/openai.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ import (
1919
type OpenAiClient struct {
2020
apiUrl string
2121
systemMessage string
22+
provider util.ApiProvider
2223
client http.Client
2324
}
2425

2526
func NewOpenAiClient(apiUrl, systemMessage string) *OpenAiClient {
27+
provider := util.GetInferenceProvider(apiUrl)
2628
return &OpenAiClient{
29+
provider: provider,
2730
apiUrl: apiUrl,
2831
systemMessage: systemMessage,
2932
client: http.Client{},
@@ -85,17 +88,22 @@ func (c OpenAiClient) constructCompletionRequestPayload(chatMsgs []util.MessageT
8588
messages := []util.MessageToSend{}
8689
messages = append(messages, constructSystemMessage(c.systemMessage))
8790
for _, singleMessage := range chatMsgs {
88-
messages = append(messages, singleMessage)
91+
if singleMessage.Content != "" {
92+
messages = append(messages, singleMessage)
93+
}
8994
}
9095
log.Println("Constructing message: ", modelSettings.Model)
91-
// log.Println("Messages: ", messages)
92-
body, err := json.Marshal(map[string]interface{}{
96+
97+
reqParams := map[string]interface{}{
9398
"model": modelSettings.Model, // Use string literals for keys
9499
"frequency_penalty": modelSettings.Frequency,
95100
"max_tokens": modelSettings.MaxTokens,
96101
"stream": true,
97102
"messages": messages,
98-
})
103+
}
104+
util.GetAdditionalReqRequestHeaders(c.provider, reqParams)
105+
106+
body, err := json.Marshal(reqParams)
99107
if err != nil {
100108
log.Fatalf("Error marshaling JSON: %v", err)
101109
return nil, err

components/sessions-list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ func NewSessionsList(items []list.Item, w, h int, colors util.SchemeColors) Sess
102102
l.SetShowHelp(false)
103103
l.DisableQuitKeybindings()
104104

105+
l.Paginator.ActiveDot = lipgloss.NewStyle().Foreground(colors.HighlightColor).Render("■")
106+
l.Paginator.InactiveDot = lipgloss.NewStyle().Foreground(colors.DefaultTextColor).Render("•")
105107
selectedItemStyle = selectedItemStyle.Copy().Foreground(colors.AccentColor)
106108
activeItemStyle = activeItemStyle.Copy().Foreground(colors.HighlightColor)
107109

0 commit comments

Comments
 (0)