8000 make chat view a bit prettier [feenkcom/gtoolkit#4462] · feenkcom/gt4llm@ace9812 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit ace9812

Browse files
committed
make chat view a bit prettier [feenkcom/gtoolkit#4462]
1 parent 4e3bfc3 commit ace9812

17 files changed

+84
-66
lines changed

src/Gt4Anthropic/GtAnthropicChatMessage.class.st

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Class {
22
#name : #GtAnthropicChatMessage,
33
#superclass : #GtLlmChatMessage,
44
#instVars : [
5-
'model',
65
'stopReason',
76
'stopSequence',
87
'type',
@@ -50,16 +49,6 @@ GtAnthropicChatMessage >> contentText [
5049
thenCollect: [ :aValue | (aValue at: #text) ifNil: [ '' ] ]) ]
5150
]
5251

53-
{ #category : #accessing }
54-
GtAnthropicChatMessage >> model [
55-
^ model
56-
]
57-
58-
{ #category : #accessing }
59-
GtAnthropicChatMessage >> model: anObject [
60-
model := anObject
61-
]
62-
6352
{ #category : #'as yet unclassified' }
6453
GtAnthropicChatMessage >> serialize [
6554
^ {'role' -> self role.

src/Gt4Llm-GToolkit/GtLlmActionThreadMessageViewModel.class.st

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ GtLlmActionThreadMessageViewModel >> action: anObject [
1717
action := anObject
1818
]
1919

20-
{ #category : #'as yet unclassified' }
21-
GtLlmActionThreadMessageViewModel >> actionModel [
22-
^ self threadMessage actionModel
23-
]
24-
2520
{ #category : #accessing }
2621
GtLlmActionThreadMessageViewModel >> elementClass [
2722
^ GtLlmExpandableThreadMessageElement

src/Gt4Llm-GToolkit/GtLlmBasicThreadMessageViewModel.class.st

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,6 @@ GtLlmBasicThreadMessageViewModel >> subscribeToThreadMessage [
159159
{ #category : #'as yet unclassified' }
160160
GtLlmBasicThreadMessageViewModel >> uiInsets [
161161
self threadMessage isAssistantRole ifTrue: [ ^ BlInsets right: 50 ].
162+
self threadMessage isToolRole ifTrue: [ ^ BlInsets left: 25 right: 25 ].
162163
^ BlInsets left: 50
163164
]

src/Gt4Llm-GToolkit/GtLlmChatViewModel.class.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ GtLlmChatViewModel >> threadMessageViewModels [
5858
aViewModel := threadMessageViewModelsCache
5959
at: aMessage id
6060
ifPresent: [ :theViewModel | theViewModel threadMessage: aMessage ]
61-
ifAbsentPut: [ aMessage asViewModel isExpanded: lastMessage = aMessage ].
61+
ifAbsentPut: [ aMessage asViewModel
62+
isExpanded: (lastMessage = aMessage and: [ aMessage isToolRole not ]) ].
6263
aStream nextPut: aViewModel ].
6364
aStatus := assistantChat status.
6465

src/Gt4Llm-GToolkit/GtLlmThreadMessageHeaderElement.class.st

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ GtLlmThreadMessageHeaderElement >> addActionElement [
1212
aFrame := BrFrame new matchParent.
1313

1414
aFrame
15-
padding: (BlInsets left: 15 right: 15);
15+
padding: (BlInsets left: 0 right: 15);
1616
addChild: (BrLabel new
1717
hFitContentLimited;
1818
vFitContent;
19-
aptitude: (BrGlamorousLabelAptitude new
20-
foreground: BrGlamorousColors disabledButtonTextColor);
19+
aptitude: BrGlamorousLabelAptitude new;
2120
beSmallSize;
22-
text: self threadMessageViewModel action;
21+
text: self threadMessageViewModel actionString;
2322
when: BlClickEvent
2423
do: [ :anEvent | anEvent target phlow spawnObject: self threadMessageViewModel actionModel ]).
2524

@@ -35,26 +34,11 @@ GtLlmThreadMessageHeaderElement >> addSenderElement [
3534
aptitude: (BrGlamorousLabelAptitude new
3635
foreground: BrGlamorousColors disabledButtonTextColor);
3736
beSmallSize;
38-
text: self threadMessageViewModel senderText)
39-
]
40-
41-
{ #category : #accessing }
42-
GtLlmThreadMessageHeaderElement >> addTimeElement [
43-
| timeTooltip |
44-
timeTooltip := BrGlamorousWithExplicitTooltipAptitude
45-
text: (String
46-
streamContents: [ :s | self threadMessageViewModel createdAt asLocal printSeparateDateAndTimeOn: s ]).
47-
48-
self
49-
addChild: (BrLabel new
50-
updatingDateAndTimeModel;
51-
fitContent;
52-
beSmallSize;
53-
aptitude: (BrGlamorousLabelAptitude new
54-
foreground: BrGlamorousColors disabledButtonTextColor);
55-
addAptitude: timeTooltip;
56-
updatingDateAndTime: self threadMessageViewModel createdAt;
57-
yourself)
37+
text: self threadMessageViewModel senderText
38+
, (self threadMessageViewModel hasAction ifTrue: [ ':' ] ifFalse: [ '' ]);
39+
addAptitude: (BrGlamorousWithExplicitTooltipAptitude
40+
text: (String
41+
streamContents: [ :s | self threadMessageViewModel createdAt asLocal printSeparateDateAndTimeOn: s ])))
5842
]
5943

6044
{ #category : #accessing }
@@ -75,6 +59,5 @@ GtLlmThreadMessageHeaderElement >> updateElement [
7559
self removeChildren.
7660

7761
self addSenderElement.
78-
self addTimeElement.
7962
self addActionElement
8063
]

src/Gt4Llm-GToolkit/GtLlmThreadMessageViewModel.class.st

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,30 @@ Class {
1111

1212
{ #category : #accessing }
1313
GtLlmThreadMessageViewModel >> action [
14-
^ ''
14+
^ self threadMessage action
15+
]
16+
17+
{ #category : #accessing }
18+
GtLlmThreadMessageViewModel >> actionArguments [
19+
^ self threadMessage arguments
20+
]
21+
22+
{ #category : #'as yet unclassified' }
23+
GtLlmThreadMessageViewModel >> actionModel [
24+
^ self threadMessage actionModel
25+
]
26+
27+
{ #category : #accessing }
28+
GtLlmThreadMessageViewModel >> actionString [
29+
| actionArguments |
30+
self action ifNil: [ ^ '' ].
31+
32+
actionArguments := self actionArguments.
33+
34+
^ self action
35+
, (actionArguments isEmptyOrNil
36+
ifTrue: [ '' ]
37+
ifFalse: [ '(' , (', ' join: actionArguments) , ')' ])
1538
]
1639

1740
{ #category : #accessing }
@@ -33,6 +56,11 @@ GtLlmThreadMessageViewModel >> elementClass [
3356
^ GtLlmExpandableThreadMessageElement
3457
]
3558

59+
{ #category : #accessing }
60+
GtLlmThreadMessageViewModel >> hasAction [
61+
^ self action isNotNil
62+
]
63+
3664
{ #category : #accessing }
3765
GtLlmThreadMessageViewModel >> isExpanded [
3866
^ isExpanded ifNil: [ true ]

src/Gt4Llm/GtLlmActionMessage.class.st

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ GtLlmActionMessage >> actionModel [
1818
ifFalse: [ nil ] ]
1919
]
2020

21-
{ #category : #'as yet unclassified' }
22-
GtLlmActionMessage >> arguments [
23-
^ self contentJson at: 'Arguments'
24-
]
25-
2621
{ #category : #'as yet unclassified' }
2722
GtLlmActionMessage >> contentSummary [
2823
^ self action

src/Gt4Llm/GtLlmChatMessage.class.st

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Class {
88
'createdAt',
99
'chat',
1010
'announcer',
11-
'images'
11+
'images',
12+
'model'
1213
],
1314
#category : #Gt4Llm
1415
}
@@ -66,6 +67,11 @@ GtLlmChatMessage >> announcer [
6667
^ announcer ifNil: [announcer := Announcer new]
6768
]
6869

70+
{ #category : #'as yet unclassified' }
71+
GtLlmChatMessage >> arguments [
72+
^ [ self contentJson at: 'Arguments' ] on: Error do: [ nil ]
73+
]
74+
6975
{ #category : #accessing }
7076
GtLlmChatMessage >> asTokenizableString [
7177
^ '<|im_start|>' , self role , '<|im_sep|>' , self content , '<|im_end|>'
@@ -219,6 +225,16 @@ GtLlmChatMessage >> isUserRole [
219225
^ self role = 'user'
220226
]
221227

228+
{ #category : #accessing }
229+
GtLlmChatMessage >> model [
230+
^ model
231+
]
232+
233+
{ #category : #accessing }
234+
GtLlmChatMessage >> model: anObject [
235+
model := anObject
236+
]
237+
222238
{ #category : #'announcer - subscription' }
223239
GtLlmChatMessage >> removeSubscription: subscription [
224240
"Remove the given subscription from the receiver"
@@ -237,7 +253,10 @@ GtLlmChatMessage >> role: anObject [
237253

238254
{ #category : #accessing }
239255
GtLlmChatMessage >> senderText [
240-
self isAssistantRole ifTrue: [ ^ 'Assistant' ].
256+
self isAssistantRole
257+
ifTrue: [ ^ self model
258+
ifNil: [ 'Assistant' ]
259+
ifNotNil: [ :aModel | GtLlmConnectionRegistry uniqueInstance labelForModel: aModel ] ].
241260
self isSystemRole ifTrue: [ ^ 'System' ].
242261
self isToolRole ifTrue: [ ^ 'Tool' ].
243262
^ 'You'

src/Gt4Llm/GtLlmConnectionRegistry.class.st

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ GtLlmConnectionRegistry >> initialize [
115115
self defaultConnection: self standardDefaultConnection
116116
]
117117

118+
{ #category : #'as yet unclassified' }
119+
GtLlmConnectionRegistry >> labelForModel: aModel [
120+
^ connections
121+
detect: [ :aConnection | aConnection model = aModel ]
122+
ifFound: [ :aConnection | aConnection label ]
123+
ifNone: [ aModel ]
124+
]
125+
118126
{ #category : #'as yet unclassified' }
119127
GtLlmConnectionRegistry >> standardDefaultConnection [
120128
^ GtLlmConnection new

src/Gt4Llm/GtLlmNewActionThreadMessage.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ GtLlmNewActionThreadMessage >> currentAction: anObject [
2121
GtLlmNewActionThreadMessage >> treatString [
2222
^ GtLlmActionCall new
2323
action: currentAction name;
24-
arguments: {contents asString}
24+
arguments: (currentAction hasArgument ifTrue: [ {contents asString} ] ifFalse: [ {} ])
2525
]

src/Gt4Llm/GtLlmProvisionalThreadMessage.class.st

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Class {
1010

1111
{ #category : #accessing }
1212
GtLlmProvisionalThreadMessage >> action [
13-
^ ''
13+
^ nil
1414
]
1515

1616
{ #category : #'as yet unclassified' }
@@ -23,6 +23,11 @@ GtLlmProvisionalThreadMessage >> annotations [
2323
^ #()
2424
]
2525

26+
{ #category : #accessing }
27+
GtLlmProvisionalThreadMessage >> arguments [
28+
^ {}
29+
]
30+
2631
{ #category : #accessing }
2732
GtLlmProvisionalThreadMessage >> chat [
2833
^ chat

src/Gt4Ollama/GtOllamaProvider.class.st

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ GtOllamaProvider >> triggerAssistant [
211211
addMessage: (self assistantMessageClass new
212212
content: result content;
213213
role: 'assistant';
214+
model: self model;
214215
chat: self;
215216
rawData: result rawData).
216217

src/Gt4OpenAI-GToolkit/GtOpenAIResponseProvider.extension.st

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ GtOpenAIResponseProvider >> executeWait [
1515
ifNil: [ self streamingMessageFrom: result ]
1616
ifNotNil: [ result hasToolCalls ifTrue: [ ^ self performToolCallsIn: result ].
1717
self assistantMessageClass new
18+
model: self model;
1819
merge: (result output detect: [ :anOutput | (anOutput rawData at: 'type') = 'message' ]) ].
1920

2021

@@ -32,6 +33,7 @@ GtOpenAIResponseProvider >> streamingMessageFrom: aResult [
3233

3334
aMessage := self assistantMessageClass new
3435
role: 'assistant';
36+
model: self model;
3537
content: ''.
3638
aResult notifyOnOutput: aMessage.
3739

src/Gt4OpenAI/GtOpenAIActionMessage.class.st

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ GtOpenAIActionMessage >> actionModel [
1414
ifFalse: [ nil ] ]
1515
]
1616

17-
{ #category : #'as yet unclassified' }
18-
GtOpenAIActionMessage >> arguments [
19-
^ self contentJson at: 'Arguments'
20-
]
21-
2217
{ #category : #'trait-TGtActionMessage' }
2318
GtOpenAIActionMessage >> gtPromoteToExampleActionFor: anAction [
2419
<gtLlmAction>

src/Gt4OpenAI/GtOpenAIAssistantProvider.class.st

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ GtOpenAIAssistantProvider >> getApiFile: anId [
136136
{ #category : #'as yet unclassified' }
137137
GtOpenAIAssistantProvider >> getMessages [
138138
^ thread updateMessages
139-
collect: [ :aThreadMessage |
140-
self assistantMessageClass new merge: aThreadMessage ]
139+
collect: [ :aThreadMessage |
140+
self assistantMessageClass new
141+
model: self model;
142+
merge: aThreadMessage ]
141143
]
142144

143145
{ #category : #'as yet unclassified' }

src/Gt4OpenAI/GtOpenAIMessage.class.st

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,6 @@ GtOpenAIMessage >> runId: anObject [
247247
runId := anObject
248248
]
249249

250-
{ #category : #accessing }
251-
GtOpenAIMessage >> senderText [
252-
self isAssistantRole ifTrue: [ ^ 'Assistant' ].
253-
self isSystemRole ifTrue: [ ^ 'System' ].
254-
^ 'You'
255-
]
256-
257250
{ #category : #accessing }
258251
GtOpenAIMessage >> step [
259252
^ step

src/Gt4OpenAI/GtOpenAIProvider.class.st

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ GtOpenAIProvider >> triggerAssistant [
130130
self chat
131131
addMessage: (self assistantMessageClass new
132132
content: result choices first message content;
133+
model: self model;
133134
role: 'assistant').
134135

135136
assistantWorking := false.

0 commit comments

Comments
 (0)
0