class_docstr: An experimental AutoGen agent class that leverages the OpenAI Assistant API for conversational capabilities.
  This agent is unique in its reliance on the OpenAI Assistant for state management, differing from other agents like ConversableAgent.
class_docstr_tok: ["An","experimental","AutoGen","agent","class","that","leverages","the","OpenAI","Assistant","API","for","conversational","capabilities",".","This","agent","is","unique","in","its","reliance","on","the","OpenAI","Assistant","for","state","management",",","differing","from","other","agents","like","ConversableAgent","."]
docstr: Waits for a run to complete or reach a final state.
  
  Args:
      run_id: The ID of the run.
      thread_id: The ID of the thread associated with the run.
  
  Returns:
      The updated run object after completion or reaching a final state.
docstr_tok: ["Waits","for","a","run","to","complete","or","reach","a","final","state",".","Args",":","run_id",":","The","ID","of","the","run",".","thread_id",":","The","ID","of","the","thread","associated","with","the","run",".","Returns",":","The","updated","run","object","after","completion","or","reaching","a","final","state","."]
code: def _wait_for_run(self, run_id: str, thread_id: str) -> Any:
      """
      Waits for a run to complete or reach a final state.
  
      Args:
          run_id: The ID of the run.
          thread_id: The ID of the thread associated with the run.
  
      Returns:
          The updated run object after completion or reaching a final state.
      """
      in_progress = True
      while in_progress:
          run = self._openai_client.beta.threads.runs.retrieve(
              run_id, thread_id=thread_id
          )
          in_progress = run.status in ("in_progress", "queued")
          if in_progress:
              time.sleep(
                  self.llm_config.get("check_every_ms", 1000) / 1000
              )
      return run
  
imports: from collections import defaultdict
  import openai
  import json
  import time
  import logging
  from autogen import OpenAIWrapper
  from autogen.oai.openai_utils import retrieve_assistants_by_name
  from autogen.agentchat.agent import Agent
  from autogen.agentchat.assistant_agent import ConversableAgent
  from autogen.agentchat.assistant_agent import AssistantAgent
  from typing import Dict, Optional, Union, List, Tuple, Any
label_desc: Use image node_id 4 for calling the GPTAssistantAgent obj's underlying member method code with example usage: obj._wait_for_run(run_id, thread_id) and returns: run