Skip to content

Commit

Permalink
Ensure ifNotNil: receives blocks [feenkcom/gtoolkit#4322]
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve committed Mar 3, 2025
1 parent 0174b02 commit 48f1e06
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/Gt4Llm-GToolkit/GtLlmActionTemplateElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ GtLlmActionTemplateElement >> exampleStringFor: anObject [
ifTrue: [ '''Action'' -> ''' asRopedText , tutorNameAttribute codeEditor
, '''' asRopedText ]
ifFalse: [ (aPair key storeString , ' -> '
, (aPair value ifNil: [ 'nil' ] ifNotNil: #storeString)) asRopedText ] ]
, (aPair value ifNil: [ 'nil' ] ifNotNil: [ :aValue | aValue storeString ])) asRopedText ] ]
separatedBy: '. ' asRopedText.

finalRope := '' asRopedText.
Expand All @@ -95,7 +95,7 @@ GtLlmActionTemplateElement >> finalExampleStringFor: anObject [
ifTrue: [ '''Action'' -> ''' asRopedText , tutorNameAttribute string
, '''' asRopedText ]
ifFalse: [ (aPair key storeString , ' -> '
, (aPair value ifNil: [ 'nil' ] ifNotNil: #storeString)) asRopedText ] ]
, (aPair value ifNil: [ 'nil' ] ifNotNil: [ :aValue | aValue storeString ])) asRopedText ] ]
separatedBy: '. ' asRopedText.

finalRope := '' asRopedText.
Expand Down
3 changes: 2 additions & 1 deletion src/Gt4Llm/GtLlmActionMessage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ GtLlmActionMessage class >> defaultRole [
GtLlmActionMessage >> actionModel [
^ (self chat tutor actionNamed: self action)
ifNil: [ self isUserRole
ifTrue: [ (self chat descendantOf: self) ifNotNil: #actionModel ]
ifTrue: [ (self chat descendantOf: self)
ifNotNil: [ :aDescendant | aDescendant actionModel ] ]
ifFalse: [ nil ] ]
]

Expand Down
20 changes: 7 additions & 13 deletions src/Gt4Llm/GtLlmTutorAction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ GtLlmTutorAction >> initialize [
self name: ''.
self description: ''.

definingMethod := (thisContext stack at: 3) blocDefiningMethod.
SystemAnnouncer uniqueInstance weak
when: MethodModified
send: #onMethodModified:
to: self
definingMethod := self initializeMethod
]

{ #category : #accessing }
GtLlmTutorAction >> initializeMethod [
^ (thisContext stack at: 3) blocDefiningMethod
]

{ #category : #accessing }
Expand All @@ -201,13 +202,6 @@ GtLlmTutorAction >> name: anObject [
self format isEmptyOrNil ifTrue: [ self format: name ]
]

{ #category : #accessing }
GtLlmTutorAction >> onMethodModified: aMethodModified [
definingMethod = aMethodModified ifFalse: [ ^ self ].

self become: aMethodModified value
]

{ #category : #accessing }
GtLlmTutorAction >> onTutorChanged [
self examples do: [ :anExample | anExample verify resolveReferences ]
Expand Down Expand Up @@ -262,7 +256,7 @@ GtLlmTutorAction >> priority: anObject [

{ #category : #'as yet unclassified' }
GtLlmTutorAction >> removeFromSystem [
self definingMethod ifNotNil: #removeFromSystem
self definingMethod ifNotNil: [ :aMethod | aMethod removeFromSystem ]
]

{ #category : #accessing }
Expand Down
6 changes: 4 additions & 2 deletions src/Gt4Llm/GtLlmTutorActionExample.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ GtLlmTutorActionExample >> asExpressionSource [
input: { '
, ('. '
join: (self input associations
collect: [ :aPair | '''' , aPair key , ''' -> ' , (aPair value ifNil: [ 'nil' ] ifNotNil: #storeString) ]))
collect: [ :aPair |
'''' , aPair key , ''' -> '
, (aPair value ifNil: [ 'nil' ] ifNotNil: [ :aValue | aValue storeString ]) ]))
, ' } asDictionary;
output: { '
, ('. '
join: (self output associations
collect: [ :aPair |
'''' , aPair key , ''' -> '
, (aPair value ifNil: [ 'nil' ] ifNotNil: #storeString) ]))
, (aPair value ifNil: [ 'nil' ] ifNotNil:[ :aValue | aValue storeString ]) ]))
, ' } asDictionary'
]

Expand Down
9 changes: 7 additions & 2 deletions src/Gt4Llm/GtLlmTutorFormatDescription.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ GtLlmTutorFormatDescription >> initialize [

referencingActions := OrderedCollection new.

definingMethod := (thisContext stack at: 3) blocDefiningMethod
definingMethod := self initializeMethod
]

{ #category : #accessing }
GtLlmTutorFormatDescription >> initializeMethod [
^ (thisContext stack at: 4) blocDefiningMethod
]

{ #category : #accessing }
Expand Down Expand Up @@ -189,7 +194,7 @@ GtLlmTutorFormatDescription >> priority: anObject [

{ #category : #'as yet unclassified' }
GtLlmTutorFormatDescription >> removeFromSystem [
self definingMethod ifNotNil: #removeFromSystem
self definingMethod ifNotNil: [ :aMethod | aMethod removeFromSystem ]
]

{ #category : #accessing }
Expand Down
3 changes: 2 additions & 1 deletion src/Gt4Llm/TGtActionMessage.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Trait {
TGtActionMessage >> actionModel [
^ (self chat tutor actionNamed: self action)
ifNil: [ self isUserRole
ifTrue: [ (self chat descendantOf: self) ifNotNil: #actionModel ]
ifTrue: [ (self chat descendantOf: self)
ifNotNil: [ :aDescendant | aDescendant actionModel ] ]
ifFalse: [ nil ] ]
]

Expand Down
2 changes: 1 addition & 1 deletion src/Gt4Ollama/GtOllamaThreadMessage.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ GtOllamaThreadMessage >> evalDuration [

{ #category : #accessing }
GtOllamaThreadMessage >> evalDuration: anObject [
evalDuration := anObject ifNotNil: #nanoSeconds
evalDuration := anObject ifNotNil: [ :aValue | aValue nanoseconds ]
]

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

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOpenAIClient >> initializeClient [
| aClient |
aClient := ZnClient new.
aClient forJsonREST.
aClient headerAt: 'OpenAI-Beta' put: 'assistants=v2'.
aClient timeout: 60.
aClient setBearerAuthentication: apiKey.
aClient beOneShot.
^ aClient
]

{ #category : #'*Gt4OpenAI-GToolkit' }
GtOpenAIClient class >> withApiKeyFromClipboard [
^ self new apiKey: Clipboard clipboardText
Expand Down
2 changes: 1 addition & 1 deletion src/Gt4OpenAI/GtOpenAIAnnotationsGroup.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ GtOpenAIAnnotationsGroup >> gtAnnotationsFor: aView [
column: 'Text' text: #text;
column: 'Type' text: #type;
column: 'File'
text: [ :anAnnotation | anAnnotation file ifNil: [ '' ] ifNotNil: #filename ]
text: [ :anAnnotation | anAnnotation file ifNil: [ '' ] ifNotNil: [ :aFile | aFile filename ] ]
]
12 changes: 0 additions & 12 deletions src/Gt4OpenAI/GtOpenAIClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,6 @@ GtOpenAIClient >> initialize [
self baseUrl: self defaultBaseUrl
]

{ #category : #accessing }
GtOpenAIClient >> initializeClient [
| aClient |
aClient := ZnClient new.
aClient forJsonREST.
aClient headerAt: 'OpenAI-Beta' put: 'assistants=v2'.
aClient timeout: 60.
aClient setBearerAuthentication: apiKey.
aClient beOneShot.
^ aClient
]

{ #category : #accessing }
GtOpenAIClient >> listAssistants [
^ GtOpenAIListAssistantsAPIClient new
Expand Down

0 comments on commit 48f1e06

Please sign in to comment.