File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change 11import logging
2+ import re
23import time
34from typing import Any , Optional
45
78from unstract .adapters .constants import Common
89from unstract .adapters .llm import adapters
910from unstract .adapters .llm .llm_adapter import LLMAdapter
11+
1012from unstract .sdk .adapters import ToolAdapter
1113from unstract .sdk .constants import LogLevel , ToolSettingsKey
1214from unstract .sdk .tool .base import BaseTool
@@ -51,9 +53,14 @@ def run_completion(
5153 ServiceContext .get_service_context (
5254 platform_api_key = platform_api_key , llm = llm
5355 )
56+ code_block_pattern = re .compile (r"```.*?\n(.*?)\n```" , re .DOTALL )
5457 for i in range (retries ):
5558 try :
5659 response : CompletionResponse = llm .complete (prompt , ** kwargs )
60+ match = code_block_pattern .search (response .text )
61+ if match :
62+ # Remove code block from response text
63+ response .text = match .group (1 )
5764 result = {
5865 "response" : response ,
5966 }
You can’t perform that action at this time.
0 commit comments