Spaces:
Sleeping
Sleeping
Commit
·
25d18e3
1
Parent(s):
c725745
prevents error from crashing hte entire site
Browse files- app.py +12 -8
- outputs/professor_guide.csv +3 -3
- poetry.lock +4 -4
- uw_programmatic/base_machine.py +7 -0
- uw_programmatic/config.yaml +4 -0
- uw_programmatic/single_question_machine.py +10 -1
- uw_programmatic/uw_machine.py +5 -0
app.py
CHANGED
|
@@ -19,7 +19,7 @@ def run_with_context(func: Callable) -> Callable:
|
|
| 19 |
|
| 20 |
def generate_questions(
|
| 21 |
page_lower, page_higher, question_number, taxonomy
|
| 22 |
-
) -> tuple[str, dict[str, Any]
|
| 23 |
if machine.value and machine.value.current_state_value == "start":
|
| 24 |
machine.value.start_machine() # Start the machine!
|
| 25 |
if not question_number or question_number <= 0:
|
|
@@ -60,13 +60,17 @@ def generate_questions(
|
|
| 60 |
},
|
| 61 |
},
|
| 62 |
)
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
visible=True, value=f"{Path.cwd().joinpath('outputs/professor_guide.csv')}"
|
| 67 |
-
),
|
| 68 |
-
gr.update(visible=False),
|
| 69 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
def create_statemachine() -> None:
|
|
@@ -115,7 +119,7 @@ with gr.Blocks() as demo:
|
|
| 115 |
start_button.click(
|
| 116 |
fn=run_with_context(generate_questions),
|
| 117 |
inputs=[page_lower, page_higher, question_number, taxonomy],
|
| 118 |
-
outputs=[output, download_professor
|
| 119 |
)
|
| 120 |
download_professor.click(
|
| 121 |
fn=run_with_context(questions_downloaded), outputs=[start_button]
|
|
|
|
| 19 |
|
| 20 |
def generate_questions(
|
| 21 |
page_lower, page_higher, question_number, taxonomy
|
| 22 |
+
) -> tuple[str, dict[str, Any]]:
|
| 23 |
if machine.value and machine.value.current_state_value == "start":
|
| 24 |
machine.value.start_machine() # Start the machine!
|
| 25 |
if not question_number or question_number <= 0:
|
|
|
|
| 60 |
},
|
| 61 |
},
|
| 62 |
)
|
| 63 |
+
button = gr.update(
|
| 64 |
+
visible=True,
|
| 65 |
+
value=f"{Path.cwd().joinpath('outputs/professor_guide.csv')}",
|
|
|
|
|
|
|
|
|
|
| 66 |
)
|
| 67 |
+
markdown = "## Questions Ready for Download Below"
|
| 68 |
+
if machine.value.errored:
|
| 69 |
+
button = gr.update()
|
| 70 |
+
markdown = "## Questions Not Ready for Download"
|
| 71 |
+
exception = "Bad Page Range Selected"
|
| 72 |
+
raise gr.Error(exception)
|
| 73 |
+
return (markdown, button)
|
| 74 |
|
| 75 |
|
| 76 |
def create_statemachine() -> None:
|
|
|
|
| 119 |
start_button.click(
|
| 120 |
fn=run_with_context(generate_questions),
|
| 121 |
inputs=[page_lower, page_higher, question_number, taxonomy],
|
| 122 |
+
outputs=[output, download_professor],
|
| 123 |
)
|
| 124 |
download_professor.click(
|
| 125 |
fn=run_with_context(questions_downloaded), outputs=[start_button]
|
outputs/professor_guide.csv
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
MC,,1,Identify the
|
| 2 |
-
MC,,1,Identify the
|
| 3 |
-
MC,,1,Identify the
|
|
|
|
| 1 |
+
MC,,1,Identify the percentage of working time the Core Team dedicates weekly.,2,The Core Team dedicates 25% of working time weekly.,The Core Team dedicates 9% of working time weekly.,The Core Team dedicates 20% of working time weekly.,The Core Team dedicates 12% of working time weekly.,The Core Team dedicates 15% of working time weekly.,68-81,Knowledge
|
| 2 |
+
MC,,1,Identify the percentage of working time the Core Team spends on ceremonies.,3,The Core Team spends 10% of working time on ceremonies.,The Core Team spends 7% of working time on ceremonies.,The Core Team spends 9% of working time on ceremonies.,The Core Team spends 11% of working time on ceremonies.,The Core Team spends 8% of working time on ceremonies.,68-81,Knowledge
|
| 3 |
+
MC,,1,Identify the frequency of the Biweekly Retrospective meetings as mentioned in the textbook.,5,Biweekly Retrospective meetings occur twice a month.,Biweekly Retrospective meetings occur every four weeks.,Biweekly Retrospective meetings occur once a month.,Biweekly Retrospective meetings occur every three weeks.,Biweekly Retrospective meetings occur every two weeks.,68-81,Knowledge
|
poetry.lock
CHANGED
|
@@ -530,7 +530,7 @@ loaders-sql = ["sqlalchemy (>=2.0.31,<3.0.0)"]
|
|
| 530 |
type = "git"
|
| 531 |
url = "https://github.com/griptape-ai/griptape.git"
|
| 532 |
reference = "main"
|
| 533 |
-
resolved_reference = "
|
| 534 |
|
| 535 |
[[package]]
|
| 536 |
name = "h11"
|
|
@@ -1546,13 +1546,13 @@ image = ["Pillow"]
|
|
| 1546 |
|
| 1547 |
[[package]]
|
| 1548 |
name = "pyright"
|
| 1549 |
-
version = "1.1.
|
| 1550 |
description = "Command line wrapper for pyright"
|
| 1551 |
optional = false
|
| 1552 |
python-versions = ">=3.7"
|
| 1553 |
files = [
|
| 1554 |
-
{file = "pyright-1.1.
|
| 1555 |
-
{file = "pyright-1.1.
|
| 1556 |
]
|
| 1557 |
|
| 1558 |
[package.dependencies]
|
|
|
|
| 530 |
type = "git"
|
| 531 |
url = "https://github.com/griptape-ai/griptape.git"
|
| 532 |
reference = "main"
|
| 533 |
+
resolved_reference = "794ee6ef4c2872dba4dbf08722a52642446b937e"
|
| 534 |
|
| 535 |
[[package]]
|
| 536 |
name = "h11"
|
|
|
|
| 1546 |
|
| 1547 |
[[package]]
|
| 1548 |
name = "pyright"
|
| 1549 |
+
version = "1.1.392.post0"
|
| 1550 |
description = "Command line wrapper for pyright"
|
| 1551 |
optional = false
|
| 1552 |
python-versions = ">=3.7"
|
| 1553 |
files = [
|
| 1554 |
+
{file = "pyright-1.1.392.post0-py3-none-any.whl", hash = "sha256:252f84458a46fa2f0fd4e2f91fc74f50b9ca52c757062e93f6c250c0d8329eb2"},
|
| 1555 |
+
{file = "pyright-1.1.392.post0.tar.gz", hash = "sha256:3b7f88de74a28dcfa90c7d90c782b6569a48c2be5f9d4add38472bdaac247ebd"},
|
| 1556 |
]
|
| 1557 |
|
| 1558 |
[package.dependencies]
|
uw_programmatic/base_machine.py
CHANGED
|
@@ -95,6 +95,7 @@ class UWBaseMachine(StateMachine):
|
|
| 95 |
# To keep vector stores on track
|
| 96 |
self.kb_ids = {}
|
| 97 |
self.rejected_questions: list = []
|
|
|
|
| 98 |
|
| 99 |
self.state_status: dict[str, bool] = {}
|
| 100 |
|
|
@@ -331,6 +332,8 @@ class UWBaseMachine(StateMachine):
|
|
| 331 |
)
|
| 332 |
question_machine.send("start_up")
|
| 333 |
if question_machine.rejected:
|
|
|
|
|
|
|
| 334 |
self.rejected_questions.append(question_machine.generated_question)
|
| 335 |
return InfoArtifact("Question is Rejected")
|
| 336 |
return TextArtifact(question_machine.generated_question)
|
|
@@ -355,6 +358,10 @@ class UWBaseMachine(StateMachine):
|
|
| 355 |
questions = []
|
| 356 |
for outputs in parent_outputs.values():
|
| 357 |
if outputs.type == "InfoArtifact":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
continue
|
| 359 |
questions.append(outputs)
|
| 360 |
return ListArtifact(questions)
|
|
|
|
| 95 |
# To keep vector stores on track
|
| 96 |
self.kb_ids = {}
|
| 97 |
self.rejected_questions: list = []
|
| 98 |
+
self.errored: bool = False
|
| 99 |
|
| 100 |
self.state_status: dict[str, bool] = {}
|
| 101 |
|
|
|
|
| 332 |
)
|
| 333 |
question_machine.send("start_up")
|
| 334 |
if question_machine.rejected:
|
| 335 |
+
if question_machine.reject_reason == "BAD KB PAGE RANGE":
|
| 336 |
+
return InfoArtifact("Bad KB Range")
|
| 337 |
self.rejected_questions.append(question_machine.generated_question)
|
| 338 |
return InfoArtifact("Question is Rejected")
|
| 339 |
return TextArtifact(question_machine.generated_question)
|
|
|
|
| 358 |
questions = []
|
| 359 |
for outputs in parent_outputs.values():
|
| 360 |
if outputs.type == "InfoArtifact":
|
| 361 |
+
if outputs.value == "Bad KB Range":
|
| 362 |
+
self.errored = True
|
| 363 |
+
self.send("error_to_start")
|
| 364 |
+
return ListArtifact([])
|
| 365 |
continue
|
| 366 |
questions.append(outputs)
|
| 367 |
return ListArtifact(questions)
|
uw_programmatic/config.yaml
CHANGED
|
@@ -23,6 +23,10 @@ events:
|
|
| 23 |
transitions:
|
| 24 |
- from: output_q
|
| 25 |
to: end
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
rulesets:
|
| 27 |
frame_question_best_practices:
|
| 28 |
name: Frame Question with KB
|
|
|
|
| 23 |
transitions:
|
| 24 |
- from: output_q
|
| 25 |
to: end
|
| 26 |
+
error_to_start:
|
| 27 |
+
transitions:
|
| 28 |
+
- from: need_more_q
|
| 29 |
+
to: gather_parameters
|
| 30 |
rulesets:
|
| 31 |
frame_question_best_practices:
|
| 32 |
name: Frame Question with KB
|
uw_programmatic/single_question_machine.py
CHANGED
|
@@ -78,6 +78,7 @@ TRANSITIONS = [
|
|
| 78 |
{"from": "start", "to": "random_selection"},
|
| 79 |
],
|
| 80 |
},
|
|
|
|
| 81 |
]
|
| 82 |
RULESETS = {
|
| 83 |
"specific_question_creator": [
|
|
@@ -211,6 +212,12 @@ class SingleQuestion(StateMachine):
|
|
| 211 |
self.taxonomy_prompt = taxonomy_prompt[self.taxonomy]
|
| 212 |
# get the random page range and GTCVectorStoreDriver
|
| 213 |
pages, driver = self.get_vector_store_id_from_page()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
self.pages = pages
|
| 215 |
self.driver = driver
|
| 216 |
self.send("next_state")
|
|
@@ -405,7 +412,7 @@ class SingleQuestion(StateMachine):
|
|
| 405 |
|
| 406 |
def get_vector_store_id_from_page(
|
| 407 |
self,
|
| 408 |
-
) -> tuple[str, GriptapeCloudVectorStoreDriver]:
|
| 409 |
possible_kbs = {}
|
| 410 |
for name, kb_id in self.kb_ids.items():
|
| 411 |
page_nums = name.split("p")[1:]
|
|
@@ -413,6 +420,8 @@ class SingleQuestion(StateMachine):
|
|
| 413 |
end_page = int(page_nums[1])
|
| 414 |
if end_page <= self.page_range[1] and start_page >= self.page_range[0]:
|
| 415 |
possible_kbs[kb_id] = f"{start_page}-{end_page}"
|
|
|
|
|
|
|
| 416 |
kb_id = random.choice(list(possible_kbs.keys()))
|
| 417 |
page_value = possible_kbs[kb_id]
|
| 418 |
return page_value, GriptapeCloudVectorStoreDriver(
|
|
|
|
| 78 |
{"from": "start", "to": "random_selection"},
|
| 79 |
],
|
| 80 |
},
|
| 81 |
+
{"event": "end_state", "transitions": [{"from": "random_selection", "to": "end"}]},
|
| 82 |
]
|
| 83 |
RULESETS = {
|
| 84 |
"specific_question_creator": [
|
|
|
|
| 212 |
self.taxonomy_prompt = taxonomy_prompt[self.taxonomy]
|
| 213 |
# get the random page range and GTCVectorStoreDriver
|
| 214 |
pages, driver = self.get_vector_store_id_from_page()
|
| 215 |
+
if driver is None:
|
| 216 |
+
self.send("end_state")
|
| 217 |
+
self.rejected = True
|
| 218 |
+
self.reject_reason = "BAD KB PAGE RANGE"
|
| 219 |
+
print(self.reject_reason)
|
| 220 |
+
return
|
| 221 |
self.pages = pages
|
| 222 |
self.driver = driver
|
| 223 |
self.send("next_state")
|
|
|
|
| 412 |
|
| 413 |
def get_vector_store_id_from_page(
|
| 414 |
self,
|
| 415 |
+
) -> tuple[str, GriptapeCloudVectorStoreDriver | None]:
|
| 416 |
possible_kbs = {}
|
| 417 |
for name, kb_id in self.kb_ids.items():
|
| 418 |
page_nums = name.split("p")[1:]
|
|
|
|
| 420 |
end_page = int(page_nums[1])
|
| 421 |
if end_page <= self.page_range[1] and start_page >= self.page_range[0]:
|
| 422 |
possible_kbs[kb_id] = f"{start_page}-{end_page}"
|
| 423 |
+
if not len(list(possible_kbs.keys())):
|
| 424 |
+
return ("No KBs in range", None)
|
| 425 |
kb_id = random.choice(list(possible_kbs.keys()))
|
| 426 |
page_value = possible_kbs[kb_id]
|
| 427 |
return page_value, GriptapeCloudVectorStoreDriver(
|
uw_programmatic/uw_machine.py
CHANGED
|
@@ -33,6 +33,7 @@ class UWMachine(UWBaseMachine):
|
|
| 33 |
self.current_question_count = 0
|
| 34 |
self.give_up_count = 0
|
| 35 |
self.question_list = []
|
|
|
|
| 36 |
|
| 37 |
# The first state: Listens for Gradio and then gives us the parameters to search for.
|
| 38 |
# Reinitializes the Give Up counter.
|
|
@@ -45,7 +46,11 @@ class UWMachine(UWBaseMachine):
|
|
| 45 |
self.page_range = parameters["page_range"]
|
| 46 |
self.question_number = parameters["question_number"]
|
| 47 |
self.taxonomy = parameters["taxonomy"]
|
|
|
|
| 48 |
self.send("next_state")
|
|
|
|
|
|
|
|
|
|
| 49 |
case _:
|
| 50 |
err_msg = f"Unexpected Transition Event ID: {event_value}."
|
| 51 |
raise ValueError(err_msg)
|
|
|
|
| 33 |
self.current_question_count = 0
|
| 34 |
self.give_up_count = 0
|
| 35 |
self.question_list = []
|
| 36 |
+
self.rejected_questions = []
|
| 37 |
|
| 38 |
# The first state: Listens for Gradio and then gives us the parameters to search for.
|
| 39 |
# Reinitializes the Give Up counter.
|
|
|
|
| 46 |
self.page_range = parameters["page_range"]
|
| 47 |
self.question_number = parameters["question_number"]
|
| 48 |
self.taxonomy = parameters["taxonomy"]
|
| 49 |
+
self.errored = False
|
| 50 |
self.send("next_state")
|
| 51 |
+
case "griptape_event":
|
| 52 |
+
if event_value["structure_id"] == "create_question_workflow":
|
| 53 |
+
pass
|
| 54 |
case _:
|
| 55 |
err_msg = f"Unexpected Transition Event ID: {event_value}."
|
| 56 |
raise ValueError(err_msg)
|