Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai>
This commit is contained in:
parent
3057aaae43
commit
172d7a0088
@ -1,7 +1,7 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { JanApiRouteConfiguration, RouteConfiguration } from './configuration'
|
import { JanApiRouteConfiguration, RouteConfiguration } from './configuration'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { Model, ThreadMessage } from './../../../index'
|
import { ContentType, MessageStatus, Model, ThreadMessage } from './../../../index'
|
||||||
|
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
import { ulid } from 'ulid'
|
import { ulid } from 'ulid'
|
||||||
@ -207,17 +207,27 @@ const generateThreadId = (assistantId: string) => {
|
|||||||
|
|
||||||
export const createMessage = async (threadId: string, message: any) => {
|
export const createMessage = async (threadId: string, message: any) => {
|
||||||
const threadMessagesFileName = 'messages.jsonl'
|
const threadMessagesFileName = 'messages.jsonl'
|
||||||
// TODO: add validation
|
|
||||||
try {
|
try {
|
||||||
const msgId = ulid()
|
const msgId = ulid()
|
||||||
const createdAt = Date.now()
|
const createdAt = Date.now()
|
||||||
const threadMessage: ThreadMessage = {
|
const threadMessage: ThreadMessage = {
|
||||||
...message,
|
|
||||||
id: msgId,
|
id: msgId,
|
||||||
thread_id: threadId,
|
thread_id: threadId,
|
||||||
|
status: MessageStatus.Ready,
|
||||||
created: createdAt,
|
created: createdAt,
|
||||||
updated: createdAt,
|
updated: createdAt,
|
||||||
object: 'thread.message',
|
object: 'thread.message',
|
||||||
|
role: message.role,
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: ContentType.Text,
|
||||||
|
text: {
|
||||||
|
value: message.content,
|
||||||
|
annotations: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
const threadDirPath = join(path, 'threads', threadId)
|
const threadDirPath = join(path, 'threads', threadId)
|
||||||
@ -312,8 +322,8 @@ export const chatCompletions = async (request: any, reply: any) => {
|
|||||||
headers['Authorization'] = `Bearer ${apiKey}`
|
headers['Authorization'] = `Bearer ${apiKey}`
|
||||||
headers['api-key'] = apiKey
|
headers['api-key'] = apiKey
|
||||||
}
|
}
|
||||||
console.log(apiUrl)
|
console.debug(apiUrl)
|
||||||
console.log(JSON.stringify(headers))
|
console.debug(JSON.stringify(headers))
|
||||||
const response = await fetch(apiUrl, {
|
const response = await fetch(apiUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: headers,
|
headers: headers,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user