Skip to content

Commit

Permalink
fix: default base_url for fetch and afetch
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Feb 6, 2024
1 parent 1d2c631 commit 9c50c75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions python/promplate/prompt/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,23 @@ async def aread(cls, path: str | Path, encoding="utf-8"):
return obj

@classmethod
def _patch_kwargs(cls, kwargs: dict):
return {
"follow_redirects": True,
"base_url": "https://promplate.dev/",
"headers": {"User-Agent": get_user_agent(cls)},
} | kwargs
def _patch_kwargs(cls, kwargs: dict) -> dict:
return {"headers": {"User-Agent": get_user_agent(cls)}} | kwargs

@staticmethod
def _join_url(url: str):
if url.startswith("http"):
return url

from urllib.parse import urljoin

return urljoin("https://promplate.dev/", url)

@classmethod
def fetch(cls, url: str, **kwargs):
from .utils import _get_client

response = _get_client().get(url, **cls._patch_kwargs(kwargs))
response = _get_client().get(cls._join_url(url), **cls._patch_kwargs(kwargs))
obj = cls(response.raise_for_status().text)
obj.name = Path(url).stem
return obj
Expand All @@ -166,7 +171,7 @@ def fetch(cls, url: str, **kwargs):
async def afetch(cls, url: str, **kwargs):
from .utils import _get_aclient

response = await _get_aclient().get(url, **cls._patch_kwargs(kwargs))
response = await _get_aclient().get(cls._join_url(url), **cls._patch_kwargs(kwargs))
obj = cls(response.raise_for_status().text)
obj.name = Path(url).stem
return obj
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "promplate"
version = "0.3.3"
version = "0.3.3.1"
description = "cross-language prompt engineering framework"
homepage = "https://promplate.dev/"
documentation = "https://docs.py.promplate.dev/"
Expand Down

0 comments on commit 9c50c75

Please sign in to comment.