From 172d7a008862802c01c9d53089f13e1e1baf96a1 Mon Sep 17 00:00:00 2001 From: NamH Date: Tue, 9 Jan 2024 23:11:51 +0700 Subject: [PATCH] fix(Messages): #1434 create message via api does not display on app correctly (#1479) Signed-off-by: James Co-authored-by: James --- core/src/node/api/common/builder.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/core/src/node/api/common/builder.ts b/core/src/node/api/common/builder.ts index 54ce9159f..2d9f315a3 100644 --- a/core/src/node/api/common/builder.ts +++ b/core/src/node/api/common/builder.ts @@ -1,7 +1,7 @@ import fs from 'fs' import { JanApiRouteConfiguration, RouteConfiguration } from './configuration' import { join } from 'path' -import { Model, ThreadMessage } from './../../../index' +import { ContentType, MessageStatus, Model, ThreadMessage } from './../../../index' import fetch from 'node-fetch' import { ulid } from 'ulid' @@ -207,17 +207,27 @@ const generateThreadId = (assistantId: string) => { export const createMessage = async (threadId: string, message: any) => { const threadMessagesFileName = 'messages.jsonl' - // TODO: add validation + try { const msgId = ulid() const createdAt = Date.now() const threadMessage: ThreadMessage = { - ...message, id: msgId, thread_id: threadId, + status: MessageStatus.Ready, created: createdAt, updated: createdAt, object: 'thread.message', + role: message.role, + content: [ + { + type: ContentType.Text, + text: { + value: message.content, + annotations: [], + }, + }, + ], } const threadDirPath = join(path, 'threads', threadId) @@ -312,8 +322,8 @@ export const chatCompletions = async (request: any, reply: any) => { headers['Authorization'] = `Bearer ${apiKey}` headers['api-key'] = apiKey } - console.log(apiUrl) - console.log(JSON.stringify(headers)) + console.debug(apiUrl) + console.debug(JSON.stringify(headers)) const response = await fetch(apiUrl, { method: 'POST', headers: headers,