Skip to content

Commit

Permalink
fix: process markdown url in knowledge base
Browse files Browse the repository at this point in the history
  • Loading branch information
zhayujie committed Dec 11, 2023
1 parent be0bb59 commit 95260e3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bot/linkai/link_ai_bot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# access LinkAI knowledge base platform
# docs: https://link-ai.tech/platform/link-app/wechat

import re
import time

import requests

import config
from bot.bot import Bot
from bot.chatgpt.chat_gpt_session import ChatGPTSession
Expand Down Expand Up @@ -125,6 +124,7 @@ def _chat(self, query, context, retry_count=0) -> Reply:
thread.start()
if response["choices"][0].get("text_content"):
reply_content = response["choices"][0].get("text_content")
reply_content = self._process_url(reply_content)
return Reply(ReplyType.TEXT, reply_content)

else:
Expand Down Expand Up @@ -355,6 +355,14 @@ def _fetch_agent_suffix(self, response):
except Exception as e:
logger.exception(e)

def _process_url(self, text):
try:
url_pattern = re.compile(r'\[(.*?)\]\((http[s]?://.*?)\)')
def replace_markdown_url(match):
return f"{match.group(2)}"
return url_pattern.sub(replace_markdown_url, text)
except Exception as e:
logger.error(e)

def _send_image(self, channel, context, image_urls):
if not image_urls:
Expand Down

0 comments on commit 95260e3

Please sign in to comment.