Skip to content

Developer Document

Shoichi Ishida edited this page Dec 18, 2024 · 9 revisions

Basic Information

File Locations for Each Component

Each component is implemented in the following files:

Environment Variables

The .env file contains the port information for each Web App and the API key. Below is the current configuration:

OPENAI_API_KEY=''
CHATBOT_PORT=8000
MODEL_BUILDER_PORT=8001
ANALYSIS_PORT=8002
CHEMTS_PORT=8003

This configuration information is used during Docker Compose operations.

How to Update Dependencies of Each Component

Each component manages its dependencies using Poetry, and Docker images are built based on the poetry.lock file. So, when adding or updating packages, please follow the steps below:

  1. Update the [tool.poetry.dependencies] section in pyproject.toml
  2. Run the poetry lock command to update the poetry.lock file.

This ensures the changes are properly reflected in the dependency management and Docker image builds. 

Note

If Docker containers or images already exist, make sure to remove them by running bash manage_app.sh clean before deploying the updated version.

Customize ChatChemTS

Change OpenAI's LLM to Another

Note

A GUI feature to switch between LLM models from different providers is planned for future implementation.
As such, the method described here is intended as a temporary solution.

To switch the LLM used in ChatChemTS to another provider's LLM, you will need to make modifications to at least two functions:

  1. start() in chatbot_app/app.py
  2. prepare_chat_model() in chatbot_app/util.py

Modify start() Function

In the start() function, you define the settings passed to the LLM model that can be adjusted via the GUI. Update these settings to match the requirements of the LLM you wish to use.

Note

Ensure that the setting with id="NumConversationMemory" is retained, as it is a shared requirement across all LLMs.

Modify prepare_chat_model() Function

In the prepare_chat_model() function, update the section where ChatOpenAI() is called. Modify it to align with the specifications of the chat model you intended to implement. The settings argument passed to this function contains the configurations defined in start(). For a list of chat models supported by LangChain, refer to the following documentation: https://python.langchain.com/docs/integrations/chat/

Update Dependencies

If additional Python packages are required for the new LLM, you must update the following files:

  • pyproject.toml and poetry.lock in chatbot_app/

Add the required package to chatbot_app/pyproject.toml, then run the command poetry lock to update the chatbot_app/poetry.lock file. Refer to the Poetry CLI documentation for more details.

Configure Environment Variables

If the new LLM requires API keys or other credentials to be defined as environment variables, you need to update the relevant sections in the following files to suit your requirements:

  • manage_app.sh
  • docker-compose.yaml
  • .env

Replace the references to OPENAI_API_KEY with the corresponding keys or environment variables for your chosen LLM.

Add New Molecule Generator

If you have a molecule generation AI with a similar specification to ChemTSv2, you can extend ChatChemTS by following the steps below.

Note

ChemTSv2 specifications include:

  • The reward function and config file are defined independently.
  • The config file is passed as an argument and can be executed via CLI.
  • The config file defines the reward file path, output directory, number of generated molecules, and other parameters.

For further details, please refer to the ChemTSv2 paper

1. Define New Function in api_chemtsv2/main.py

  • Create a function similar to run_chemtsv2() that takes the path to a config file as input, executes the molecule generation process using subprocess.run(), and returns the directory name containing the output files.
  • Update the corresponding API endpoint by replacing @app.post("/run/") with @app.post("/run_[ANYWORD]") to avoid conflicts with existing routes.

2. Define New Tool in chatbot_app/tools.py

  • Use ChemTSv2ApiTool as a reference to define a new tool that interacts with the API endpoint defined in Step 1.
  • Ensure that the tool sends requests to the URL you configured and accepts the path to the config file as input.
  • For details on how to define a custom tool, refer to the LangChain documentation: LangChain Custom Tools
  • Include the newly defined tool in the prepare_tools() function.
  • Ensure the description field is clearly written, as it plays a crucial role in helping the agent decide when to use this tool.

3. Update Prompts in chatbot_app/prompts.py

  • Modify the system message and prompts to include the name of your new molecule generation AI, in addition to "ChemTSv2," wherever it appears. Use the name specified in the tool's description.

4. Execution in Chat

  • When running the AI, type chat like Run [YOUR_AI_NAME] using config.yaml in the chat interface. The agent should correctly interpret the request and execute molecule generation using the newly added AI.

Customize Reward Generator Tool

Under construction.

Customize Config Generator Tool

Under construction.

Debug

How to Retrieve Logs from Docker Containers

You can inspect the raw logs using the docker logs command if you encounter errors or unexpected behaviors.

docker container ls  # List running containers to find the container names related to ChatChemTS
docker logs [CONTAINER_NAME]  # Example: chatchemts-chatbot-1 or chatchemts-api_chemtsv2-1