The Custom Server is used to store user-defined utility functions that do not belong to standard modules such as Retriever, Generation, or Evaluation.
It provides developers with a flexible extension space for implementing logic components that work in coordination with core RAG modules, such as:
The following example demonstrates how to define and register a custom Tool, using a common function output_extract_from_boxed as an example.
servers/custom/src/custom.py
Copy
@app.tool(output="ans_ls->pred_ls")def output_extract_from_boxed(ans_ls: List[str]) -> Dict[str, List[str]]: def extract(ans: str) -> str: start = ans.rfind(r"\boxed{") if start == -1: content = ans.strip() else: i = start + len(r"\boxed{") brace_level = 1 end = i while end < len(ans) and brace_level > 0: if ans[end] == "{": brace_level += 1 elif ans[end] == "}": brace_level -= 1 end += 1 content = ans[i : end - 1].strip() content = re.sub(r"^\$+|\$+$", "", content).strip() content = re.sub(r"^\\\(|\\\)$", "", content).strip() if content.startswith(r"\text{") and content.endswith("}"): content = content[len(r"\text{") : -1].strip() content = content.strip("()").strip() content = content.replace("\\", " ") content = content.replace(" ", " ") return content return {"pred_ls": [extract(ans) for ans in ans_ls]}
This Tool extracts the final answer text in the \boxed{...} format from model output strings.
The extracted results are mapped to the variable pred_ls, which can then be used by downstream evaluation or post-processing modules.
In this example, custom.output_extract_from_boxed is used to extract standardized answers from model outputs,
which are then passed to evaluation.evaluate for further evaluation.