Skip to content
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

Indentation error in Python example in "Step 4: Create a Run" of Quickstart Documentation #2028

Open
1 task done
Programmer-RD-AI opened this issue Jan 18, 2025 · 0 comments
Labels

Comments

@Programmer-RD-AI
Copy link

Programmer-RD-AI commented Jan 18, 2025

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

The Python example provided in the "Step 4: Create a Run" section of the [Quickstart documentation](https://platform.openai.com/docs/assistants/quickstart#step-4-create-a-run) contains incorrect indentation, which leads to a IndentationError when executed as-is.

Specifically, the methods within the EventHandler class are not properly indented under the class definition. This may confuse users and lead to runtime errors.

To Reproduce

  1. Visit the [Quickstart documentation, Step 4](https://platform.openai.com/docs/assistants/quickstart#step-4-create-a-run).
  2. Copy the provided Python code snippet.
  3. Attempt to execute the code in a Python environment.
  4. Observe the IndentationError caused by misaligned methods in the EventHandler class.

Code snippets

# Here is the problematic snippet:  


class EventHandler(AssistantEventHandler):    
@override
def on_text_created(self, text) -> None:
  print(f"\nassistant > ", end="", flush=True)
    
@override
def on_text_delta(self, delta, snapshot):
  print(delta.value, end="", flush=True)
    
def on_tool_call_created(self, tool_call):
  print(f"\nassistant > {tool_call.type}\n", flush=True)

def on_tool_call_delta(self, delta, snapshot):
  if delta.type == 'code_interpreter':
    if delta.code_interpreter.input:
      print(delta.code_interpreter.input, end="", flush=True)
    if delta.code_interpreter.outputs:
      print(f"\n\noutput >", flush=True)
      for output in delta.code_interpreter.outputs:
        if output.type == "logs":
          print(f"\n{output.logs}", flush=True)


# Correctly indented version:  


class EventHandler(AssistantEventHandler):    
    @override
    def on_text_created(self, text) -> None:
        print(f"\nassistant > ", end="", flush=True)
    
    @override
    def on_text_delta(self, delta, snapshot):
        print(delta.value, end="", flush=True)
    
    def on_tool_call_created(self, tool_call):
        print(f"\nassistant > {tool_call.type}\n", flush=True)

    def on_tool_call_delta(self, delta, snapshot):
        if delta.type == 'code_interpreter':
            if delta.code_interpreter.input:
                print(delta.code_interpreter.input, end="", flush=True)
            if delta.code_interpreter.outputs:
                print(f"\n\noutput >", flush=True)
                for output in delta.code_interpreter.outputs:
                    if output.type == "logs":
                        print(f"\n{output.logs}", flush=True)

OS

Python version

Library version

@Programmer-RD-AI Programmer-RD-AI added the bug Something isn't working label Jan 18, 2025
@RobertCraigie RobertCraigie added api docs and removed bug Something isn't working labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants