Skip to content

Commit

Permalink
Add num_ctx variable to manage tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Marpioux committed Oct 30, 2024
1 parent 996bf15 commit d50f3b7
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/Pharo-Ollama/OllamaAPI.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Class {
'num_predict',
'top_k',
'top_p',
'format'
'format',
'num_ctx'
],
#classInstVars : [
'defaultModel'
Expand Down Expand Up @@ -154,6 +155,18 @@ OllamaAPI >> model: anObject [
model := anObject
]

{ #category : 'accessing' }
OllamaAPI >> num_ctx [

^ num_ctx
]

{ #category : 'accessing' }
OllamaAPI >> num_ctx: anObject [

num_ctx := anObject
]

{ #category : 'accessing' }
OllamaAPI >> num_predict [

Expand Down Expand Up @@ -198,36 +211,40 @@ OllamaAPI >> pull [
{ #category : 'api' }
OllamaAPI >> query: aTextQuery [

| znClient paramDic writer |
| znClient paramDic writer optionsDic |
znClient := ZnClient new.
writer := ZnUtils defaultJSONWriter.
znClient
accept: ZnMimeType applicationJson;
contentWriter: [ :data | ZnEntity json: (writer toString: data) ].
accept: ZnMimeType applicationJson;
contentWriter: [ :data | ZnEntity json: (writer toString: data) ].
znClient host: self host.
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.

self addParameterTo: paramDic.
znClient contents: paramDic.

self stream
ifTrue: [
znClient streaming: true.
^ znClient post ]
ifFalse: [
| reader |
znClient forJsonREST.
reader := ZnUtils defaultJSONReader.
znClient contentReader: [ :entity |
reader fromString: entity contents ].
^ znClient post at: #response ]
self stream
ifTrue: [
znClient streaming: true.
^ znClient post ]
ifFalse: [
| reader |
znClient forJsonREST.
reader := ZnUtils defaultJSONReader.
znClient contentReader: [ :entity |
reader fromString: entity contents ].
^ znClient post at: #response ].
]

{ #category : 'accessing' }
Expand Down

0 comments on commit d50f3b7

Please sign in to comment.