Skip to content

Commit

Permalink
Use GToolkit-specific packages for Ollama and OpenAI [feenkcom/gtoolk…
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve committed Mar 3, 2025
1 parent 88c5edc commit 61d950f
Show file tree
Hide file tree
Showing 42 changed files with 298 additions and 277 deletions.
27 changes: 27 additions & 0 deletions src/Gt4Ollama-GToolkit/GtOllamaClient.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Extension { #name : #GtOllamaClient }

{ #category : #'*Gt4Ollama-GToolkit' }
GtOllamaClient >> initializeClient [
| aClient |
aClient := ZnClient new.
aClient forJsonREST.
aClient timeout: 600.
^ aClient
]

{ #category : #'*Gt4Ollama-GToolkit' }
GtOllamaClient >> postStreaming: aString withEntity: anEntity [
| aClient aResult |
aClient := self initializeClient
accept: 'application/jsonl,application/x-ndjson';
contentReader: [ :entity | (NeoJSONReader on: entity readStream) upToEnd ].
aClient url: self baseUrl / aString.

aClient contents: anEntity.

aResult := aClient post.

aResult size > 0 ifTrue: [ self checkForErrors: aResult first ].

^ aResult
]
31 changes: 31 additions & 0 deletions src/Gt4Ollama-GToolkit/GtOllamaModelsGroup.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Extension { #name : #GtOllamaModelsGroup }

{ #category : #'*Gt4Ollama-GToolkit' }
GtOllamaModelsGroup >> gtModelsFor: aView [
<gtView>
^ aView columnedList
title: 'Models';
priority: 1;
items: [ self items ];
column: 'Name' text: #name;
column: 'Model' text: #model;
column: 'Modified at'
text: #modifiedAt
weight: 2;
column: 'Actions'
stencil: [ :aModel |
| aToolbar |
aToolbar := BrToolbar new
aptitude: (BrGlamorousToolbarAptitude new spacing: 5);
fitContent;
addItem: (BrButton new beTinySize
aptitude: BrGlamorousButtonWithIconAptitude;
icon: BrGlamorousVectorIcons inspect;
label: 'Get model information';
action: [ aToolbar phlow spawnObject: (self client getModelInformationFor: aModel name) ]);
addItem: (BrButton new beTinySize
aptitude: BrGlamorousButtonWithIconAptitude;
icon: BrGlamorousVectorIcons cancel;
label: 'Delete model';
action: [ self client deleteModel: aModel name ]) ]
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #GtOllamaThreadMessageExamples,
#superclass : #GtLlmThreadMessageExamples,
#category : #Gt4Ollama
#superclass : #Object,
#category : #'Gt4Ollama-GToolkit'
}

{ #category : #'as yet unclassified' }
Expand Down
26 changes: 0 additions & 26 deletions src/Gt4Ollama/GtOllamaClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,6 @@ GtOllamaClient >> initialize [
self baseUrl: self defaultBaseUrl
]

{ #category : #accessing }
GtOllamaClient >> initializeClient [
| aClient |
aClient := ZnClient new.
aClient forJsonREST.
aClient timeout: 600.
^ aClient
]

{ #category : #accessing }
GtOllamaClient >> listModels [
^ GtOllamaListModelsClient new
Expand All @@ -193,23 +184,6 @@ GtOllamaClient >> post: aString withEntity: anEntity [
^ self checkForErrors: aClient post
]

{ #category : #accessing }
GtOllamaClient >> postStreaming: aString withEntity: anEntity [
| aClient aResult |
aClient := self initializeClient
accept: 'application/jsonl,application/x-ndjson';
contentReader: [ :entity | (NeoJSONReader on: entity readStream) upToEnd ].
aClient url: self baseUrl / aString.

aClient contents: anEntity.

aResult := aClient post.

aResult size > 0 ifTrue: [ self checkForErrors: aResult first ].

^ aResult
]

{ #category : #accessing }
GtOllamaClient >> pullModel: aString [
^ GtOllamaPullModelClient new
Expand Down
14 changes: 0 additions & 14 deletions src/Gt4Ollama/GtOllamaEmbeddingsGroup.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,3 @@ GtOllamaEmbeddingsGroup >> client: aGtOllamaClient [
client := aGtOllamaClient.
self items do: [ :anItem | anItem client: aGtOllamaClient ]
]

{ #category : #accessing }
GtOllamaEmbeddingsGroup >> gtEmbeddingsFor: aView [
<gtView>
^ aView columnedList
title: 'Embeddings';
priority: 1;
items: [ self items withIndexCollect: [ :anItem :anIndex | anIndex -> anItem ] ];
column: 'Index'
text: [ :aPair | aPair key asRopedText foreground: BrGlamorousColors disabledButtonTextColor ]
width: 50;
column: 'Size' text: [ :aPair | aPair value size ];
send: #value
]
9 changes: 0 additions & 9 deletions src/Gt4Ollama/GtOllamaModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ GtOllamaModel >> digest: anObject [
digest := anObject
]

{ #category : #accessing }
GtOllamaModel >> gtDeleteModelActionFor: anAction [
<gtAction>
^ anAction button
label: 'Delete';
icon: BrGlamorousVectorIcons cancel;
action: [ :aButton | self client deleteModel: self name ]
]

{ #category : #accessing }
GtOllamaModel >> gtPushModelActionFor: anAction [
<gtAction>
Expand Down
30 changes: 0 additions & 30 deletions src/Gt4Ollama/GtOllamaModelsGroup.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,3 @@ GtOllamaModelsGroup >> client: anObject [

self do: [ :anItem | anItem client: client ]
]

{ #category : #accessing }
GtOllamaModelsGroup >> gtModelsFor: aView [
<gtView>
^ aView columnedList
title: 'Models';
priority: 1;
items: [ self items ];
column: 'Name' text: #name;
column: 'Model' text: #model;
column: 'Modified at'
text: #modifiedAt
weight: 2;
column: 'Actions'
stencil: [ :aModel |
| aToolbar |
aToolbar := BrToolbar new
aptitude: (BrGlamorousToolbarAptitude new spacing: 5);
fitContent;
addItem: (BrButton new beTinySize
aptitude: BrGlamorousButtonWithIconAptitude;
icon: BrGlamorousVectorIcons inspect;
label: 'Get model information';
action: [ aToolbar phlow spawnObject: (self client getModelInformationFor: aModel name) ]);
addItem: (BrButton new beTinySize
aptitude: BrGlamorousButtonWithIconAptitude;
icon: BrGlamorousVectorIcons cancel;
label: 'Delete model';
action: [ self client deleteModel: aModel name ]) ]
]
25 changes: 0 additions & 25 deletions src/Gt4Ollama/GtOllamaProvider.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,6 @@ GtOllamaProvider >> client: anObject [
client := anObject
]

{ #category : #'as yet unclassified' }
GtOllamaProvider >> gtModelFileFor: aView [
<gtView>
modelfile ifNil: [ ^ aView empty ].

^ aView forward
title: 'Modelfile';
priority: 1;
object: [ modelfile ];
view: #gtContentFor:;
actionButtonIcon: BrGlamorousVectorIcons playinspect
tooltip: 'Inspect modelfile'
action: [ :aButton | aButton phlow spawnObject: modelfile ]
]

{ #category : #'as yet unclassified' }
GtOllamaProvider >> gtTriggerAssistantActionFor: anAction [
<gtAction>
^ anAction button
priority: 1;
tooltip: 'Trigger';
icon: BrGlamorousVectorIcons refresh;
action: [ self triggerAssistant ]
]

{ #category : #'as yet unclassified' }
GtOllamaProvider >> initialize [
super initialize.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Extension { #name : #Gt4LlmHomeSection }

{ #category : #'*Gt4OpenAI' }
{ #category : #'*Gt4OpenAI-GToolkit' }
Gt4LlmHomeSection >> apiKeyCard [
<gtSectionCard>
| card |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #GtLlmWardleyMapTutor,
#superclass : #GtLlmTutor,
#category : #Gt4OpenAI
#category : #'Gt4OpenAI-GToolkit'
}

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

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOllamaEmbeddingsGroup >> gtEmbeddingsFor: aView [
<gtView>
^ aView columnedList
title: 'Embeddings';
priority: 1;
items: [ self items withIndexCollect: [ :anItem :anIndex | anIndex -> anItem ] ];
column: 'Index'
text: [ :aPair | aPair key asRopedText foreground: BrGlamorousColors disabledButtonTextColor ]
width: 50;
column: 'Size' text: [ :aPair | aPair value size ];
send: #value
]
10 changes: 10 additions & 0 deletions src/Gt4OpenAI-GToolkit/GtOllamaModel.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension { #name : #GtOllamaModel }

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOllamaModel >> gtDeleteModelActionFor: anAction [
<gtAction>
^ anAction button
label: 'Delete';
icon: BrGlamorousVectorIcons cancel;
action: [ :aButton | self client deleteModel: self name ]
]
26 changes: 26 additions & 0 deletions src/Gt4OpenAI-GToolkit/GtOllamaProvider.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Extension { #name : #GtOllamaProvider }

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOllamaProvider >> gtModelFileFor: aView [
<gtView>
modelfile ifNil: [ ^ aView empty ].

^ aView forward
title: 'Modelfile';
priority: 1;
object: [ modelfile ];
view: #gtContentFor:;
actionButtonIcon: BrGlamorousVectorIcons playinspect
tooltip: 'Inspect modelfile'
action: [ :aButton | aButton phlow spawnObject: modelfile ]
]

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOllamaProvider >> gtTriggerAssistantActionFor: anAction [
<gtAction>
^ anAction button
priority: 1;
tooltip: 'Trigger';
icon: BrGlamorousVectorIcons refresh;
action: [ self triggerAssistant ]
]
17 changes: 17 additions & 0 deletions src/Gt4OpenAI-GToolkit/GtOpenAIActionMessage.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Extension { #name : #GtOpenAIActionMessage }

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOpenAIActionMessage >> gtTextFor: aView [
<gtView>
<gtLlmMessageView>
self textBlock isEmptyOrNil ifTrue: [ ^ aView empty ].

^ aView textEditor
title: 'Text';
priority: 1;
styler: (BlCompositeStyler new
stylers: {GtLlmMessageStyler new
threadMessageViewModel: (GtLlmNewThreadMessageViewModel new threadMessage: GtLlmNewThreadMessage new).
GtLlmThreadMessageStyler new annotations: self annotations});
text: [ self textBlock ]
]
9 changes: 9 additions & 0 deletions src/Gt4OpenAI-GToolkit/GtOpenAIAssistantProvider.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Extension { #name : #GtOpenAIAssistantProvider }

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOpenAIAssistantProvider >> executeWait [
future := (self runFuture
then: [ :aRun |
self updateMessages.
chat signalRunIsDone ]) await: GtOpenAIUtilities executionConfiguration
]
15 changes: 15 additions & 0 deletions src/Gt4OpenAI-GToolkit/GtOpenAIBlogPostMessage.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Extension { #name : #GtOpenAIBlogPostMessage }

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOpenAIBlogPostMessage >> gtDiffFor: aView [
<gtView>
<gtLlmMessageView>
(self contentJson includesKey: 'Post') ifFalse: [ ^ aView empty ].
^ aView diff
title: 'Diff';
priority: 2;
from: [ self chat serializer instance value asString ];
to: [ self contentJson at: 'Post' ];
actionButtonIcon: BrGlamorousVectorIcons accept
action: [ :b | self chat serializer instance updateContent: (self contentJson at: 'Post') ]
]
6 changes: 6 additions & 0 deletions src/Gt4OpenAI-GToolkit/GtOpenAIClient.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #GtOpenAIClient }

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOpenAIClient class >> withApiKeyFromClipboard [
^ self new apiKey: Clipboard clipboardText
]
15 changes: 15 additions & 0 deletions src/Gt4OpenAI-GToolkit/GtOpenAIEmbeddingsGroup.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Extension { #name : #GtOpenAIEmbeddingsGroup }

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOpenAIEmbeddingsGroup >> gtEmbeddingsFor: aView [
<gtView>
^ aView columnedList
title: 'Embeddings';
priority: 1;
items: [ self items withIndexCollect: [ :anItem :anIndex | anIndex -> anItem ] ];
column: 'Index'
text: [ :aPair | aPair key asRopedText foreground: BrGlamorousColors disabledButtonTextColor ]
width: 50;
column: 'Size' text: [ :aPair | aPair value size ];
send: #value
]
15 changes: 15 additions & 0 deletions src/Gt4OpenAI-GToolkit/GtOpenAIFile.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Extension { #name : #GtOpenAIFile }

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOpenAIFile >> gtFileFor: aView [
<gtView>
^ aView explicit
title: 'File';
priority: 1;
stencil: [ (self contents gtViewsFor: GtPhlowEmptyView new)
asElementDo: [ :e |
e
margin: (BlInsets all: 15);
background: Color white;
addAptitude: BrShadowAptitude ] ]
]
Loading

0 comments on commit 61d950f

Please sign in to comment.