@@ -169,38 +169,27 @@ D.prepare_payload = function(messages, model, provider)
169
169
return payload
170
170
end
171
171
172
- if provider == " ollama" then
172
+ if provider == " xai" then
173
+ local system = " "
174
+ local i = 1
175
+ while i < # messages do
176
+ if messages [i ].role == " system" then
177
+ system = system .. messages [i ].content .. " \n "
178
+ table.remove (messages , i )
179
+ else
180
+ i = i + 1
181
+ end
182
+ end
183
+
173
184
local payload = {
174
185
model = model .model ,
175
186
stream = true ,
176
187
messages = messages ,
188
+ system = system ,
189
+ max_tokens = model .max_tokens or 4096 ,
190
+ temperature = math.max (0 , math.min (2 , model .temperature or 1 )),
191
+ top_p = math.max (0 , math.min (1 , model .top_p or 1 )),
177
192
}
178
-
179
- if model .think ~= nil then
180
- payload .think = model .think
181
- end
182
-
183
- local options = {}
184
- if model .temperature then
185
- options .temperature = math.max (0 , math.min (2 , model .temperature ))
186
- end
187
- if model .top_p then
188
- options .top_p = math.max (0 , math.min (1 , model .top_p ))
189
- end
190
- if model .min_p then
191
- options .min_p = math.max (0 , math.min (1 , model .min_p ))
192
- end
193
- if model .num_ctx then
194
- options .num_ctx = model .num_ctx
195
- end
196
- if model .top_k then
197
- options .top_k = model .top_k
198
- end
199
-
200
- if next (options ) then
201
- payload .options = options
202
- end
203
-
204
193
return payload
205
194
end
206
195
@@ -454,6 +443,14 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
454
443
endpoint = render .template_replace (endpoint , " {{model}}" , payload .model )
455
444
elseif provider == " ollama" then
456
445
headers = {}
446
+ elseif provider == " xai" then
447
+ -- currently xai only uses bearer token for authentication.
448
+ -- since I cannot sure its going to be that way for long time
449
+ -- branching out as another condition.
450
+ headers = {
451
+ " -H" ,
452
+ " Authorization: Bearer " .. bearer ,
453
+ }
457
454
else -- default to openai compatible headers
458
455
headers = {
459
456
" -H" ,
0 commit comments