Skip to content

Commit

Permalink
Merge branch 'main' of https://GitHub.com/Aitomatic/OpenSSA into expe…
Browse files Browse the repository at this point in the history
…rimental
  • Loading branch information
TheVinhLuong102 committed Dec 13, 2023
2 parents 7614344 + e950ef9 commit 7fd20ad
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"**/.ropeproject": true
},

"[python]": {
"editor.formatOnSave": false
},

"python.analysis.diagnosticSeverityOverrides": {
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
LEPTON_API_KEY = '...'

AWS_ACCESS_KEY_ID = '...'
AWS_SECRET_ACCESS_KEY = '...'
82 changes: 41 additions & 41 deletions openssa/contrib/streamlit_ssa_prob_solver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class SSAProbSolver:
DOC_SRC_FILE_RELPATH_SETS_SSS_KEY: str = '_doc_src_file_relpath_sets'

PROBLEMS_SSS_KEY: str = '_problems'
EXPERT_HEURISTICS_SSS_KEY: str = '_expert_heuristics'
EXPERT_INSTRUCTIONS_SSS_KEY: str = '_expert_instructions'
FINE_TUNED_MODELS_SSS_KEY: str = '_fine_tuned_models'

SSAS_SSS_KEY: str = '_ssas'

def __init__(self, unique_name: Uid, domain: str = '',
problem: str = '', expert_heuristics: str = '',
problem: str = '', expert_instructions: str = '',
fine_tuned_model_url: str = '',
doc_src_path: DirOrFilePath = '', doc_src_file_relpaths: FilePathSet = frozenset()):
# pylint: disable=too-many-arguments
Expand All @@ -79,9 +79,9 @@ def __init__(self, unique_name: Uid, domain: str = '',
if not self.problem:
self.problem: str = problem

# set Expert Heuristics
if not self.expert_heuristics:
self.expert_heuristics: str = expert_heuristics
# set Expert Instructions/Knowledge
if not self.expert_instructions:
self.expert_instructions: str = expert_instructions

# set Fine-Tuned Model URL
if not self.fine_tuned_model_url:
Expand All @@ -108,8 +108,8 @@ def _init_sss(cls):
if cls.PROBLEMS_SSS_KEY not in sss:
sss[cls.PROBLEMS_SSS_KEY]: defaultdict[cls.Uid, str] = defaultdict(str)

if cls.EXPERT_HEURISTICS_SSS_KEY not in sss:
sss[cls.EXPERT_HEURISTICS_SSS_KEY]: defaultdict[cls.Uid, str] = defaultdict(str)
if cls.EXPERT_INSTRUCTIONS_SSS_KEY not in sss:
sss[cls.EXPERT_INSTRUCTIONS_SSS_KEY]: defaultdict[cls.Uid, str] = defaultdict(str)

if cls.FINE_TUNED_MODELS_SSS_KEY not in sss:
sss[cls.FINE_TUNED_MODELS_SSS_KEY]: defaultdict[cls.Uid, str] = defaultdict(str)
Expand All @@ -127,16 +127,16 @@ def problem(self, problem: str, /):
sss[self.PROBLEMS_SSS_KEY][self.unique_name]: str = problem

@property
def expert_heuristics(self) -> str:
return sss[self.EXPERT_HEURISTICS_SSS_KEY][self.unique_name]
def expert_instructions(self) -> str:
return sss[self.EXPERT_INSTRUCTIONS_SSS_KEY][self.unique_name]

@expert_heuristics.setter
def expert_heuristics(self, expert_heuristics: str, /):
if expert_heuristics != sss[self.EXPERT_HEURISTICS_SSS_KEY][self.unique_name]:
sss[self.EXPERT_HEURISTICS_SSS_KEY][self.unique_name]: str = expert_heuristics
@expert_instructions.setter
def expert_instructions(self, expert_instructions: str, /):
if expert_instructions != sss[self.EXPERT_INSTRUCTIONS_SSS_KEY][self.unique_name]:
sss[self.EXPERT_INSTRUCTIONS_SSS_KEY][self.unique_name]: str = expert_instructions

def append_expert_heuristics(self, addl_expert_heuristics: str, /):
self.expert_heuristics += f'\n{addl_expert_heuristics}'
def append_expert_instructions(self, addl_expert_instructions: str, /):
self.expert_instructions += f'\n{addl_expert_instructions}'

@property
def fine_tuned_model_url(self) -> str:
Expand Down Expand Up @@ -218,7 +218,7 @@ def ssa(self) -> RagSSA | None:

def ssa_solve(self):
ooda_ssa = OodaSSA(task_heuristics=TaskDecompositionHeuristic({}),
highest_priority_heuristic=self.expert_heuristics)
highest_priority_heuristic=self.expert_instructions)

ooda_ssa.activate_resources(self.doc_src_path)

Expand Down Expand Up @@ -247,46 +247,46 @@ def run(self):

st.write('__EXPERT INSTRUCTIONS/KNOWLEDGE__')

if recorded_expert_heuristics := speech_to_text(start_prompt='Expert Instructions/Knowledge: 🎤 here or ⌨️ below',
stop_prompt='Stop Recording',
just_once=True,
use_container_width=False,
language='en',
callback=None, args=(), kwargs={},
key=None):
if recorded_expert_instructions := speech_to_text(start_prompt='Expert Instructions/Knowledge: 🎤 here or ⌨️ below',
stop_prompt='Stop Recording',
just_once=True,
use_container_width=False,
language='en',
callback=None, args=(), kwargs={},
key=None):
if self.ssa:
recorded_expert_heuristics: str = self.ssa.discuss(f"""
recorded_expert_instructions: str = self.ssa.discuss(f"""
Given your understanding of the domain "{self.domain}",
please rectify and/or restructure the following recorded info
please rectify and/or restructure the following recorded instructions/knowledge
to make it clear and understandable to both humans and other processing engines:
{recorded_expert_heuristics}
"{recorded_expert_instructions}"
Please return the rectified/restructured info in the form of at most 3 paragraphs.
Please return the rectified/restructured instructions/knowledge in the form of at most 3 paragraphs.
""")['content']

st.write(f'"{recorded_expert_heuristics}"')
st.write(f'"{recorded_expert_instructions}"')

else:
st.write(f'_"{recorded_expert_heuristics}"_')
st.write(f'_"{recorded_expert_instructions}"_')

st.button(label='append to saved heuristics below?',
st.button(label='append to saved instructions/knowledge below?',
key=None,
on_click=self.append_expert_heuristics, args=(recorded_expert_heuristics,), kwargs=None,
on_click=self.append_expert_instructions, args=(recorded_expert_instructions,), kwargs=None,
type='secondary',
disabled=False,
use_container_width=False)

self.expert_heuristics: str = st.text_area(label='Expert Heuristics',
value=self.expert_heuristics,
height=10,
max_chars=None,
key=None,
help='Expert Heuristics (recorded or typed)',
on_change=None, args=None, kwargs=None,
placeholder='Expert Heuristics (recorded or typed)',
disabled=False,
label_visibility='collapsed')
self.expert_instructions: str = st.text_area(label='Expert Instructions/Knowledge',
value=self.expert_instructions,
height=10,
max_chars=None,
key=None,
help='Expert Instructions/Knowledge (recorded or typed)',
on_change=None, args=None, kwargs=None,
placeholder='Expert Instructions/Knowledge (recorded or typed)',
disabled=False,
label_visibility='collapsed')

st.write('_(optional)_ __DOMAIN-FINE-TUNED MODEL__')

Expand Down
2 changes: 1 addition & 1 deletion openssa/contrib/streamlit_ssa_prob_solver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

st.session_state['LEPTON_API_KEY']: str | None = \
st.text_input(label='Lepton API Key',
value=st.session_state.get('LEPTON_API_KEY'),
value=st.session_state.get('LEPTON_API_KEY', os.environ.get('LEPTON_API_KEY')),
max_chars=None,
type='password',
help='Lepton API Key (obtainable at dashboard.lepton.ai)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
domain='Atomic Layer Deposition (ALD) for Semiconductor',
problem=('Estimate the ALD process time for 10 cycles, '
'each with Pulse Time = 15 secs, Purge Time = 10 secs and negligible Inert'),
expert_heuristics=('Purge Time must be at least as long as Pulse Time in each cycle '
'to ensure all excess precursor and reaction byproducts are removed '
'from the chamber before the next cycle begins'),
expert_instructions=('Purge Time must be at least as long as Pulse Time in each cycle '
'to ensure all excess precursor and reaction byproducts are removed '
'from the chamber before the next cycle begins'),
doc_src_path='s3://aitomatic-public/KnowledgeBase/Semiconductor/ALD/ALD-Process.txt')

0 comments on commit 7fd20ad

Please sign in to comment.