core

The core package contains the Chat class central to this package.

The following line loads the OpenRouter api key from the .env file which is hidden from you. To use this notebook, either create a .env file containing OPENROUTER_API_KEY=your_api_key or uncomment the os.environ assignment below and set it to your personal api key.

load_dotenv("../.env")
# os.environ['OPENROUTER_API_KEY'] = <your OpenRouter api key>
True

source

show

 show (string)

source

Chat

 Chat (model)

Initialize self. See help(type(self)) for accurate signature.


source

Chat.save_conversation

 Chat.save_conversation (generate_title=True)
model = "google/gemini-2.0-pro-exp-02-05:free"
chat = Chat(model)
chat("Give me the canonical SMILES string of ibuprofen. Output only the SMILES string and nothing else.")

CC(C)Cc1ccc(C(C)C(=O)O)cc1

from rdkit import Chem
from rdkit.Chem import Draw
names = ["ibuprofen"]
smiles = [chat.context[-1]['content']]

Draw.MolsToGridImage(mols=[Chem.MolFromSmiles(x) for x in smiles], 
                     molsPerRow=5, subImgSize=(400,300), legends=names)

chat.save_conversation(generate_title=False)
'Saving complete!'
chat.save_conversation()
'Saving complete!'
chat.title
'ibuprofen-smiles-string-generation'
chat.usage
[{'prompt_tokens': 21, 'completion_tokens': 20, 'total_tokens': 41},
 {'prompt_tokens': 73, 'completion_tokens': 9, 'total_tokens': 82}]
chat.usage_summary()
Input tokens: 94
Output tokens: 29
Total tokens: 123
chat.date
1740427285

source

Chat.print_conversation

 Chat.print_conversation (user='Me')
chat.print_conversation()

Ibuprofen smiles string generation

Me: Give me the canonical SMILES string of ibuprofen. Output only the SMILES string and nothing else.

Gemini: CC(C)Cc1ccc(C(C)C(=O)O)cc1


source