Skip to content

Commit

Permalink
fix(Messages): janhq#1434 create message via api does not display on …
Browse files Browse the repository at this point in the history
…app correctly (janhq#1479)

Signed-off-by: James <[email protected]>
Co-authored-by: James <[email protected]>
  • Loading branch information
namchuai and James authored Jan 9, 2024
1 parent 3057aaa commit 172d7a0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions core/src/node/api/common/builder.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 172d7a0

Please sign in to comment.