Skip to content

Commit

Permalink
546 ai prompt support (#591)
Browse files Browse the repository at this point in the history
* initial openAI integration

* python reformatting

* remove warning

* make unselecting element in schema editor also unselect it in sessionStore

* add openAI support for data changes

* make API key secure

* make AI prompts accessible by adding it to the menu bar

* add axios

* apply formatting changes

---------

Co-authored-by: Logende <[email protected]>
  • Loading branch information
Logende and Logende authored Jan 15, 2025
1 parent e599186 commit 8e21f3c
Show file tree
Hide file tree
Showing 22 changed files with 2,103 additions and 250 deletions.
353 changes: 206 additions & 147 deletions backend/app.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions backend/gunicorn_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bind = '0.0.0.0:5000'
bind = "0.0.0.0:5000"
workers = 4
timeout = 120
timeout = 120
40 changes: 19 additions & 21 deletions documentation_user/examples/mof_synthesis/enrich_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,53 @@
from documentation_user.examples.mof_synthesis.utils import collectMetadata

# Load JSON document with synthesis data
with open('ecmofsynthesis.json') as f:
with open("ecmofsynthesis.json") as f:
data = json.load(f)

with open('ecmofsynthesis.schema.json') as f:
with open("ecmofsynthesis.schema.json") as f:
schema = json.load(f)

# Validate the JSON document
validate(data, schema)
print('Data validated successfully')
print("Data validated successfully")


result_data = []
# Iterate over the JSON document and enrich it with metadata
for index, entry in enumerate(data[('ecmofsynthesis')]):
for index, entry in enumerate(data[("ecmofsynthesis")]):

metalSaltName = entry['metal_salt_name']
linkerName = entry['linker_name']
metalSaltName = entry["metal_salt_name"]
linkerName = entry["linker_name"]

# Collect metadata for both molecules
metalSaltMetadata = collectMetadata(metalSaltName)
linkerMetadata = collectMetadata(linkerName)

# draw both molecules and save to disk
if 'smiles' in metalSaltMetadata:
mol1 = Chem.MolFromSmiles(metalSaltMetadata['smiles'])
Draw.MolToFile(mol1, f'metal_salt_{metalSaltName}.png')
if 'smiles' in linkerMetadata:
mol2 = Chem.MolFromSmiles(linkerMetadata['smiles'])
Draw.MolToFile(mol2, f'linker_{linkerName}.png')
if "smiles" in metalSaltMetadata:
mol1 = Chem.MolFromSmiles(metalSaltMetadata["smiles"])
Draw.MolToFile(mol1, f"metal_salt_{metalSaltName}.png")
if "smiles" in linkerMetadata:
mol2 = Chem.MolFromSmiles(linkerMetadata["smiles"])
Draw.MolToFile(mol2, f"linker_{linkerName}.png")

# Append metadata to the entry
result_entry = entry
result_entry['metal_salt'] = metalSaltMetadata
result_entry['linker'] = linkerMetadata
result_entry["metal_salt"] = metalSaltMetadata
result_entry["linker"] = linkerMetadata
result_data.append(result_entry)

# Save the result data
full_result = {
'ecmofsynthesis': result_data
}
with open('ecmofsynthesis_enriched.json', 'w') as f:
full_result = {"ecmofsynthesis": result_data}
with open("ecmofsynthesis_enriched.json", "w") as f:
json.dump(full_result, f, indent=4)

print('Enriched data saved to ecmofsynthesis_enriched.json')
print("Enriched data saved to ecmofsynthesis_enriched.json")


# Validate enriched data according to the schema for enriched files
with open('ecmofsynthesis_enriched.schema.json') as f:
with open("ecmofsynthesis_enriched.schema.json") as f:
schema = json.load(f)

validate(full_result, schema)
print('Enriched data validated successfully')
print("Enriched data validated successfully")
12 changes: 6 additions & 6 deletions documentation_user/examples/mof_synthesis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ def collectMetadata(compoundName: str):
"""
compound = queryCompoundFromPubChem(compoundName)
if compound is None:
print('Error: Could not find molecule in PubChem: ' + compoundName)
print("Error: Could not find molecule in PubChem: " + compoundName)
return {}

# Append metadata
compoundMetadata = {
'cid': compound.cid,
'inchi_code': compound.inchi,
'smiles_code': compound.isomeric_smiles,
'iupac_name': compound.iupac_name,
'molecular_weight': float(compound.molecular_weight)
"cid": compound.cid,
"inchi_code": compound.inchi,
"smiles_code": compound.isomeric_smiles,
"iupac_name": compound.iupac_name,
"molecular_weight": float(compound.molecular_weight),
}

return compoundMetadata
43 changes: 36 additions & 7 deletions meta_configurator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions meta_configurator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@vueuse/core": "^10.6.0",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"axios": "^1.7.9",
"brace": "^0.11.1",
"csv-parse": "^5.5.6",
"dagrejs": "^0.2.1",
Expand Down
4 changes: 4 additions & 0 deletions meta_configurator/src/components/panelType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import GuiEditorPanel from '@/components/panels/gui-editor/GuiEditorPanel.vue';
import SchemaDiagramPanel from '@/components/panels/schema-diagram/SchemaDiagramPanel.vue';
import DebugPanel from '@/components/panels/debug-panel/DebugPanel.vue';
import {errorService} from '@/main';
import AiPromptsPanel from './panels/ai-prompts/AiPromptsPanel.vue';

export enum PanelType {
GuiEditor = 'guiEditor',
TextEditor = 'textEditor',
SchemaDiagram = 'schemaDiagram',
AiPrompts = 'aiPrompts',
Debug = 'debug',
}

Expand All @@ -19,6 +21,8 @@ export function getComponentByPanelType(panelType: PanelType) {
return CodeEditorPanel;
case PanelType.SchemaDiagram:
return SchemaDiagramPanel;
case PanelType.AiPrompts:
return AiPromptsPanel;
case PanelType.Debug:
return DebugPanel;
}
Expand Down
Loading

0 comments on commit 8e21f3c

Please sign in to comment.