From 81f80e1722dfcf90eda7d8235e6d23966e896008 Mon Sep 17 00:00:00 2001 From: numexai Date: Wed, 23 Sep 2026 23:32:23 +0000 Subject: [PATCH] Sohbette messages dizisini message/history alanlarina da cevir; arama parametresini belgele --- src/resources/chat.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/resources/chat.js b/src/resources/chat.js index 87d3c9b..61f0921 100644 --- a/src/resources/chat.js +++ b/src/resources/chat.js @@ -1,9 +1,27 @@ +// Numex /chat uç noktası { message, history } bekler; OpenAI tarzı { messages } da +// verilebilsin diye son kullanıcı mesajını ve önceki mesajları bu alanlara da kopyalarız. +function withMessageFields(params = {}) { + if (params.message || !Array.isArray(params.messages) || !params.messages.length) return params; + let lastUser = -1; + for (let i = params.messages.length - 1; i >= 0; i--) { + if (params.messages[i] && params.messages[i].role === 'user') { lastUser = i; break; } + } + if (lastUser === -1) return params; + const content = params.messages[lastUser].content; + const message = typeof content === 'string' + ? content + : Array.isArray(content) ? content.map((c) => (c && c.text) || '').join('') : ''; + const history = params.history || params.messages.slice(0, lastUser); + return { ...params, message, history }; +} + class ChatCompletions { constructor(client) { this.client = client; } async create(params) { + params = withMessageFields(params); // If stream is requested, use the appropriate streaming endpoint/method if (params.stream) { return this.client.post('/chat/stream', params, { stream: true });