pytilpack.htmlrag¶
必要なextra
pip install pytilpack[htmlrag]
pytilpack.htmlrag
¶
HtmlRAG関連。
clean_html だけを使用したい場合に依存関係が厳しいため、切り出したものを用意する。 加えて独自の拡張を行っている。
https://github.com/plageon/HtmlRAG/blob/main/toolkit/README.md https://github.com/plageon/HtmlRAG/blob/main/toolkit/LICENSE https://github.com/plageon/HtmlRAG/blob/main/toolkit/htmlrag/html_utils.py
DEFAULT_ACCEPT = 'text/markdown,text/plain;q=0.9,text/html,application/xhtml+xml,application/xml;q=0.8,*/*;q=0.7'
module-attribute
¶
Acceptヘッダーのデフォルト値。
fetch_url(url, no_verify=False, accept=DEFAULT_ACCEPT, user_agent=None)
¶
URLからHTMLを取得し、簡略化して返す。
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
url
|
str
|
取得するURL |
必須 |
no_verify
|
bool
|
SSL証明書の検証を無効化するかどうか |
False
|
accept
|
str
|
受け入れるコンテンツタイプ |
DEFAULT_ACCEPT
|
user_agent
|
str | None
|
User-Agentヘッダー(未指定時はデフォルト値を使用) |
None
|
戻り値:
| タイプ | デスクリプション |
|---|---|
str
|
簡略化されたHTML内容 |
発生:
| タイプ | デスクリプション |
|---|---|
Exception
|
HTTP取得やHTMLパースでエラーが発生した場合 |
ソースコード位置: pytilpack/htmlrag.py
get_default_user_agent()
¶
clean_html(html, aggressive=False, keep_title=None, keep_href=None, remove_span=None)
¶
HTMLからLLM向けに不要なタグを削除する。
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
html
|
str | bytes
|
HTML文字列 |
必須 |
aggressive
|
bool
|
より強力な削除を行うか否か。Defaults to False. |
False
|
keep_title
|
bool | None
|
titleタグを残すか否か。Defaults to 'not aggressive'. |
None
|
keep_href
|
bool | None
|
href属性を残すか否か。Defaults to 'not aggressive'. |
None
|
remove_span
|
bool | None
|
spanタグを削除するか否か。(deprecated) |
None
|
戻り値:
| タイプ | デスクリプション |
|---|---|
str
|
処理後のHTML文字列 |