Skip to content

Commit

Permalink
Remove code block before returning response (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepak-Kesavan authored Mar 22, 2024
1 parent f6d3ffc commit d87222e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/unstract/sdk/llm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
import time
from typing import Any, Optional

Expand All @@ -7,6 +8,7 @@
from unstract.adapters.constants import Common
from unstract.adapters.llm import adapters
from unstract.adapters.llm.llm_adapter import LLMAdapter

from unstract.sdk.adapters import ToolAdapter
from unstract.sdk.constants import LogLevel, ToolSettingsKey
from unstract.sdk.tool.base import BaseTool
Expand Down Expand Up @@ -51,9 +53,14 @@ def run_completion(
ServiceContext.get_service_context(
platform_api_key=platform_api_key, llm=llm
)
code_block_pattern = re.compile(r"```.*?\n(.*?)\n```", re.DOTALL)
for i in range(retries):
try:
response: CompletionResponse = llm.complete(prompt, **kwargs)
match = code_block_pattern.search(response.text)
if match:
# Remove code block from response text
response.text = match.group(1)
result = {
"response": response,
}
Expand Down

0 comments on commit d87222e

Please sign in to comment.