Skip to content

Commit 54435c7

Browse files
PhillipDowneyPhil Downeybrian316
authored
Llm rxn fix (#53)
* notebook and LLM updates * first merge llm * llm fix and rxn fix * magic performance fix * minor tweak onLLM settings * update docs --------- Co-authored-by: Phil Downey <phildowney@pd-work-mac.local> Co-authored-by: Brian Duenas <brian.duenas@ibm.com>
1 parent 381f17d commit 54435c7

9 files changed

Lines changed: 206 additions & 136 deletions

File tree

docs/output/csv/commands.csv

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ docs;Help
6565
?;Help
6666
? ...<soft> --> List all commands containing "..."</soft>;Help
6767
... ?<soft> --> List all commands starting with "..."</soft>;Help
68+
model auth list;Model
69+
model auth add group '<auth_group>' with '<api_key>';Model
70+
model auth remove group '<auth_group>';Model
71+
model auth add service '<service_name>' to group '<auth_group>';Model
72+
model auth remove service '<service_name>';Model
6873
model service status;Model
69-
model service config '<service_name>'|<service_name>;Model
74+
model service describe '<service_name>'|<service_name>;Model
7075
model catalog list;Model
7176
uncatalog model service '<service_name>'|<service_name>;Model
72-
catalog model service from (remote) '<path or github>' as '<service_name>'|<service_name>;Model
77+
catalog model service from (remote) '<path or github>' as '<service_name>'|<service_name> USING (<parameter>=<value> <parameter>=<value>);Model
7378
model service up '<service_name>'|<service_name> [no_gpu]};Model
7479
model service local up '<service_name>'|<service_name> ;Model
7580
model service down '<service_name>'|<service_name>;Model

docs/output/markdown/commands.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ This command Enriches every molecule in your current working list of molecules w
252252
- RXN Toolkit `predict Reaction` <br>
253253
- RXN Toolkit `predict retrosynthesis ` <br>
254254
- DS4SD Toolkit `search for patents containing molecule` <br>
255-
- DS4SD Toolkit `search for similiar molecules` <br><br>
255+
- DS4SD Toolkit `search for similiar molecules` <br>
256+
257+
See the Deep Search toolkit and RXN toolkit help for further assistance on these commands. <br><br>
256258

257259
`clear analysis cache`{: .cmd }
258260
this command clears the cache of analysis results for your current workspace. <br><br>
@@ -466,11 +468,26 @@ List all available commands. <br><br>
466468

467469
### Model
468470

471+
`model auth list`{: .cmd }
472+
show authentication group mapping <br><br>
473+
474+
`model auth add group '<auth_group>' with '<api_key>'`{: .cmd }
475+
add an authentication group for model services to use <br><br>
476+
477+
`model auth remove group '<auth_group>'`{: .cmd }
478+
remove an authentication group <br><br>
479+
480+
`model auth add service '<service_name>' to group '<auth_group>'`{: .cmd }
481+
attach an authentication group to a model service <br><br>
482+
483+
`model auth remove service '<service_name>'`{: .cmd }
484+
detatch an authentication group from a model service <br><br>
485+
469486
`model service status`{: .cmd }
470487
get the status of currently cataloged services <br><br>
471488

472-
`model service config '<service_name>'|<service_name>`{: .cmd }
473-
get the config of a service <br><br>
489+
`model service describe '<service_name>'|<service_name>`{: .cmd }
490+
get the configuration of a service <br><br>
474491

475492
`model catalog list`{: .cmd }
476493
get the list of currently cataloged services <br><br>
@@ -481,8 +498,9 @@ uncatalog a model service <br>
481498
Example: <br>
482499
`uncatalog model service 'gen'` <br><br>
483500

484-
`catalog model service from (remote) '<path or github>' as '<service_name>'|<service_name>`{: .cmd }
501+
`catalog model service from (remote) '<path or github>' as '<service_name>'|<service_name> USING (<parameter>=<value> <parameter>=<value>)`{: .cmd }
485502
catalog a model service from a path or github or remotely from an existing OpenAD service. <br>
503+
(USING) optional headers parameters for communication with service backend. <br>
486504

487505
Example: <br>
488506

@@ -679,7 +697,7 @@ Lists all RXN AI models currently available. <br><br>
679697
`predict retrosynthesis '<smiles>' [ using (option1=<value> option2=<value>) ]`{: .cmd }
680698
Perform a retrosynthesis route prediction on a molecule. <br>
681699

682-
Options for the optional `using` clause: <br>
700+
Optional Parameters that can be specified in the `using` clause: <br>
683701
- `availability_pricing_threshold=<int>` Maximum price in USD per g/ml of compounds. Default: no threshold. <br>
684702
- `available_smiles='<smiles>.<smiles>.<smiles>'` List of molecules available as precursors, delimited with a period. <br>
685703
- `exclude_smiles='<smiles>.<smiles>.<smiles>'` List of molecules to exlude from the set of precursors, delimited with a period. <br>
@@ -703,7 +721,7 @@ Run a batch of reaction predictions. The provided list of reactions can be speci
703721

704722
Reactions are defined by combining two SMILES strings delimited by a period. For example: `'BrBr.c1ccc2cc3ccccc3cc2c1'` <br>
705723

706-
Options for the optional `using` clause: <br>
724+
Optional Parameters that can be specified in the `using` clause: <br>
707725
- `ai_model='<model_name>'` What model to use. Use the command `list rxn models` to list all available models. The default is '2020-07-01'. <br>
708726

709727
You can reuse previously generated results by appending the optional `use_saved` clause. This will reuse the results of a previously run command with the same parameters, if available. <br>
@@ -717,7 +735,7 @@ Predict the reaction between two molecules. <br>
717735

718736
Reactions are defined by combining two SMILES strings delimited by a period. For example: `'BrBr.c1ccc2cc3ccccc3cc2c1'` <br>
719737

720-
Options for the optional `using` clause: <br>
738+
Optional Parameters that can be specified in the `using` clause: <br>
721739
- `ai_model='<model_name>'` What model to use. Use the command `list rxn models` to list all available models. The default is '2020-07-01'. <br>
722740

723741
You can reuse previously generated results by appending the optional `use_saved` clause. This will reuse the results of a previously run command with the same parameters, if available. <br>
@@ -731,7 +749,7 @@ Run a batch of reaction predictions for topn. The provided list of reactions can
731749

732750
Reactions are defined by combining two SMILES strings delimited by a period. For example: `'BrBr.c1ccc2cc3ccccc3cc2c1'` <br>
733751

734-
Options for the optional `using` clause: <br>
752+
Optional Parameters that can be specified in the `using` clause: <br>
735753
- `ai_model='<model_name>'` What model to use. Use the command `list rxn models` to list all available models. The default is '2020-07-01'. <br>
736754
- `topn=<integer>` Defined the number of results being returned. The default value is 3. <br>
737755

docs/output/markdown/installation.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,23 +284,55 @@ To run a command in bash mode, prepend it with `openad` and make sure to escape
284284

285285
# AI Assistant
286286

287-
To enable our AI assistant, you'll need an account with OpenAI. There is a one month free trial.
287+
To enable our AI assistant, you'll need either have access to [IBM BAM](https://bam.res.ibm.com/auth/signin) or to use a free open source LLM use [ollama](ollama.com).
288288

289-
This is available for IBM BAM service and Openai.
289+
**Note:** Ollama will requires a 8gb GPU
290290

291291
> **Note:** watsonx coming soon
292292
293+
## IBM BAM Setup
293294
For IBM BAM simply used your supplied API key if you have BAM access
294295

295-
For OpenAI
296-
297-
1. Go to [platform.openai.com](https://platform.openai.com) and create an account
298-
299-
2. Click on the profile icon in the top right and choose "View API keys"
300-
301-
3. Create a new key
302-
303-
4. Run `tell me` to be prompted for your OpenAI API credentials
296+
### Run BAM LLM
297+
run `tell me` to be prompted for your BAM API credentials
298+
```
299+
>> set llm bam
300+
>> tell me <enter prompt>
301+
```
302+
303+
## Ollama setup
304+
Install ollama on your platform from [here](https://ollama.com/download)
305+
306+
Download appropriate models
307+
```
308+
ollama pull llama3:latest
309+
ollama pull nomic-embed-text
310+
```
311+
312+
Start the server if not already started
313+
```
314+
ollama serve
315+
```
316+
Thats it for local usage. If you want to run ollama remotely continue.
317+
318+
### Ollama remote setup with skypilot
319+
Check out our configuration file to launch ollama on skypilot [ollama_setup.yaml](./ollama_setup.yaml)
320+
```
321+
sky serve up ollama_setup.yaml
322+
```
323+
324+
Setup local environment variables
325+
326+
1. For windows `setx OLLAMA_HOST=<sky-server-ip>:11434`
327+
2. For Linux and macos `export OLLAMA_HOST=<sky-server-ip>:11434`
328+
3. To reset to local use `OLLAMA_HOST=0.0.0.0:11434`
329+
330+
### Run ollama on openad toolkit
331+
> if prompted for api key and none was setup just leave empty
332+
```
333+
>> set llm ollama
334+
>> tell me <enter prompt>
335+
```
304336

305337
<br>
306338

@@ -410,4 +442,4 @@ You will need to restart your Linux session before running `pip install openad`
410442

411443
If you get an error when running `init_magic`, you may first need to setup the default iPython profile for magic commands.
412444

413-
ipython profile create
445+
`ipython profile create`

openad/app/magic/openad_magic.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import pandas
4+
import atexit
45

56
# required for Magic Template
67
from IPython.display import Markdown
@@ -110,3 +111,11 @@ def strip_leading_blanks(input):
110111

111112
ip = get_ipython() # pylint: disable=undefined-variable
112113
ip.register_magics(AD)
114+
115+
116+
def cleanup():
117+
print("killing magic")
118+
openad.app.main.MAGIC_PROMPT.do_exit("exit magic")
119+
120+
121+
atexit.register(cleanup)

openad/app/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,6 @@ def api_remote(
859859
MAGIC_PROMPT = magic_prompt
860860
else:
861861
magic_prompt = MAGIC_PROMPT
862-
863862
if api_context["workspace"] is None:
864863
api_context["workspace"] = magic_prompt.settings["workspace"]
865864
else:
@@ -907,6 +906,7 @@ def api_remote(
907906

908907
# Triggered by magic commands, eg. `%openad ? list files`
909908
starts_with_qmark = len(inp) > 0 and inp.split()[0] == "?" and inp.strip() != "??"
909+
magic_prompt.do_exit("dummy do not remove")
910910
return magic_prompt.do_help(inp.strip(), jup_return_format=None, display_info=starts_with_qmark)
911911

912912
# If there is a argument and it is not a help attempt to run the command.
@@ -920,8 +920,6 @@ def api_remote(
920920
result = magic_prompt.default(inp)
921921
api_context["workspace"] = magic_prompt.settings["workspace"]
922922
api_context["toolkit"] = magic_prompt.settings["context"]
923-
924-
magic_prompt.do_exit("dummy do not remove")
925923
if result is not True and result is not False:
926924
return result
927925

openad/flask_apps/molsgrid/routes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ def render_mols2grid():
146146
else:
147147
# Display the grid.
148148
m2g_params = _compile_default_m2g_params(mol_frame)
149+
import sys
150+
151+
# ToDO silence redunant error for RISE
149152

150153
return None, the_mols2grid.display(**m2g_params)
151154

openad/llm_assist/model_reference.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,25 @@
9999
"model": "instructlab/granite-7b-lab",
100100
"url": OLLAMA_HOST,
101101
"template": """You are a technical documentation writer and when responding follow the following rules:
102-
- Format All Command Syntax, Clauses, Examples or Option Syntax in codeblock ipython Markdown
102+
- Respond like you were writing a refernce guide for a software package
103+
- Format All Command Syntax, Clauses, Examples or Option Syntax in codeblock ipython Markdown
103104
- Format all Command Syntax, Options or clause quotations in codeblock ipython Markdown
104-
- reply with all the paramters or options for a command from the help text if syntax requested
105105
- Only format codeblocks one line at a time and place them on single lines
106106
- For each instruction used in an answer also provide full command syntax with clauses and options in codeblock format. for example " Use the `search collection` with the 'PubChem' collection to search for papers and molecules. \n\n command: ` search collection '<collection name or key>' for '<search string>' using ( [ page_size=<int> system_id=<system_id> edit_distance=<integer> display_first=<integer>]) show (data|docs) [ estimate only|return as data|save as '<csv_filename>' ] ` \n
107107
\n For Example: ` search collection 'PubChem' for 'Ibuprofen' show ( data ) ` \n"
108108
- Provide All syntax, clauses, Options, Parameters and Examples separated by "\n" for a command when answering a question with no leading spaces on the line
109-
- ensure bullet lines are indented consistently
110109
- Compounds and Molecules are the same concept
111-
- smiles or inchi strings are definitions of compounds or smiles
112110
- Always explain using the full name not short form of a name
113-
- Always list all parameters for a command
111+
- Never refer to source files from the embeddings
114112
- after explaning a command tell them how to go to the help using `<command> ?` substituing the command into the string
115-
- if asked to tell the user about a command , display the commands help
113+
- respond with a output format as per following example
114+
'''Command: <put command syntax here >
115+
116+
Description: <brief description of funciton
116117
117-
118-
118+
Parameters: < Tell the user what Parameters are available for the comand>
119119
120+
Examples: < examples of how to use the function> '''
120121
121122
Answer the question based only on the following
122123
context: {context}
@@ -125,10 +126,12 @@
125126
126127
Answer:""",
127128
"settings": {
128-
"temperature": 0.3,
129+
"temperature": 0.5,
129130
"decoding_method": "greedy",
130-
"max_new_tokens": 4000,
131+
"max_new_tokens": 3000,
131132
"min_new_tokens": 1,
133+
"top_p": 0.85,
134+
"top_k": 50,
132135
},
133136
"embeddings": None,
134137
"embeddings_api": None,

openad/user_toolkits/RXN/fn_reactions/fn_predict_retro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def __init__(self):
220220
except Exception as e: # pylint: disable=broad-exception-caught
221221
retries = retries + 1
222222
sleep(15)
223+
223224
newspin.text = "Processing Retrosynthesis: Waiting"
224225
if retries > 20:
225226
raise Exception(

0 commit comments

Comments
 (0)