Skip to content

Commit

Permalink
fix: openai client sdk compatible (janhq#2096)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Feb 20, 2024
1 parent 2cbbe1b commit 6966c5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions core/src/node/api/restful/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
createMessage,
createThread,
getMessages,
retrieveMesasge,
retrieveMessage,
updateThread,
} from './helper/builder'

Expand All @@ -17,10 +17,18 @@ import { startModel, stopModel } from './helper/startStopModel'
import { ModelSettingParams } from '../../../types'

export const commonRouter = async (app: HttpServer) => {
const normalizeData = (data: any) => {
return {
object: 'list',
data,
}
}
// Common Routes
// Read & Delete :: Threads | Models | Assistants
Object.keys(JanApiRouteConfiguration).forEach((key) => {
app.get(`/${key}`, async (_request) => getBuilder(JanApiRouteConfiguration[key]))
app.get(`/${key}`, async (_request) =>
getBuilder(JanApiRouteConfiguration[key]).then(normalizeData)
)

app.get(`/${key}/:id`, async (request: any) =>
retrieveBuilder(JanApiRouteConfiguration[key], request.params.id)
Expand All @@ -34,10 +42,12 @@ export const commonRouter = async (app: HttpServer) => {
// Threads
app.post(`/threads/`, async (req, res) => createThread(req.body))

app.get(`/threads/:threadId/messages`, async (req, res) => getMessages(req.params.threadId))
app.get(`/threads/:threadId/messages`, async (req, res) =>
getMessages(req.params.threadId).then(normalizeData)
)

app.get(`/threads/:threadId/messages/:messageId`, async (req, res) =>
retrieveMesasge(req.params.threadId, req.params.messageId)
retrieveMessage(req.params.threadId, req.params.messageId)
)

app.post(`/threads/:threadId/messages`, async (req, res) =>
Expand Down
2 changes: 1 addition & 1 deletion core/src/node/api/restful/helper/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const getMessages = async (threadId: string): Promise<ThreadMessage[]> =>
}
}

export const retrieveMesasge = async (threadId: string, messageId: string) => {
export const retrieveMessage = async (threadId: string, messageId: string) => {
const messages = await getMessages(threadId)
const filteredMessages = messages.filter((m) => m.id === messageId)
if (!filteredMessages || filteredMessages.length === 0) {
Expand Down

0 comments on commit 6966c5d

Please sign in to comment.