From 43c689f6784be62746325df2d1bf1ba6b44eb800 Mon Sep 17 00:00:00 2001 From: Jakub Knejzlik Date: Thu, 4 Jul 2024 15:41:38 +0200 Subject: [PATCH] Update default order of thread listMessages --- src/thread.spec.ts | 34 +++++++++++++++++++++++++++++++++- src/thread.ts | 8 ++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/thread.spec.ts b/src/thread.spec.ts index 9a05d43..c43171a 100644 --- a/src/thread.spec.ts +++ b/src/thread.spec.ts @@ -14,6 +14,26 @@ const jira = new Assistant('Jira assistant', { describe( 'Thread', () => { + it('should list messages', async () => { + const thread = new Thread() + + await thread.appendMessage({ + role: 'assistant', + content: '1' + }) + await thread.appendMessage({ + role: 'user', + content: '2' + }) + + const messages = await thread.listMessages() + expect(messages.length).toBe(2) + + expect(messages[0]?.content[0]).toEqual({ + type: 'text', + text: { value: '1', annotations: [] } + }) + }) it('should clone thread', async () => { const thread = new Thread() @@ -21,18 +41,30 @@ describe( role: 'assistant', content: 'Hello, world!' }) + await thread.appendMessage({ + role: 'user', + content: '1+1?' + }) + await thread.appendMessage({ + role: 'assistant', + content: '2' + }) expect(thread).toBeDefined() expect(await thread.getId()).toBeDefined() const messages = await thread.listMessages() - expect(messages.length).toBe(1) + expect(messages.length).toBe(3) const thread2 = await thread.clone() const messages2 = await thread2.listMessages() expect(messages2.length).toBe(messages.length) expect(messages2[0]?.content).toEqual(messages[0]?.content) + expect(messages2[0]?.content[0]).toEqual({ + type: 'text', + text: { value: 'Hello, world!', annotations: [] } + }) }) it('should run prompt', async () => { diff --git a/src/thread.ts b/src/thread.ts index 637572d..2e09519 100644 --- a/src/thread.ts +++ b/src/thread.ts @@ -90,10 +90,10 @@ export class Thread { options?: OpenAI.Beta.Threads.Messages.MessageListParams ): Promise { const threadId = await this.getId() - const messages = await this.client.beta.threads.messages.list( - threadId, - options - ) + const messages = await this.client.beta.threads.messages.list(threadId, { + order: 'asc', + ...options + }) return messages.data }