Unverified Commit 79425521 authored by jinyuan sun's avatar jinyuan sun Committed by GitHub
Browse files

Merge branch 'main' into get_ride_of_openai

parents c9d44988 0685660e
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -135,6 +135,9 @@ python miniGUI.py
Here is a screenshot of the miniGUI:
Here is a screenshot of the miniGUI:
![img](./assets/chatmol_lite.png)
![img](./assets/chatmol_lite.png)


## Acknowledgements

As an open source project, we thank the support from [ChemXAI](https://www.chemxai.com/), [WeComput](https://www.wecomput.com/) and [levinthal](https://www.levinthal.bio/).


## License
## License
This project is released under the MIT License.
This project is released under the MIT License.
+6 −5
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@ from pymol import cmd
import http.server
import http.server


class PyMOLCommandHandler(http.server.BaseHTTPRequestHandler):
class PyMOLCommandHandler(http.server.BaseHTTPRequestHandler):

    def __init__(self):
    def __init__(self):
        
        
        from http import HTTPStatus
        from http import HTTPStatus
@@ -107,9 +108,9 @@ def load_api_key():
        print("API key loaded from environment variable.")
        print("API key loaded from environment variable.")
    return client
    return client
    
    
def update_model(mdoel_name):
def update_model(model_name):
    global GPT_MODEL
    global GPT_MODEL
    GPT_MODEL = mdoel_name
    GPT_MODEL = model_name
    print("Model updated to: ", GPT_MODEL)
    print("Model updated to: ", GPT_MODEL)
    return "Model updated to: " + GPT_MODEL
    return "Model updated to: " + GPT_MODEL


@@ -120,7 +121,7 @@ def chat_with_gpt(message, max_history=10):


    try:
    try:
        messages = [
        messages = [
            {"role": "system", "content": "You are an AI language model specialized in providing command line code solutions related to PyMOL. Generate clear and effective solutions in a continuous manner. When providing demos or examples, try to use 'fetch' if object name is not provided. Prefer academic style visulizations. Code within triple backticks, comment and code should not in the same line."}
            {"role": "system", "content": "You are an AI language model specialized in providing command line code solutions related to PyMOL. Generate clear and effective solutions in a continuous manner. You think step-by-step before you conclude correctly. When providing demos or examples, try to use 'fetch' if object name is not provided. Prefer academic style visulizations. Code within triple backticks, comment and code should not in the same line."}
        ]
        ]


        # Keep only the max_history latest exchanges to avoid making the conversation too long
        # Keep only the max_history latest exchanges to avoid making the conversation too long
+3 −2
Original line number Original line Diff line number Diff line
@@ -8,7 +8,7 @@ class ChatMol:
    def __init__(self,
    def __init__(self,
                openai_api_key=None, 
                openai_api_key=None, 
                verbose=False,
                verbose=False,
                gpt_model="gpt-3.5-turbo-1106",
                gpt_model="gpt-4o",
                chatgpt_max_history=10,
                chatgpt_max_history=10,
                chatgpt_temp=0,
                chatgpt_temp=0,
                chatgpt_max_tokens=2048,
                chatgpt_max_tokens=2048,
@@ -29,6 +29,7 @@ class ChatMol:
        self.claude_conversation_messages = []
        self.claude_conversation_messages = []
        self.chatmol_llm_conversation_history = []
        self.chatmol_llm_conversation_history = []
        self.chatgpt_sys_prompt = "You are an expert familiar with PyMOL and specialized in providing PyMOL command line code solutions accuratly, and concisely. "
        self.chatgpt_sys_prompt = "You are an expert familiar with PyMOL and specialized in providing PyMOL command line code solutions accuratly, and concisely. "
        self.chatgpt_sys_prompt += "You think step-by-step before you conclude correctly. "
        self.chatgpt_sys_prompt += "When providing demos or examples, try to use 'fetch' if object name is not provided. "
        self.chatgpt_sys_prompt += "When providing demos or examples, try to use 'fetch' if object name is not provided. "
        self.chatgpt_sys_prompt += "Prefer academic style visulizations. Code within triple backticks, comment and code should not in the same line. "
        self.chatgpt_sys_prompt += "Prefer academic style visulizations. Code within triple backticks, comment and code should not in the same line. "
        self.chatmol_llm_prompt_dict = {
        self.chatmol_llm_prompt_dict = {
+1 −1
Original line number Original line Diff line number Diff line
@@ -231,7 +231,7 @@ def func_schema_gen(registry):
            if (p_desc.find('Optional') == -1 and p_desc.find('optional') == -1):
            if (p_desc.find('Optional') == -1 and p_desc.find('optional') == -1):
                required.append(param_name)
                required.append(param_name)
            props[param_name] = {'type':"string","description":param_desc[param_name]}
            props[param_name] = {'type':"string","description":param_desc[param_name]}
        params['reguired'] = required
        params['required'] = required
        func_schema['parameters'] = params
        func_schema['parameters'] = params
        func_sche_dict[r['service_name']] = func_schema
        func_sche_dict[r['service_name']] = func_schema
        pprint.pprint(func_schema)
        pprint.pprint(func_schema)
+1 −1
Original line number Original line Diff line number Diff line
@@ -210,7 +210,7 @@ if "messages" not in st.session_state or st.session_state.messages == []:
    st.session_state.messages = [
    st.session_state.messages = [
        {
        {
            "role": "system",
            "role": "system",
            "content": f"You are ChatMol copilot, a helpful copilot in molecule analysis with tools. Use tools only when you need them. Answer to questions related molecular modelling. When providing file path for downloading, use the realpath of the file without modification, it should be looks like: [link name](http://localhost:3333/work_dr/filename.suffix), the current work_dir is {work_dir}",
            "content": f"You are ChatMol copilot, a helpful copilot in molecule analysis with tools. You think step-by-step before you conclude correctly. Use tools only when you need them. Answer to questions related molecular modelling. When providing file path for downloading, use the realpath of the file without modification, it should be looks like: [link name](http://localhost:3333/work_dr/filename.suffix), the current work_dir is {work_dir}",
        }
        }
    ]
    ]
    if st.session_state.openai_model.startswith("glm"):
    if st.session_state.openai_model.startswith("glm"):