Skip to content

Commit

Permalink
fix: fetch threads and messages without limiting (janhq#4304)
Browse files Browse the repository at this point in the history
* fix: threads and messages are cutoff

* fix: threads sorting

* chore: bump cortex latest release and app version
  • Loading branch information
louis-jan authored Dec 20, 2024
1 parent 1acbb33 commit 4e43f97
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions extensions/conversational-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class CortexConversationalExtension extends ConversationalExtensi
async listThreads(): Promise<Thread[]> {
return this.queue.add(() =>
ky
.get(`${API_URL}/v1/threads`)
.get(`${API_URL}/v1/threads?limit=-1`)
.json<ThreadList>()
.then((e) => e.data)
) as Promise<Thread[]>
Expand Down Expand Up @@ -133,7 +133,7 @@ export default class CortexConversationalExtension extends ConversationalExtensi
async listMessages(threadId: string): Promise<ThreadMessage[]> {
return this.queue.add(() =>
ky
.get(`${API_URL}/v1/threads/${threadId}/messages?order=asc`)
.get(`${API_URL}/v1/threads/${threadId}/messages?order=asc&limit=-1`)
.json<MessageList>()
.then((e) => e.data)
) as Promise<ThreadMessage[]>
Expand All @@ -147,7 +147,7 @@ export default class CortexConversationalExtension extends ConversationalExtensi
*/
async getThreadAssistant(threadId: string): Promise<ThreadAssistantInfo> {
return this.queue.add(() =>
ky.get(`${API_URL}/v1/assistants/${threadId}`).json<ThreadAssistantInfo>()
ky.get(`${API_URL}/v1/assistants/${threadId}?limit=-1`).json<ThreadAssistantInfo>()
) as Promise<ThreadAssistantInfo>
}
/**
Expand Down
2 changes: 1 addition & 1 deletion extensions/inference-cortex-extension/bin/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.5-rc2
1.0.5
2 changes: 1 addition & 1 deletion extensions/model-extension/src/cortex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class CortexAPI implements ICortexAPI {
*/
getModels(): Promise<Model[]> {
return this.queue
.add(() => ky.get(`${API_URL}/v1/models`).json<ModelList>())
.add(() => ky.get(`${API_URL}/v1/models?limit=-1`).json<ModelList>())
.then((e) =>
typeof e === 'object' ? e.data.map((e) => this.transformModel(e)) : []
)
Expand Down
1 change: 1 addition & 0 deletions web/containers/Providers/ModelHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export default function ModelHandler() {
const metadata = {
...thread.metadata,
...(messageContent && { lastMessage: messageContent }),
updated_at: Date.now(),
}

updateThread({
Expand Down
1 change: 1 addition & 0 deletions web/hooks/useCreateNewThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const useCreateNewThread = () => {
updated: createdAt,
metadata: {
title: 'New Thread',
updated_at: Date.now(),
},
}

Expand Down
7 changes: 6 additions & 1 deletion web/hooks/useThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ const useThreads = () => {

useEffect(() => {
const getThreads = async () => {
const localThreads = await getLocalThreads()
const localThreads = (await getLocalThreads()).sort((a, b) => {
return ((a.metadata?.updated_at as number) ?? 0) >
((b.metadata?.updated_at as number) ?? 0)
? -1
: 1
})
const localThreadStates: Record<string, ThreadState> = {}
const threadModelParams: Record<string, ModelParams> = {}

Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@janhq/web",
"version": "0.5.11",
"version": "0.5.12",
"private": true,
"homepage": "./",
"scripts": {
Expand Down

0 comments on commit 4e43f97

Please sign in to comment.