Skip to content

Commit

Permalink
Use GToolkit-specific package for LLM core [feenkcom/gtoolkit#4322]
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve committed Mar 3, 2025
1 parent 61d950f commit 266463b
Show file tree
Hide file tree
Showing 107 changed files with 849 additions and 762 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Extension { #name : #BrGlamorousVectorIcons }

{ #category : #'*Gt4Llm' }
{ #category : #'*Gt4Llm-GToolkit' }
BrGlamorousVectorIcons class >> largeOpenAi [
<script: 'self openAi inspect'>
^ [ BlElement new
Expand All @@ -11,7 +11,7 @@ BrGlamorousVectorIcons class >> largeOpenAi [
background: Color black ] asStencil
]

{ #category : #'*Gt4Llm' }
{ #category : #'*Gt4Llm-GToolkit' }
BrGlamorousVectorIcons class >> openAi [
^ [ self largeOpenAi asElement asScalableElement size: 16 @ 16 ] asStencil
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class {
#classVars : [
'ShouldShowSection'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #settings }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #GtBPEDemoEncodingResultProxy,
#superclass : #PBProxyObject,
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #GtBPEDemoMergeProxy,
#superclass : #PBProxyObject,
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
14 changes: 14 additions & 0 deletions src/Gt4Llm-GToolkit/GtBPEEncoder.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Extension { #name : #GtBPEEncoder }

{ #category : #'*Gt4Llm-GToolkit' }
GtBPEEncoder >> getStatsFor: aListOfTokens [
| stats |
stats := GtCounter new.
1
to: aListOfTokens size - 1
do: [ :anIndex |
stats
increment: {aListOfTokens at: anIndex.
aListOfTokens at: anIndex + 1} ].
^ stats
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Extension { #name : #GtHome }

{ #category : #'*Gt4Llm' }
{ #category : #'*Gt4Llm-GToolkit' }
GtHome >> gt4llmSection [
"<gtHomeSection>"
Gt4LlmHomeSection shouldShowSection ifFalse: [ ^ GtHomeEmptySection new ].
Expand Down
11 changes: 11 additions & 0 deletions src/Gt4Llm-GToolkit/GtLlmActionChat.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Extension { #name : #GtLlmActionChat }

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmActionChat >> asViewModel [
^ GtLlmActionChatViewModel new assistantChat: self
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmActionChat >> executeWait: aBlock [
(self whenReadyFuture then: [ :_ | aBlock value: self messages last ]) await
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #GtLlmActionChatViewModel,
#superclass : #GtLlmChatViewModel,
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {
'example',
'onActionCreated'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class {
#instVars : [
'action'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
25 changes: 25 additions & 0 deletions src/Gt4Llm-GToolkit/GtLlmActionsGroup.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Extension { #name : #GtLlmActionsGroup }

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmActionsGroup >> gtActionsFor: aView [
<gtView>
^ aView columnedList
title: 'Actions';
priority: 1;
items: [ self items ];
column: 'Name'
text: #name
weight: 0.5;
column: 'Description' text: #description;
column: 'Actions'
stencil: [ :anItem |
BrButton new
aptitude: BrGlamorousButtonWithIconAptitude;
icon: BrGlamorousVectorIcons cancel;
label: 'Remove';
action: [ :aButton |
self remove: anItem.
anItem removeFromSystem.
aButton phlow fireToolUpdateWish ] ]
width: 70
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
'fileError',
'clientClass'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
'styler',
'checkRunResultViewModels'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
44 changes: 44 additions & 0 deletions src/Gt4Llm-GToolkit/GtLlmChat.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Extension { #name : #GtLlmChat }

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmChat >> asViewModel [
^ GtLlmChatViewModel new assistantChat: self
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmChat >> gtMessagesWidgetFor: aView [
"cannot be a forward because the update wouldn’t work"

<gtView>
| aViewModel |
self provider ifNil: [ ^ aView empty ].

^ aView explicit
title: 'Chat';
priority: 0;
stencil: [ aViewModel ifNil: [ aViewModel := self asViewModel ].
GtLlmChatElement new chatViewModel: aViewModel ];
actionUpdateButton
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmChat >> gtWriteFor: aView [
<gtView>
^ aView textEditor
title: 'Write';
priority: 4;
text: [ 'Write a message here' ];
actionButtonIcon: BrGlamorousVectorIcons play
tooltip: 'Send'
action: [ :aButton |
aButton parent parent parent parent
allChildrenBreadthFirstDetect: [ :anElement | anElement isKindOf: BrEditor ]
ifFound: [ :anEditor |
self sendMessage: anEditor text asString.
anEditor text: '' ] ]
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmChat >> whenReadyFuture [
^ GtLlmChatReadyFuture new chat: self
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
'chatViewModel',
'listElement'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #GtLlmChatExamples,
#superclass : #Object,
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #'as yet unclassified' }
Expand Down
17 changes: 17 additions & 0 deletions src/Gt4Llm-GToolkit/GtLlmChatMessage.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Extension { #name : #GtLlmChatMessage }

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmChatMessage >> asViewModel [
^ GtLlmThreadMessageViewModel new threadMessage: self
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmChatMessage >> gtContentFor: aView [
<gtView>
<gtLlmMessageView>
^ aView explicit
title: 'Content';
priority: 5;
stencil: [ GtLlmThreadMessageElement new
threadMessageViewModel: self asViewModel ]
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
'chat',
'delay'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
'newThreadMessageViewModel',
'threadMessageViewModelsCache'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #initialization }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class {
#instVars : [
'choices'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #'as yet unclassified' }
Expand Down
22 changes: 22 additions & 0 deletions src/Gt4Llm-GToolkit/GtLlmEmbeddingRegistry.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Extension { #name : #GtLlmEmbeddingRegistry }

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmEmbeddingRegistry >> gtEmbeddingsFor: aView [
<gtView>
^ aView columnedList
title: 'Embeddings';
priority: 1;
items: [ embeddings associations ];
column: 'Input' text: [ :aPair | aPair value input ];
column: 'Actions'
stencil: [ :aPair |
BrButton new
aptitude: BrGlamorousButtonWithIconAptitude;
label: 'Remove';
icon: BrGlamorousVectorIcons remove;
action: [ :aButton |
embeddings removeKey: aPair key.
aButton phlow fireUpdateWish ] ]
width: 80;
send: #value
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {
'instructions',
'viewsBlacklist'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
'oneLineThreadMessageElement',
'threadMessageElement'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #factory }
Expand Down
17 changes: 17 additions & 0 deletions src/Gt4Llm-GToolkit/GtLlmFailureThreadMessage.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Extension { #name : #GtLlmFailureThreadMessage }

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmFailureThreadMessage >> elementClass [
^ GtLlmThreadMessageElement
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmFailureThreadMessage >> gtContentFor: aView [
<gtView>
<gtLlmMessageView>
^ aView explicit
title: 'Content';
priority: 1;
stencil: [ GtLlmThreadMessageElement new
threadMessageViewModel: (GtLlmThreadMessageViewModel new threadMessage: self) ]
]
60 changes: 60 additions & 0 deletions src/Gt4Llm-GToolkit/GtLlmFineTuningFile.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Extension { #name : #GtLlmFineTuningFile }

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmFineTuningFile >> costsForEpochs: anInteger [
| numberOfTokens |
numberOfTokens := self numberOfTokens * anInteger.

"this model is free until september 23rd 2024 for under 2M tokens"
((self model beginsWith: 'gpt-4o-mini')
and: [ Date today
< (Date
year: 2024
month: 9
day: 23) and: [ numberOfTokens < 2000000 ] ])
ifTrue: [ ^ GtTCurrencyMoney new
amount: 0;
currency: GtTCurrency usd ].

^ GtTCurrencyMoney new
amount: numberOfTokens * self pricePerToken;
currency: GtTCurrency usd
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmFineTuningFile >> costsPerEpoch [
| numberOfTokens |
numberOfTokens := self numberOfTokens.

"this model is free until september 23rd 2024 for under 2M tokens"
((self model beginsWith: 'gpt-4o-mini')
and: [ Date today
< (Date
year: 2024
month: 9
day: 23) and: [ numberOfTokens < 2000000 ] ])
ifTrue: [ ^ GtTCurrencyMoney new
amount: 0;
currency: GtTCurrency usd ].

^ GtTCurrencyMoney new
amount: numberOfTokens * self pricePerToken;
currency: GtTCurrency usd
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmFineTuningFile >> gtCostFor: aView [
<gtView>
^ aView forward
title: 'Cost';
priority: 3;
object: [ self costsPerEpoch ];
view: #gtDetailsFor:
]

{ #category : #'*Gt4Llm-GToolkit' }
GtLlmFineTuningFile >> numberOfTokens [
^ (GtLlmTokenizer new
tokenizeMessages: (conversations flatCollect: #items)
usingModel: self model) tokenCount
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #GtLlmInspectorSummarizer,
#superclass : #Object,
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
'viewClass',
'withoutMarkup'
],
#category : #Gt4Llm
#category : #'Gt4Llm-GToolkit'
}

{ #category : #accessing }
Expand Down
Loading

0 comments on commit 266463b

Please sign in to comment.