Skip to content

Commit

Permalink
Changes to make Ollama work in Gemstone [feenkcom/gtoolkit#4322]
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve committed Mar 4, 2025
1 parent f75a659 commit 9d6b83b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 57 deletions.
2 changes: 1 addition & 1 deletion rowan/components/Core.ston
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ RwSimpleProjectLoadComponentV2 {
'Gt4Ollama'
],
#comment : ''
}
}
2 changes: 1 addition & 1 deletion rowan/components/gemstone/Core.ston
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ RwPlatformNestedProjectLoadComponentV2 {
'Gt4Llm-Gemstone'
],
#comment : ''
}
}
2 changes: 1 addition & 1 deletion rowan/project.ston
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RwProjectSpecificationV2 {
#packageFormat : 'tonel',
#packageConvention : 'RowanHybrid',
#comment : ''
}
}
7 changes: 7 additions & 0 deletions src/Gt4Llm-Gemstone/ExecBlock.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : 'ExecBlock' }

{ #category : '*Gt4Llm-Gemstone' }
ExecBlock >> doWhileTrue: aBlock [
self value.
^ aBlock whileTrue: self
]
30 changes: 15 additions & 15 deletions src/Gt4Llm/GtLlmEntity.class.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Class {
#name : #GtLlmEntity,
#superclass : #Object,
#name : 'GtLlmEntity',
#superclass : 'Object',
#instVars : [
'rawData',
'client'
],
#category : #Gt4Llm
#category : 'Gt4Llm'
}

{ #category : #accessing }
{ #category : 'accessing' }
GtLlmEntity class >> from: aDictionary [
| entity |
(aDictionary isKindOf: self) ifTrue: [ ^ aDictionary ].
Expand All @@ -20,29 +20,29 @@ GtLlmEntity class >> from: aDictionary [
^ entity
]

{ #category : #accessing }
{ #category : 'accessing' }
GtLlmEntity class >> serializationProperties [
^ #()
]

{ #category : #accessing }
{ #category : 'accessing' }
GtLlmEntity >> client [
^ client
]

{ #category : #accessing }
{ #category : 'accessing' }
GtLlmEntity >> client: anObject [
client := anObject
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtLlmEntity >> deserializeTime: anObject [
^ (anObject isNil or: [ anObject isKindOf: DateAndTime ])
ifTrue: [ anObject ]
ifFalse: [ DateAndTime fromUnixTime: anObject ]
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtLlmEntity >> from: aDictionary [
self rawData: aDictionary.

Expand All @@ -53,7 +53,7 @@ GtLlmEntity >> from: aDictionary [
withArguments: {aDictionary at: aPair key ifAbsent: [ nil ]} ]
]

{ #category : #accessing }
{ #category : 'accessing' }
GtLlmEntity >> gtViewRawDataFor: aView [
<gtView>
self rawData ifNil: [^ aView empty ].
Expand All @@ -65,7 +65,7 @@ GtLlmEntity >> gtViewRawDataFor: aView [
view: #gtItemsFor:
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtLlmEntity >> merge: anotherEntity [
self rawData: anotherEntity rawData.

Expand All @@ -77,19 +77,19 @@ GtLlmEntity >> merge: anotherEntity [
ifNotNil: [ self perform: (aPair value , ':') asSymbol withArguments: {aValue} ] ]
]

{ #category : #accessing }
{ #category : 'accessing' }
GtLlmEntity >> rawData [
^ rawData
]

{ #category : #accessing }
{ #category : 'accessing' }
GtLlmEntity >> rawData: anObject [
rawData := anObject
]

{ #category : #accessing }
{ #category : 'accessing' }
GtLlmEntity >> serialize [
^ (self class serializationProperties
collect: [ :aPair | aPair key -> (self perform: aPair value) ]) asDictionary
reject: #isNil
reject: [ :aValue | aValue isNil ]
]
37 changes: 19 additions & 18 deletions src/Gt4Ollama/GtOllamaCompleteChatAPIClient.class.st
Original file line number Diff line number Diff line change
@@ -1,75 +1,76 @@
Class {
#name : #GtOllamaCompleteChatAPIClient,
#superclass : #GtLlmEndpointClient,
#name : 'GtOllamaCompleteChatAPIClient',
#superclass : 'GtLlmEndpointClient',
#instVars : [
'messages',
'model',
'format',
'tools'
],
#category : #Gt4Ollama
#category : 'Gt4Ollama'
}

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> entity [
| entity |
entity := {'stream' -> false.
'model' -> self model.
'messages' -> (self messages collect: #serialize)} asDictionary.
entity := {('stream' -> false).
('model' -> self model).
('messages' -> (self messages collect: [ :aMessage | aMessage serialize ]))}
asDictionary.

self format ifNotNil: [ entity at: 'format' put: self format ].
self tools
ifNotNil: [ entity at: 'tools' put: (self tools collect: #serialize) ].
ifNotNil: [ entity at: 'tools' put: (self tools collect: #'serialize') ].

^ entity
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> format [
^ format
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> format: anObject [
format := anObject
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> messages [
^ messages
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> messages: anObject [
messages := anObject
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> model [
^ model
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> model: anObject [
model := anObject
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> request [
^ self client post: '/chat' withEntity: self entity
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> serializationClass [
^ GtOllamaThreadMessage
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> tools [
^ tools
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaCompleteChatAPIClient >> tools: anObject [
tools := anObject
]
48 changes: 27 additions & 21 deletions src/Gt4Ollama/GtOllamaProvider.class.st
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
Class {
#name : #GtOllamaProvider,
#superclass : #GtLlmProvider,
#name : 'GtOllamaProvider',
#superclass : 'GtLlmProvider',
#instVars : [
'assistantWorking',
'model',
'client',
'modelfile',
'tools'
],
#category : #Gt4Ollama
#category : 'Gt4Ollama'
}

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> addTool: aTool [
tools add: aTool
]

{ #category : #accessing }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> asyncWait [
self triggerAssistant
]

{ #category : 'accessing' }
GtOllamaProvider >> client [
^ client
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaProvider >> client: anObject [
client := anObject
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> initialize [
super initialize.

Expand All @@ -37,12 +42,12 @@ GtOllamaProvider >> initialize [
tools := GtLlmToolsGroup new
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> initializeClient [
client := GtOllamaClient new
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> instructions: aString [
| internalModelName modelFile |
internalModelName := 'gt-tutor-' , self model , '-' , self uuidClass new asString.
Expand All @@ -57,30 +62,30 @@ GtOllamaProvider >> instructions: aString [
self model: internalModelName
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaProvider >> model [
^ model
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaProvider >> model: anObject [
model := anObject.

"ignore pulling errors that occur on local models. worst case is we’ll get an issue later when trying to chat"
[ self client pullModel: model ] on: Error do: [ ]
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaProvider >> modelfile [
^ modelfile
]

{ #category : #accessing }
{ #category : 'accessing' }
GtOllamaProvider >> modelfile: anObject [
modelfile := anObject
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> performToolCallsFor: aResult [
aResult toolCalls
do: [ :aToolCall |
Expand All @@ -92,23 +97,24 @@ GtOllamaProvider >> performToolCallsFor: aResult [
output: toolOutput) ]
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> sendAssistantMessage: aMessage [
userMessageClass adoptInstance: aMessage.
aMessage role: 'user'.
self chat addMessage: aMessage.
| userMessage |
userMessage := userMessageClass new merge: aMessage.
userMessage role: 'user'.
self chat addMessage: userMessage.

[ self triggerAssistant ] asAsyncPromise
self asyncWait
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> status [
^ assistantWorking
ifTrue: [ GtLlmAssistantChatWorkingStatus new ]
ifFalse: [ GtLlmAssistantChatReadyStatus new ]
]

{ #category : #'as yet unclassified' }
{ #category : 'as yet unclassified' }
GtOllamaProvider >> triggerAssistant [
| result |
assistantWorking := true.
Expand Down
4 changes: 4 additions & 0 deletions src/properties.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
#format : 'tonel',
#convention : 'RowanHybrid'
}

0 comments on commit 9d6b83b

Please sign in to comment.