refactor: Move the checking of protocol and prepending protocol inside api handlers
This commit is contained in:
@@ -48,6 +48,8 @@ async def handle_llm_qa(
|
|||||||
) -> str:
|
) -> str:
|
||||||
"""Process QA using LLM with crawled content as context."""
|
"""Process QA using LLM with crawled content as context."""
|
||||||
try:
|
try:
|
||||||
|
if not url.startswith(('http://', 'https://')):
|
||||||
|
url = 'https://' + url
|
||||||
# Extract base URL by finding last '?q=' occurrence
|
# Extract base URL by finding last '?q=' occurrence
|
||||||
last_q_index = url.rfind('?q=')
|
last_q_index = url.rfind('?q=')
|
||||||
if last_q_index != -1:
|
if last_q_index != -1:
|
||||||
@@ -61,7 +63,7 @@ async def handle_llm_qa(
|
|||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
detail=result.error_message
|
detail=result.error_message
|
||||||
)
|
)
|
||||||
content = result.markdown.fit_markdown
|
content = result.markdown.fit_markdown or result.markdown.raw_markdown
|
||||||
|
|
||||||
# Create prompt and get LLM response
|
# Create prompt and get LLM response
|
||||||
prompt = f"""Use the following content as context to answer the question.
|
prompt = f"""Use the following content as context to answer the question.
|
||||||
@@ -377,6 +379,7 @@ async def handle_crawl_request(
|
|||||||
) -> dict:
|
) -> dict:
|
||||||
"""Handle non-streaming crawl requests."""
|
"""Handle non-streaming crawl requests."""
|
||||||
try:
|
try:
|
||||||
|
urls = [('https://' + url) if not url.startswith(('http://', 'https://')) else url for url in urls]
|
||||||
browser_config = BrowserConfig.load(browser_config)
|
browser_config = BrowserConfig.load(browser_config)
|
||||||
crawler_config = CrawlerRunConfig.load(crawler_config)
|
crawler_config = CrawlerRunConfig.load(crawler_config)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user