Skip to content

fix(wren-ai-service): The DeepSeek response may not be a valid JSON format. #1529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion wren-ai-service/src/providers/llm/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from src.providers.loader import provider
from src.utils import remove_trailing_slash
from src.utils import extract_braces_content


@provider("litellm_llm")
Expand Down Expand Up @@ -106,7 +107,7 @@ async def _run(
check_finish_reason(response)

return {
"replies": [message.content for message in completions],
"replies": [extract_braces_content(message.content) for message in completions],
"meta": [message.meta for message in completions],
}

Expand Down
10 changes: 10 additions & 0 deletions wren-ai-service/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,13 @@ async def wrapper(*args, **kwargs):
return results

return wrapper

# For adapting deepseek response content contains "```json{....}```"
def extract_braces_content(resp: str) -> str:
start = resp.find('{')
end = resp.rfind('}')

if start == -1 or end == -1 or end <= start:
return resp

return resp[start:end+1]