Skip to content

Commit 436c007

Browse files
authored
fix: finance-content-checker logic repair (#13)
1 parent 08bfefd commit 436c007

9 files changed

Lines changed: 146 additions & 893 deletions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{"id": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "type": "page", "content": {"pageMode": "compact"}, "handlers": {}, "isCodeManaged": false, "parentId": "root", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
2+
{"id": "bebc5fe9-63a7-46a7-b0fa-62303555cfaf", "type": "header", "content": {"text": "@{my_app.title}"}, "handlers": {}, "isCodeManaged": false, "parentId": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
3+
{"id": "oifvuxkfgni30c04", "type": "image", "content": {"caption": "", "maxHeight": "30", "maxWidth": "", "src": "@{img_path}"}, "handlers": {}, "isCodeManaged": false, "parentId": "bebc5fe9-63a7-46a7-b0fa-62303555cfaf", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
4+
{"id": "cfdn0lwtc3bc2e1i", "type": "message", "content": {"message": "@{message}"}, "handlers": {}, "isCodeManaged": false, "parentId": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
5+
{"id": "3emssu3oapg9aaeb", "type": "columns", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "c0f99a9e-5004-4e75-a6c6-36f17490b134", "position": 2, "visible": {"binding": "", "expression": true, "reversed": false}}
6+
{"id": "0r3y4groykgktb1l", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "3emssu3oapg9aaeb", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
7+
{"id": "hjtxdwb3aeylsfh6", "type": "section", "content": {"title": "Input content to check"}, "handlers": {}, "isCodeManaged": false, "parentId": "0r3y4groykgktb1l", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
8+
{"id": "f82m2sdbhhgfgbb1", "type": "textareainput", "binding": {"eventType": "wf-change", "stateRef": "content"}, "content": {"label": "Paste in some content to check (<500 words)", "placeholder": "", "rows": "5"}, "handlers": {"wf-change": "content_to_HMTL"}, "isCodeManaged": false, "parentId": "hjtxdwb3aeylsfh6", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
9+
{"id": "3wckjuynvz0od6w9", "type": "section", "content": {"title": ""}, "handlers": {}, "isCodeManaged": false, "parentId": "0r3y4groykgktb1l", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
10+
{"id": "c30ch4pibyw5juug", "type": "html", "content": {"htmlInside": "@{html_content}", "styles": "{\n \"padding\": \"16px\",\n\"padding-top\":\"20px\",\n \"min-height\": \"64px\",\n\"max-height\": \"420px\",\n\"overflow\":\"auto\",\n \"min-width\": \"64px\",\n \"border-radius\": \"8px\"\n}"}, "handlers": {}, "isCodeManaged": false, "parentId": "3wckjuynvz0od6w9", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
11+
{"id": "43cp015ju9156xvo", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "3emssu3oapg9aaeb", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
12+
{"id": "z4toz7gq7kpdhbvs", "type": "multiselectinput", "binding": {"eventType": "wf-options-change", "stateRef": "suggestion_flags_selected"}, "content": {"accentColor": "gray", "chipTextColor": "", "label": "Select one or more Suggestion Flags", "maximumCount": "5", "options": "@{suggestion_flags}", "placeholder": "Select up to 3 options..."}, "handlers": {"wf-options-change": "enable_suggestion_tabs"}, "isCodeManaged": false, "parentId": "43cp015ju9156xvo", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
13+
{"id": "e9re4hpngsrtszns", "type": "button", "content": {"icon": "arrow_forward", "isDisabled": "@{generate_btn_disabled}", "text": "Generate suggestions"}, "handlers": {"wf-click": "handle_generate_button_click"}, "isCodeManaged": false, "parentId": "43cp015ju9156xvo", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
14+
{"id": "amo4m8mssxwfztng", "type": "tabs", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "43cp015ju9156xvo", "position": 2, "visible": {"binding": "", "expression": true, "reversed": false}}
15+
{"id": "y2co003xc2z7ckld", "type": "tab", "content": {"name": "Outcome language"}, "handlers": {"click": "get_current_tab"}, "isCodeManaged": false, "parentId": "amo4m8mssxwfztng", "position": 0, "visible": {"binding": "tab_enabled.outcome_language", "expression": "custom", "reversed": false}}
16+
{"id": "8cgl5i0vbhppyh4i", "type": "columns", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "y2co003xc2z7ckld", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
17+
{"id": "p8jduqivbny7bdxy", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "8cgl5i0vbhppyh4i", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
18+
{"id": "hyfos0bkdr3v50nb", "type": "section", "content": {"title": "Original text"}, "handlers": {"click": "highlight_string"}, "isCodeManaged": false, "parentId": "p8jduqivbny7bdxy", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
19+
{"id": "h4k2l0kghizi1osw", "type": "message", "content": {"message": "@{output.outcome_language.text}"}, "handlers": {"change": "highlight_string"}, "isCodeManaged": false, "parentId": "hyfos0bkdr3v50nb", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
20+
{"id": "atmnc5edtlm52idp", "type": "section", "content": {"title": "Suggestion"}, "handlers": {}, "isCodeManaged": false, "parentId": "p8jduqivbny7bdxy", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
21+
{"id": "fli8kybxrmqrrfaw", "type": "message", "content": {"message": "+@{output.outcome_language.suggestion}"}, "handlers": {}, "isCodeManaged": false, "parentId": "atmnc5edtlm52idp", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
22+
{"id": "shhxankpkgzxdp6o", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "8cgl5i0vbhppyh4i", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
23+
{"id": "v41sm3g27nf7qxsx", "type": "tags", "content": {"tags": "{\n \"outcome_language\": \"outcome language\"\n}"}, "handlers": {}, "isCodeManaged": false, "parentId": "shhxankpkgzxdp6o", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
24+
{"id": "ijghkvhd8yxwxboq", "type": "message", "content": {"message": "!@{output.outcome_language.description}"}, "handlers": {}, "isCodeManaged": false, "parentId": "shhxankpkgzxdp6o", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
25+
{"id": "1h3fup2ixqij4zzl", "type": "pagination", "content": {"page": "@{pagination.outcome_language.current_page}", "pageSize": "1", "pageSizeOptions": "", "totalItems": "@{pagination.outcome_language.data_size}"}, "handlers": {"wf-change-page": "set_page"}, "isCodeManaged": false, "parentId": "y2co003xc2z7ckld", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
26+
{"id": "kdx0s5tf0t6t272y", "type": "tab", "content": {"name": "Hyperbole"}, "handlers": {"click": "get_current_tab"}, "isCodeManaged": false, "parentId": "amo4m8mssxwfztng", "position": 1, "visible": {"binding": "tab_enabled.hyperbole", "expression": "custom", "reversed": false}}
27+
{"id": "4ut5mwq967zm0049", "type": "columns", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "kdx0s5tf0t6t272y", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
28+
{"id": "p6hezc459yfkcvrb", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "4ut5mwq967zm0049", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
29+
{"id": "9n7r2yllx9h6d9vh", "type": "section", "content": {"title": "Original text"}, "handlers": {}, "isCodeManaged": false, "parentId": "p6hezc459yfkcvrb", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
30+
{"id": "giyebjqjd4tuojwy", "type": "message", "content": {"message": "@{output.hyperbole.text}"}, "handlers": {}, "isCodeManaged": false, "parentId": "9n7r2yllx9h6d9vh", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
31+
{"id": "8avbiu3lz7hzk4u4", "type": "section", "content": {"title": "Suggestion"}, "handlers": {}, "isCodeManaged": false, "parentId": "p6hezc459yfkcvrb", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
32+
{"id": "cumxx6s29p0kf3p1", "type": "message", "content": {"message": "+@{output.hyperbole.suggestion}"}, "handlers": {}, "isCodeManaged": false, "parentId": "8avbiu3lz7hzk4u4", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
33+
{"id": "jdjc5g79v7qffben", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "4ut5mwq967zm0049", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
34+
{"id": "smuxxei8eqmzd3i5", "type": "tags", "content": {"tags": "{\n \"Hyperbole\": \"hyperbole\"\n}"}, "handlers": {}, "isCodeManaged": false, "parentId": "jdjc5g79v7qffben", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
35+
{"id": "fhomxd6iobyhvq22", "type": "message", "content": {"message": "!@{output.hyperbole.description}"}, "handlers": {}, "isCodeManaged": false, "parentId": "jdjc5g79v7qffben", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
36+
{"id": "br9ri32d6dwg6btf", "type": "pagination", "content": {"page": "@{pagination.hyperbole.current_page}", "pageSize": "1", "pageSizeOptions": "", "totalItems": "@{pagination.hyperbole.data_size}"}, "handlers": {"wf-change-page": "set_page"}, "isCodeManaged": false, "parentId": "kdx0s5tf0t6t272y", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
37+
{"id": "1ntjnjorgokmrksh", "type": "tab", "content": {"name": "We pronoun"}, "handlers": {"click": "get_current_tab"}, "isCodeManaged": false, "parentId": "amo4m8mssxwfztng", "position": 2, "visible": {"binding": "tab_enabled.we_pronoun", "expression": "custom", "reversed": false}}
38+
{"id": "220abedg02oxr0df", "type": "columns", "content": {}, "handlers": {}, "isCodeManaged": false, "parentId": "1ntjnjorgokmrksh", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
39+
{"id": "ash4sqj4675xby5u", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "220abedg02oxr0df", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
40+
{"id": "pz1uzfd2sgvj35wf", "type": "section", "content": {"title": "Original text"}, "handlers": {}, "isCodeManaged": false, "parentId": "ash4sqj4675xby5u", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
41+
{"id": "wufcwgrrybpweoc2", "type": "message", "content": {"message": "@{output.we_pronoun.text}"}, "handlers": {}, "isCodeManaged": false, "parentId": "pz1uzfd2sgvj35wf", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
42+
{"id": "4euoiqzlcfgkrd51", "type": "section", "content": {"title": "Suggestion"}, "handlers": {}, "isCodeManaged": false, "parentId": "ash4sqj4675xby5u", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
43+
{"id": "gg5gv7ukdcbp0ys7", "type": "message", "content": {"message": "+@{output.we_pronoun.suggestion}"}, "handlers": {}, "isCodeManaged": false, "parentId": "4euoiqzlcfgkrd51", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
44+
{"id": "0jydi26cfk0lj4zg", "type": "column", "content": {"width": "1"}, "handlers": {}, "isCodeManaged": false, "parentId": "220abedg02oxr0df", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
45+
{"id": "hddj4kf5pbu7nltg", "type": "tags", "content": {"tags": "{\n \"we_pronoun\": \"we pronoun\"\n}"}, "handlers": {}, "isCodeManaged": false, "parentId": "0jydi26cfk0lj4zg", "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
46+
{"id": "tbherv4idvftfhr5", "type": "message", "content": {"message": "!@{output.we_pronoun.description}"}, "handlers": {}, "isCodeManaged": false, "parentId": "0jydi26cfk0lj4zg", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
47+
{"id": "tu8ujfgmwm1cviiu", "type": "pagination", "content": {"page": "@{pagination.we_pronoun.current_page}", "pageSize": "1", "pageSizeOptions": "", "totalItems": "@{pagination.we_pronoun.data_size}"}, "handlers": {"wf-change-page": "set_page"}, "isCodeManaged": false, "parentId": "1ntjnjorgokmrksh", "position": 1, "visible": {"binding": "", "expression": true, "reversed": false}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id": "root", "type": "root", "content": {"appName": "Finance Copy Compliance Checker"}, "handlers": {}, "isCodeManaged": false, "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id": "workflows_root", "type": "workflows_root", "content": {}, "handlers": {}, "isCodeManaged": false, "position": 0, "visible": {"binding": "", "expression": true, "reversed": false}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"writer_version": "0.8.2"
3+
}

finance-content-checker/main.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1+
import asyncio
2+
13
import writer as wf
4+
from writerai import AsyncWriter
5+
from dotenv import load_dotenv
26
import utils as ut
37
from prompts import _hyperbole_prompt, _outcome_language_prompt, _we_pronoun_prompt, input_text, initial_output
48

9+
load_dotenv()
10+
511
class Rule:
612
def __init__(self, name, prompt_function, state):
713
self.name = name
814
self.prompt_function = prompt_function
915
self.state = state
1016

11-
def fetch_data(self):
17+
async def fetch_data(self):
1218
formatted_content = self.state["content"].replace('\n\n', ' ')
1319
prompt = self.prompt_function(formatted_content)
14-
output = wf.ai.complete(prompt)
15-
data = ut.convert_string_to_dict_list(output)
20+
output = await AsyncWriter().completions.create(
21+
model="palmyra-x-004", prompt=prompt
22+
)
23+
data = ut.convert_string_to_dict_list(output.choices[0].text)
1624
if data:
1725
first_entry = data[0]
1826
ut.set_page_output(first_entry, self.state, self.name)
1927
self.state[self.name] = data
2028
self.state["pagination"][self.name]["data_size"] = len(data)
2129

22-
def process_rules(state):
30+
async def process_rules(state):
2331
"""Process all rules and update the state accordingly."""
2432

2533
# Define rules
@@ -29,20 +37,27 @@ def process_rules(state):
2937
Rule("we_pronoun", _we_pronoun_prompt, state)
3038
]
3139

40+
tasks = []
41+
42+
state["message"] = "Performing analysis..."
43+
3244
# Fetch data for each rule
3345
for rule in rules:
3446
if(rule.name in state["suggestion_flags_selected"]):
3547
formatted_name = rule.name.replace("_", " ")
36-
state["message"] = f"Processing {formatted_name}..."
37-
rule.fetch_data()
48+
tasks.append(rule.fetch_data())
49+
50+
await asyncio.gather(*tasks)
3851

3952

4053

4154
# Event handlers
4255
# Handler to add/remove tabs from being displayed when suggestion flags are selected. Called by change event on multiselect suggestion flags UI component.
4356
def enable_suggestion_tabs(state,context):
4457
"""
45-
Handler to add/remove tabs from being displayed when suggestion flags are selected. Called by change event on multiselect suggestion flags UI component.
58+
Handler to add/remove tabs from being displayed when suggestion
59+
flags are selected. Called by change event on multiselect suggestion
60+
flags UI component.
4661
"""
4762
all_options = list(flags.values())
4863

@@ -53,13 +68,19 @@ def enable_suggestion_tabs(state,context):
5368

5469

5570
def set_page(state,payload):
56-
"""This is a handler called by the pagination component when a page is clicked ("wf-change-page event). The payload returns the number of the current page "
71+
"""This is a handler called by the pagination component when
72+
a page is clicked ("wf-change-page event). The payload returns
73+
the number of the current page "
5774
"""
5875
index = payload - 1
5976
curr_tab = state["current_tab"]
6077
state["pagination"][curr_tab]["current_page"] = payload
6178

62-
"""The tab name of the current tab is used to determine which suggestion rule is in focus. This means that the tab names need to line up with the rules. The logic here is that based on the page clicked on in the active tab, we index that data dictionary and set the page output accordingly, as well as highlight the text in the html output."""
79+
"""The tab name of the current tab is used to determine which suggestion rule is in focus.
80+
This means that the tab names need to line up with the rules. The logic here is that based
81+
on the page clicked on in the active tab, we index that data dictionary and set the page
82+
output accordingly, as well as highlight the text in the html output.
83+
"""
6384
rule = state["current_tab"]
6485
data = state[rule]
6586
ut.set_page_output(data=data[index],state=state,rule=rule)
@@ -68,15 +89,16 @@ def set_page(state,payload):
6889

6990

7091
def content_to_HMTL(state):
71-
"""handler to set up the input text as html for the html element. Called whenever there is a change in the input text."""
92+
"""handler to set up the input text as html for the html element.
93+
Called whenever there is a change in the input text."""
7294
formatted_content = state["content"].replace('\n\n', '<br/><br/>')
7395
print(formatted_content)
7496
html = """ <p class="description">{content}</p>""".format(content=formatted_content)
7597
state["html_content"] = html
7698
return html
7799

78100
# Generate button click handler
79-
def handle_generate_button_click(state):
101+
async def handle_generate_button_click(state):
80102
# Disable button when clicked to prevent double clicking
81103
state["generate_btn_disabled"] = "yes"
82104

@@ -85,15 +107,19 @@ def handle_generate_button_click(state):
85107
# This collection is stored in the state[rule] field and the
86108
# number of pages is set based on the number of items in the collection.
87109

88-
process_rules(state)
110+
await process_rules(state)
89111

90112
# Re-enable button once processing is completed.
91113
state["message"] = ""
92114
state["generate_btn_disabled"] = "no"
93115
ut.highlight_string(state,state["current_tab"])
94116

95117
def get_current_tab(state,context :dict):
96-
"""This is a handler that is tied to the tab click event. Return the current tab: this uses an approach that will eventually be deprecated where we look at the context and grab the target from it which gives the component id of the UI component"""
118+
"""This is a handler that is tied to the tab click event.
119+
Return the current tab: this uses an approach that will
120+
eventually be deprecated where we look at the context and
121+
grab the target from it which gives the component id of
122+
the UI component"""
97123

98124
# mapping of component ids to tab names.
99125
tabs = {"y2co003xc2z7ckld": "outcome_language", "kdx0s5tf0t6t272y": "hyperbole", "1ntjnjorgokmrksh": "we_pronoun"}
@@ -123,7 +149,7 @@ def get_current_tab(state,context :dict):
123149
},
124150
"message": "",
125151
"content": input_text(),
126-
"html_content":f""" <p class="description">{input_text().replace('\n\n', '<br/><br/>')}</p>""",
152+
"html_content":'<p class="description">{text}</p>'.format(text=input_text().replace("\n\n", "<br/><br/>")),
127153
"outcome_language": "",
128154
"we_pronoun":"",
129155
"hyperbole":"",

0 commit comments

Comments
 (0)