Skip to content

Commit

Permalink
add test for num_ctx / add prequery for request construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Marpioux committed Nov 4, 2024
1 parent d50f3b7 commit a0b4473
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/Pharo-Ollama-Tests/OllamaAPITest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ OllamaAPITest >> setUp [
ollama := OllamaAPI new.
]

{ #category : 'tests' }
OllamaAPITest >> testNumTokenVariables [

| ollamatest |
ollamatest := OllamaAPI new.
self assert: (ollamatest num_ctx isNil).
self assert: (((ollamatest prequery: 'test') at: #options) isEmptyOrNil).
ollamatest num_ctx: 50.
self assert: (ollamatest num_ctx == 50).
self assert: (((ollamatest prequery: 'test') at: #options) isNotEmpty).
]

{ #category : 'running' }
OllamaAPITest >> testOllamaAPIHasDefaultModelInitialized [

Expand Down
35 changes: 23 additions & 12 deletions src/Pharo-Ollama/OllamaAPI.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ OllamaAPI >> port: anObject [
port := anObject
]

{ #category : 'api' }
OllamaAPI >> prequery: aTextQuery [

| paramDic optionsDic |
paramDic := Dictionary new.
paramDic at: #model put: self model fullName.
paramDic at: #prompt put: (self buildQuery: aTextQuery).
paramDic at: #stream put: self stream.
self format ifNotNil: [ :f | paramDic at: #format put: f ].
self addParameterTo: paramDic.

self num_ctx ifNotNil: [
optionsDic := Dictionary new.
optionsDic at: #num_ctx put: self num_ctx.
paramDic at: #options put: optionsDic.
].

^ paramDic

]

{ #category : 'api' }
OllamaAPI >> pull [
"Pull the model linked to this API"
Expand All @@ -211,7 +232,7 @@ OllamaAPI >> pull [
{ #category : 'api' }
OllamaAPI >> query: aTextQuery [

| znClient paramDic writer optionsDic |
| znClient writer |
znClient := ZnClient new.
writer := ZnUtils defaultJSONWriter.
znClient
Expand All @@ -221,18 +242,8 @@ OllamaAPI >> query: aTextQuery [
znClient port: self port.
znClient path: 'api/generate'.

paramDic := Dictionary new.
paramDic at: #model put: self model fullName.
paramDic at: #prompt put: (self buildQuery: aTextQuery).
paramDic at: #stream put: self stream.
self format ifNotNil: [ :f | paramDic at: #format put: f ].
self addParameterTo: paramDic.

optionsDic := Dictionary new.
optionsDic at: #num_ctx put: self num_ctx.
paramDic at: #options put: optionsDic.

znClient contents: paramDic.
znClient contents: (self prequery: aTextQuery).

self stream
ifTrue: [
Expand Down

0 comments on commit a0b4473

Please sign in to comment.