(name: str, state: PipelineState, prompt_template: str, llm)
| 67 | return state |
| 68 | |
| 69 | def execute_tool(name: str, state: PipelineState, prompt_template: str, llm) -> PipelineState: |
| 70 | |
| 71 | logger(f"{name} is working...") |
| 72 | |
| 73 | state["history"] = clip_history(state["history"]) |
| 74 | |
| 75 | generation = create_llm_chain(prompt_template, llm, state["history"]) |
| 76 | |
| 77 | # Sanitize the generation output by removing invalid control characters |
| 78 | sanitized_generation = re.sub(r'[\x00-\x1F\x7F]', '', generation) |
| 79 | |
| 80 | logger(sanitized_generation) |
| 81 | |
| 82 | data = json.loads(sanitized_generation) |
| 83 | |
| 84 | choice = data |
| 85 | tool_name = choice["function"] |
| 86 | args = choice["args"] |
| 87 | |
| 88 | if tool_name not in tool_registry: |
| 89 | raise ValueError(f"Tool {tool_name} not found in registry.") |
| 90 | |
| 91 | result = tool_registry[tool_name](*args) |
| 92 | |
| 93 | # Flatten args to a string |
| 94 | flattened_args = ', '.join(map(str, args)) |
| 95 | |
| 96 | logger(f"\nExecuted Tool: {tool_name}({flattened_args}) Result is: {result}") |
| 97 | |
| 98 | |
| 99 | state["history"] += f"\nExecuted {tool_name}({flattened_args}) Result is: {result}" |
| 100 | state["history"] = clip_history(state["history"]) |
| 101 | |
| 102 | return state |
| 103 | |
| 104 | def condition_switch(name:str, state: PipelineState, prompt_template: str, llm) -> PipelineState: |
| 105 | logger(f"{name} is working...") |
no test coverage detected