Skip to content

Fail to create message in assistant thread #1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
zouzhenglu opened this issue Dec 25, 2023 · 1 comment
Closed
1 task done

Fail to create message in assistant thread #1023

zouzhenglu opened this issue Dec 25, 2023 · 1 comment
Assignees
Labels
API-feedback question Further information is requested

Comments

@zouzhenglu
Copy link

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

def add_messages(self, room_id, prompt, file_ids: List[str] | NotGiven = NotGiven): thread = self.get_thread(room_id) message = self.client.beta.threads.messages.create( thread_id=thread.id, role="user", content=prompt, metadata={'room_id': room_id}, file_ids=file_ids, ) mlogger.info(f'[add_messages]room_id:{room_id} thread_id:{thread.id} message_id:{message.id}') return message
I've finished my test before. But I got this error these days.
openai.BadRequestError: Error code: 400 - {'error': {'message': "Can't add messages to thread_jD1dj44APTovq48PCBZACOGV while a run run_KfVG8fSJg882VHYeewFQ2BHk is active.", 'type': 'invalid_request_error', 'param': None, 'code': None}}
I'v make sure the thread was just created .

To Reproduce

  1. get assistant from list assistant
  2. get file ids from file list
  3. create thread or get thread id from cache
  4. message create with content 、file_ids 、 metadata
  5. call run.create
  6. see error

Code snippets

def reply(self, room_id, prompt, payload: dict):
        file_ids = self._get_file_ids(payload, room_id)
        # get file ids from redis
        try:
            self.repo.add_messages(room_id, prompt, file_ids)
            self.repo.create_run(room_id)
        except Exception as e:
            mlogger.exception(e)
        yield from self._get_answer(room_id, payload)
    def get_thread(self, room_id):
        thread_id = room_id_to_thread_id.get(room_id)
        if thread_id:
            return self.client.beta.threads.retrieve(thread_id=thread_id)
        thread = self.client.beta.threads.create()
        room_id_to_thread_id.set(key=room_id, value=thread.id)
        return thread

    def add_messages(self, room_id, prompt, file_ids: List[str] | NotGiven = NotGiven):
        thread = self.get_thread(room_id)
        message = self.client.beta.threads.messages.create(
            thread_id=thread.id,
            role="user",
            content=prompt,
            metadata={'room_id': room_id},
            file_ids=file_ids,
        )
        mlogger.info(f'[add_messages]room_id:{room_id} thread_id:{thread.id}  message_id:{message.id}')
        return message

    def create_run(self, room_id):
        thread = self.get_thread(room_id)
        run = self.client.beta.threads.runs.create(
            thread_id=thread.id,
            assistant_id=self.assistant.id,
            metadata={'room_id': room_id}
        )
        mlogger.info(f'[create_run]room_id:{room_id} thread_id:{thread.id} run_id:{run.id}')
        room_id_to_run_id[room_id] = run.id
        return run

OS

win11

Python version

Python 3.11.2

Library version

openai v1.6.1

@zouzhenglu zouzhenglu added the bug Something isn't working label Dec 25, 2023
@rattrayalex rattrayalex removed the bug Something isn't working label Dec 26, 2023
@rattrayalex rattrayalex added question Further information is requested API-feedback labels Dec 26, 2023
@rattrayalex
Copy link
Collaborator

Thanks for reporting!

This sounds like an issue with the underlying OpenAI API and not the Python library, so I'm going to go ahead and close this issue.

Would you mind reposting at community.openai.com?

@rattrayalex rattrayalex closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API-feedback question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants