reflex icon indicating copy to clipboard operation
reflex copied to clipboard

The yield for special events in the event handler is not in the original order we call.

Open milochen0418 opened this issue 2 years ago β€’ 4 comments

Describe the bug The yield for special events in the event handler is not in the original order we call.

yield for special events is like

  • yield pc.set_value()
  • yield pc.window_alert()
  • yield pc.redirect()
  • yield pc.console_log

To Reproduce Steps to reproduce the behavior:

  • Code/Link to Repo:
"""Welcome to Pynecone! This file outlines the steps to create a basic app."""
import pynecone as pc
import openai
import asyncio
openai.api_key = "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"


class State(pc.State):
    """The app state."""
    image_url = ""
    image_processing = False
    image_made = False
    def get_dalle_result_test(self, form_data: dict[str, str]):
        prompt_text:str = form_data["prompt_text"]
        self.image_made = False
        self.image_processing = True
        ver = "-- ver0002"
        print("run code " + ver)
        yield pc.console_log("run code log trigger "+ver)
        #yield pc.window_alert("Start to call openai.Image.create")
        try:
            response = openai.Image.create(prompt=prompt_text, n=1, size="1024x1024")
            self.image_url = response["data"][0]["url"]
            self.image_processing = False
            self.image_made = True
            #yield pc.console_log("Log 2 trigger")
            yield pc.window_alert("Finish of generate image..." + ver)
            print("finish code in the try-block" + ver)
        except:
            print("in the except-block" + ver)
            self.image_processing = False
            yield pc.console_log("Log Faield trigger" + ver)
            yield pc.window_alert("Error with OpenAI Execution." + ver)
            yield pc.redirect("https://www.google.com")  
    def get_dalle_result(self, form_data: dict[str, str]):
        return self.get_dalle_result_test(form_data)

def index_2():
    return pc.center(
        pc.vstack(
            pc.heading("DALL-E", font_size="1.5em"),
            pc.form(
                pc.input(id="prompt_text", placeholder="Enter a prompt.."),
                pc.button(
                    "Generate Image",
                    type_="submit",
                    width="100%",
                ),
                on_submit=State.get_dalle_result,
            ),
            pc.divider(),
            pc.cond(
                State.image_processing,
                pc.circular_progress(is_indeterminate=True),
                pc.cond(
                    State.image_made,
                    pc.image(
                        src=State.image_url,
                        height="25em",
                        width="25em",
                    ),
                ),
            ),
            bg="white",
            padding="2em",
            shadow="lg",
            border_radius="lg",
        ),
        width="100%",
        height="100vh",
        background="radial-gradient(circle at 22% 11%,rgba(62, 180, 137,.20),hsla(0,0%,100%,0) 19%),radial-gradient(circle at 82% 25%,rgba(33,150,243,.18),hsla(0,0%,100%,0) 35%),radial-gradient(circle at 25% 61%,rgba(250, 128, 114, .28),hsla(0,0%,100%,0) 55%)",
    )

def index():
    return index_2()

# Add state and page to the app.
app = pc.App(state=State)
app.add_page(index, title="Pynecone:DALL-E")
app.compile()

Watch the video to show the bug. https://youtu.be/TtVNWz8ALig Expected behavior A clear and concise description of what you expected to happen.

The yield speicla event should not missed when we use many yield special events.

Screenshots If applicable, add screenshots to help explain your problem.

** Specifics (please complete the following information):**

  • Python Version: 3.11
  • Reflex Version: pc 0.1.34
  • OS: Mac
  • Browser (Optional): Chrome

Additional context Add any other context about the problem here.

milochen0418 avatar Jul 01 '23 03:07 milochen0418

Maybe you accidently leaked your API key? Please edit to remove it and makes it invaild in the OpenAI dashboard.

Take care of your secret.

Edit: Seems like this key is already invaild.

FHU-yezi avatar Jul 01 '23 23:07 FHU-yezi

Thank you for mentioning it @FHU-yezi :) You are so nice. OpenAI checked the GitHub, and it detects this key is on this page. so it automatically deleted it and sent me an email to let me know.
I think the way is a wonderful design for developer who may expose the key sometimes on GitHub.

milochen0418 avatar Jul 02 '23 14:07 milochen0418

related to #1309

ElijahAhianyo avatar Jul 06 '23 13:07 ElijahAhianyo

@milochen0418 can you try your code with #1313

masenf avatar Jul 06 '23 22:07 masenf

Fixed via #1313, please reopen if that is not the case.

masenf avatar Aug 03 '23 20:08 masenf