|
|
from promptflow.core import tool
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
class ResponseType(str, Enum):
|
|
|
CONTENT = "content"
|
|
|
SEPARATORS = "separators"
|
|
|
CODEBLOCK = "codeblock"
|
|
|
|
|
|
|
|
|
import sys, os
|
|
|
root_path = os.path.abspath(os.path.join(os.path.abspath(__file__), "../.."))
|
|
|
if root_path not in sys.path:
|
|
|
sys.path.append(root_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@tool
|
|
|
def parse_response(response_msgs, response_type: Enum):
|
|
|
from prompts.prompt_utils import parse_chunks_by_separators, match_code_block
|
|
|
|
|
|
content = response_msgs[-1]['content']
|
|
|
|
|
|
if response_type == ResponseType.CONTENT:
|
|
|
return content
|
|
|
elif response_type == ResponseType.CODEBLOCK:
|
|
|
codeblock = match_code_block(content)
|
|
|
|
|
|
if codeblock:
|
|
|
return codeblock[-1]
|
|
|
else:
|
|
|
raise Exception("ζ ζ³θ§£ζεηοΌζͺε
ε«δΈεΌε·δ»£η εγ")
|
|
|
|
|
|
elif response_type == ResponseType.SEPARATORS:
|
|
|
chunks = parse_chunks_by_separators(content, [r'\S*', ])
|
|
|
return chunks
|
|
|
else:
|
|
|
raise Exception(f"ζ ζηθ§£ζη±»εοΌ{response_type}")
|
|
|
|