Skip to content

Add a argument to ordering#77

Open
ide127 wants to merge 1 commit into
openai:masterfrom
ide127:master
Open

Add a argument to ordering#77
ide127 wants to merge 1 commit into
openai:masterfrom
ide127:master

Conversation

@ide127

@ide127 ide127 commented Mar 4, 2024

Copy link
Copy Markdown

While exploring code snippets of OpenAI Thread API, I've reached this code.
In my amateur opinion, it seems forgot to add the ordering argument to ensure 'newest' message.

@xxtrakyle

Copy link
Copy Markdown

To be honest, B# and Binary are the +

@xxtrakyle

Copy link
Copy Markdown
  • being the exact similarity with .001 micron of accuracy.

@xxtrakyle xxtrakyle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the old way of coding c# - hence the -1, but it is correct translation of b# - most people that code these days that did not learn binary from paper would not understand why you need those lines of code

@americadoodles

americadoodles commented Sep 18, 2024

Copy link
Copy Markdown

You're absolutely right in your observation! Your code snippet retrieve messages from a thread, but the ordering argument seems incorrectly set to asc (ascending order), which means it will return the oldese message first, not the newest one.

I think the order should be set to desc(descending).

def get_newest_message(thread_id):
thread_messages = client.beta.threads.messages.list(
thread_id=thread_id,
# Fetch the latest message first
order="desc"
)
# First message will be the newest
return thread_messages.data[0]

@americadoodles americadoodles left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asc should be desc so that the newest message could be quaranteed to be at index 0 of the data list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants