|
7 | 7 | import asyncio |
8 | 8 | import traceback |
9 | 9 | from typing import Any, Optional, cast |
| 10 | +from urllib.parse import urljoin |
10 | 11 |
|
11 | 12 | from llama_stack_api.openai_responses import ( |
12 | 13 | OpenAIResponseMessage as ResponseMessage, |
@@ -565,27 +566,18 @@ async def build_rag_context( |
565 | 566 |
|
566 | 567 |
|
567 | 568 | def _join_okp_doc_url(base_url: AnyUrl, reference: Optional[str]) -> str: |
568 | | - """Build a well-formed document URL from base and reference. |
569 | | -
|
570 | | - If reference is None or empty, returns ''. |
571 | | - If reference already starts with 'http', returns reference unchanged. |
572 | | - Otherwise normalizes ``base_url`` to end with a single '/', strips any leading |
573 | | - '/' from reference, and concatenates. |
| 569 | + """Build a well-formed document URL from base and reference path. |
574 | 570 |
|
575 | 571 | Args: |
576 | 572 | base_url: OKP base URL. |
577 | | - reference: Document path or full URL. |
| 573 | + reference: Origin-relative document path (e.g. ``/docs/foo``). |
578 | 574 |
|
579 | 575 | Returns: |
580 | | - Well-formed doc_url string. |
| 576 | + Well-formed doc_url string, or empty string if reference is empty. |
581 | 577 | """ |
582 | 578 | if not reference: |
583 | 579 | return "" |
584 | | - if reference.startswith("http"): |
585 | | - return reference |
586 | | - base = str(base_url).rstrip("/") + "/" |
587 | | - ref = reference.lstrip("/") |
588 | | - return base + ref |
| 580 | + return urljoin(str(base_url), reference) |
589 | 581 |
|
590 | 582 |
|
591 | 583 | def _build_document_url( |
|
0 commit comments