Skip to content

Commit

Permalink
run precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
jombooth authored and elijahbenizzy committed Mar 5, 2024
1 parent 275223c commit 6729c07
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions examples/corgi_adventure/application.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json
from typing import List, Optional, Tuple

from openai import Client

import burr.core
from burr.core import Application, State, default, when
from burr.core.action import action
from burr.lifecycle import LifecycleAdapter
from openai import Client
import json


RESTRICTIONS = """You're a small corgi with short legs. You can't jump high,
you can't run fast, you can't perform feats of athleticism in general
Expand Down Expand Up @@ -41,7 +41,6 @@ def prompt_for_challenge(state: State) -> Tuple[dict, State]:
writes=["challenge_solved", "what_happened"],
)
def evaluate_attempt(state: State) -> Tuple[dict, State]:

result = Client().chat.completions.create(
model="gpt-4",
messages=[
Expand All @@ -65,9 +64,12 @@ def evaluate_attempt(state: State) -> Tuple[dict, State]:
content = result.choices[0].message.content
try:
json_result = json.loads(content)
except json.JSONDecodeError as e:
except json.JSONDecodeError:
print("bad json: ", content)
json_result = {"solved": False, "what_happened": "Not sure, really. I'm a dog. I can't read json. I can't read at all."}
json_result = {
"solved": False,
"what_happened": "Not sure, really. I'm a dog. I can't read json. I can't read at all.",
}

result = {"challenge_solved": json_result["solved"], "txt_result": content}

Expand All @@ -88,9 +90,7 @@ def maybe_progress(state: State) -> Tuple[dict, State]:
result = {"did_win": True}
else:
result = {
"current_challenge": challenges[
challenges.index(state["current_challenge"]) + 1
]
"current_challenge": challenges[challenges.index(state["current_challenge"]) + 1]
}
else:
result = {"current_challenge": state["current_challenge"]}
Expand Down Expand Up @@ -127,16 +127,12 @@ def application(
("maybe_progress", "prompt_for_challenge", default),
)
.with_entrypoint("start")
.with_tracker(
"demo:corgi_adventure", params={"app_id": app_id, "storage_dir": storage_dir}
)
.with_tracker("demo:corgi_adventure", params={"app_id": app_id, "storage_dir": storage_dir})
.build()
)


if __name__ == "__main__":
app = application()
app.visualize(
output_file_path="digraph", include_conditions=True, view=False, format="png"
)
app.visualize(output_file_path="digraph", include_conditions=True, view=False, format="png")
action, state, result = app.run(halt_after=["win"])

0 comments on commit 6729c07

Please sign in to comment.