diff --git a/scripts/flask_modelscope/setup_ms_service.py b/scripts/flask_modelscope/setup_ms_service.py index 5f0212ef3..d22aca257 100644 --- a/scripts/flask_modelscope/setup_ms_service.py +++ b/scripts/flask_modelscope/setup_ms_service.py @@ -7,7 +7,6 @@ from flask import request import modelscope -from agentscope.utils.tools import reform_dialogue def create_timestamp(format_: str = "%Y-%m-%d %H:%M:%S") -> str: @@ -23,9 +22,7 @@ def get_response() -> dict: """Receive post request and return response""" json = request.get_json() - inputs = json.pop("inputs") - - inputs = reform_dialogue(inputs) + inputs = json.pop("messages") global model, tokenizer diff --git a/scripts/flask_transformers/setup_hf_service.py b/scripts/flask_transformers/setup_hf_service.py index 6084b6dcc..710bd74cb 100644 --- a/scripts/flask_transformers/setup_hf_service.py +++ b/scripts/flask_transformers/setup_hf_service.py @@ -7,7 +7,6 @@ from flask import request import transformers -from agentscope.utils.tools import reform_dialogue def create_timestamp(format_: str = "%Y-%m-%d %H:%M:%S") -> str: @@ -23,12 +22,10 @@ def get_response() -> dict: """Receive post request and return response""" json = request.get_json() - inputs = json.pop("inputs") + inputs = json.pop("messages") global model, tokenizer - inputs = reform_dialogue(inputs) - if hasattr(tokenizer, "apply_chat_template"): prompt = tokenizer.apply_chat_template( inputs, diff --git a/src/agentscope/models/post_model.py b/src/agentscope/models/post_model.py index 7a6dfa6ec..385881fd2 100644 --- a/src/agentscope/models/post_model.py +++ b/src/agentscope/models/post_model.py @@ -206,14 +206,14 @@ def format( ) # OpenAI - if model_name.startswith("gpt-"): + if model_name and model_name.startswith("gpt-"): return OpenAIChatWrapper.static_format( *args, model_name=model_name, ) # Gemini - elif model_name.startswith("gemini"): + elif model_name and model_name.startswith("gemini"): return GeminiChatWrapper.format(*args) # Include DashScope, ZhipuAI, Ollama, the other models supported by diff --git a/src/agentscope/utils/tools.py b/src/agentscope/utils/tools.py index 440aee1b4..f79a8b754 100644 --- a/src/agentscope/utils/tools.py +++ b/src/agentscope/utils/tools.py @@ -315,42 +315,6 @@ def _convert_to_str(content: Any) -> str: return str(content) -def reform_dialogue(input_msgs: list[dict]) -> list[dict]: - """record dialog history as a list of strings""" - messages = [] - - dialogue = [] - for i, unit in enumerate(input_msgs): - if i == 0 and unit["role"] == "system": - # system prompt - messages.append( - { - "role": unit["role"], - "content": _convert_to_str(unit["content"]), - }, - ) - else: - # Merge all messages into a conversation history prompt - dialogue.append( - f"{unit['name']}: {_convert_to_str(unit['content'])}", - ) - - dialogue_history = "\n".join(dialogue) - - user_content_template = "## Conversation History\n{dialogue_history}" - - messages.append( - { - "role": "user", - "content": user_content_template.format( - dialogue_history=dialogue_history, - ), - }, - ) - - return messages - - def _join_str_with_comma_and(elements: List[str]) -> str: """Return the JSON string with comma, and use " and " between the last two elements."""