Purpose

During the teaching assistance process conducted by the HP team, they noticed that the Expert Mode was not suitable for middle and primary school students: due to their relative lack of foundational knowledge in synthetic biology, they would find it difficult to express their needs for complete synthetic biology products in a structured way, and this frustration could further lead to unnecessary anxiety and resistance toward synthetic biology.

However, our team’s original intention is to promote synthetic biology to everyone, enabling all to utilize synthetic biology for their own purposes. The Expert Mode, which is not particularly friendly to newcomers, clearly does not align with the team’s goals. Therefore, we need a more user-friendly interactive method that can be used through common conversational formats in daily life, to lower the threshold for using our model and truly achieve the popularization of synthetic biology.

Design

To achieve conversational interaction, we need a large language model as support. We have chosen the same Llama3-8B-Ins as used in Extraction to support this dialogue, ensuring high performance and reusable experience in model deployment and tuning.

Considering that beginner users may be unfamiliar with synthetic biology, we might encounter issues where initial user descriptions lack detail or are incomplete. Therefore, we also need to engage in multiple rounds of dialogue and confirm with the user whether their needs have indeed been met after summarizing them.

To allow multiple users to access conversations simultaneously, we chose to run a single Llama3 instance and switch user contexts by passing different dialogue contexts. Each user is randomly assigned a SessionID for unique identification; to ensure user privacy, the SessionID is destroyed after the conversation ends. Additionally, to avoid excessive concurrency, we opted for a strategy to discard the earliest inactive conversations when the number of connected users exceeds a certain threshold.

Furthermore, to allow users to search for components and generate plasmids with one click after fully expressing their needs, our Freshman Mode should also connect to Expert Mode for one-click migration of user demand data. To achieve this, we enabled the large model to extract the desired functions of components and plasmids from longer dialogues, further summarizing them into a JSON object suitable for data exchange.

If the large model successfully organizes the user's needs in JSON format, we report this and provide a button for the user to send that request to Expert Mode for further processing, as detailed in "Match" (to the Match page).

Implementation

In this phase, it's worth mentioning the prompts used at various stages of Llama3.

We first assigned the role of a "friendly synthetic biology expert" to the large model, enabling it to exhibit both professional synthetic biology techniques and a friendly demeanor, providing a good first impression for beginner users. We also specified a detailed workflow, especially that if sufficient information is obtained and the final design is confirmed by the user, it outputs a specific END OF CONVERSATION message to be recognized and enter the next phase; otherwise, it should further inquire about the model's misunderstandings or redesign until the user is satisfied.

system_prompt_1 = {"role": "system", "content": """
...
#Character#
You're an expert in synthetic biology, user-friendly to people who don't know the field, and adept at extracting key points from conversations. You will have a conversation with the user and eventually output a piece of text describing the user's needs.
...
1. You talk to the user and ask him what functions he needs for a synthetic biology component;
2. If you get enough information, jump to step 3, otherwise jump to step 5;
3. You summarize all your conversations with the user, output a text describing the user's needs for synthetic biology components and ask the user if they are satisfied;
4. If the user is satisfied, you terminate the conversation and output "END OF CONVERSATION", otherwise jump to step 5;
5. Based on the current conversation, you ask the user for further information and jump to step 2.
...
"""}

Next, we assigned the role of JSON format extractor to the large model. We also specified optional categories to ensure consistency with the formats recorded in the database.

system_prompt_2 = {"role": "system", "content": f"""
...
#Character#
You are an expert in synthetic biology who is good at summarizing the function of plasmids and giving the categories and functions of the individual components they contain...
...
#Allowed component types#
{json.dumps(catalog)}
...
"""}

However, we noticed that the large model not only outputs JSON format objects but also some additional content, which is difficult to eliminate solely through prompt engineering. Therefore, we opted to engage in an additional round of dialogue to precisely extract only the JSON object from the previous output, and this attempt effectively improved the success rate of extraction and summarization.

Nonetheless, the large model occasionally still fails to output the JSON format correctly and may make minor spelling errors in component categories. To address this, we prepared a recommend(type_name) function driven entirely by string matching, to correct any spelling errors in component types and recommend the most likely intended meaning. As for JSON format errors, after several experiments, we found that the large model might drop the outer [] and , in the JSON format, so we added code to automatically supplement these components when detected as missing. If the aforementioned fixes still do not result in a correctly formatted JSON (though this situation is very rare), we will return an error to prevent larger failures in the next phase.

class FreshmanMode():
    def get_json(self, target):
        messages, outputs, reply = ...
        if reply[0] == "{":
            reply = "[" + reply.replace("}", "},", reply.count("}") - 1) + "]"
        try:
            reply = json.loads(reply)
            for i in reply:
                i["type"] = recommend(i["type"])
        except:
            reply = [{"type": "ERROR", "description": "ERROR"}]
        return json.dumps(reply)

It’s noteworthy that the large model itself also has the ability to call function tools. This means another possible implementation solution is to provide a function interface add_part(part_type, part_desc) and then generate JSON format information by writing corresponding functions for the interface. It is easy to prove that if the large model can correctly call this interface, it will ultimately obtain correctly formatted JSON user requirements. However, we ultimately abandoned this approach.

According to the official Llama3 documentation[1], its User-defined Custom tool calling functionality is implemented through specially pre-trained prompts. Moreover, this functionality returns only an object that must repeatedly adhere to the given tool calling format, containing the function name and parameters when calling the function.

Step - 1 System prompt with custom tool details

...
# Tool Instructions
- Always execute python code in messages that you share.
- When looking for real time information use relevant functions if available else fallback to brave_search

You have access to the following functions:

Use the function 'spotify_trending_songs' to: Get top trending songs on Spotify
{
 "name": "spotify_trending_songs",
 "description": "Get top trending songs on Spotify",
 "parameters": {
   "n": {
     "param_type": "int",
     "description": "Number of trending songs to get",
     "required": true
   }
 }
}

If a you choose to call a function ONLY reply in the following format:
<{start_tag}={function_name}>{parameters}{end_tag}
where

start_tag => ` a JSON dict with the function argument name as key and function argument value as value.
end_tag => ``

Here is an example,
{"example_name": "example_value"}

Reminder:
- Function calls MUST follow the specified format
- Required parameters MUST be specified
- Only call one function at a time
- Put the entire function call reply on one line
- Always add your sources when using search results to answer the user query
...

During our use of another large model, Qwen-2, we noticed that the model often makes parameter naming errors and fails to fully understand the function calling format when implementing tool function calls through prompt engineering, requiring additional corrections. Thus, we judged that relying solely on tool calls to generate JSON format would also encounter issues needing manual corrections, and fundamentally, it is also prompt engineering, which may not yield better results than directly extracting JSON format through prompt engineering and multiple dialogues, while adding too many functions required by a single large model and making the prompt too lengthy, which could complicate its understanding and execution of necessary functions. In summary, we chose to design two custom prompts specifically for JSON format extraction to better achieve the extraction of JSON formatted user requirements.

A portion of the tool call implemented with Qwen-2. Note that the large model does not understand that the first parameter name refers to dish, and in this case, the parameter refers to (name of) dish, which may lead to it naming the parameter name during the call, requiring additional judgment and correction in that function. This implies that the large model does not comprehend some descriptions well.

@register_tool("my_select")
class call_select(BaseTool):
description = "点菜服务,用于新增指定数量的选择的菜品,未指定数量则默认为1份。返回字符串,若点菜成功返回点菜结果,点菜失败返回错误信息和智能推荐。当点菜失败时,你不应对订单做任何操作。你应当将返回的字符串原样输出。任何时候你都应输出现在已有的订单。"
# Dish ordering service, used to add a specified number of selected dishes. If the quantity is not specified, it defaults to one portion. Returns a string; if the ordering is successful, returns the result, otherwise returns an error message and smart recommendations. When ordering fails, you should not perform any operations on the order. You should output the current order at all times.
parameters = [{
 "name": "dish",
 "type": "string",
 "description": "希望新增点菜的菜品的名称", # The name of the dish you wish to order.
 "required": True
}, ...]
def call(self, params: str, **kwargs) -> str:
 params = json5.loads(params)
 if "dish" not in params and "name" in params:
     params["dish"] = params["name"]
 ...

To summarize, we need to recognize the importance of language models for friendly dialogue with users, extract key information from their needs, and efficiently convert this into structured JSON format. This design process involves both prompt engineering and utilizing model capabilities. Through these iterations and explorations, we have crafted a more user-friendly Freshman Mode, facilitating the journey into the world of synthetic biology for beginners.

In this section, we use the open source Llama3-8B-Ins large language model. Detailed information about this model can be found on its official website [2] and in our brief introduction to it on Llama 3.

To use Freshman Mode, please refer to the User Guide section, or visit our demo page igem.iamdanny.online.

[1]: https://www.llama.com/docs/model-cards-and-prompt-formats/llama3_1#user-defined-custom-tool-calling.

[2]: https://www.llama.com.

BACK TO
TOP !