Skip to content

Commit

Permalink
Update default order of thread listMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubknejzlik committed Jul 4, 2024
1 parent 98ffe33 commit 43c689f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
34 changes: 33 additions & 1 deletion src/thread.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,57 @@ 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()

await thread.appendMessage({
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 () => {
Expand Down
8 changes: 4 additions & 4 deletions src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export class Thread {
options?: OpenAI.Beta.Threads.Messages.MessageListParams
): Promise<OpenAI.Beta.Threads.Messages.Message[]> {
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
}

Expand Down

0 comments on commit 43c689f

Please sign in to comment.