lemura 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -206,10 +206,36 @@ var OpenAICompatibleAdapter = class {
206
206
  if (r === "content_filter" || r === "error") return "error";
207
207
  return "stop";
208
208
  }
209
+ toOpenAIMessages(messages) {
210
+ return messages.map((msg) => {
211
+ if (msg.role === "assistant" && msg.toolCalls?.length) {
212
+ return {
213
+ role: "assistant",
214
+ content: msg.content || null,
215
+ tool_calls: msg.toolCalls.map((tc) => ({
216
+ id: tc.id,
217
+ type: "function",
218
+ function: {
219
+ name: tc.name,
220
+ arguments: typeof tc.arguments === "string" ? tc.arguments : JSON.stringify(tc.arguments)
221
+ }
222
+ }))
223
+ };
224
+ }
225
+ if (msg.role === "tool") {
226
+ return {
227
+ role: "tool",
228
+ tool_call_id: msg.name,
229
+ content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
230
+ };
231
+ }
232
+ return msg;
233
+ });
234
+ }
209
235
  buildPayload(request) {
210
236
  const payload = {
211
237
  model: request.model || this.defaultModel,
212
- messages: request.messages
238
+ messages: this.toOpenAIMessages(request.messages)
213
239
  };
214
240
  if (request.maxTokens !== void 0) payload.max_tokens = request.maxTokens;
215
241
  if (request.temperature !== void 0) payload.temperature = request.temperature;