Skip to content

Commit

Permalink
[fix] maxlength
Browse files Browse the repository at this point in the history
  • Loading branch information
AIboy996 committed May 22, 2024
1 parent 1108d82 commit e97fa31
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# exclude from statistics
site/* linguist-vendored
2 changes: 1 addition & 1 deletion mkdocs_ai_summary/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from mkdocs.config import config_options
from mkdocs.config.defaults import MkDocsConfig
from mkdocs.plugins import BasePlugin, get_plugin_logger
from mkdocs.plugins import BasePlugin
from mkdocs.structure.files import Files
from mkdocs.structure.pages import Page

Expand Down
7 changes: 4 additions & 3 deletions mkdocs_ai_summary/tongyi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def ask(prompt):


def get_summary_tongyi(page, prompt, markdown, cache=True, cache_dir="./"):
question = (prompt + markdown)[: MAX_LENGTH - 10]
if cache:
content_md5 = md5(markdown.encode("utf-8")).hexdigest()
cache_file = f"{cache_dir}_ai_summary_cache.json"
Expand All @@ -55,15 +56,15 @@ def get_summary_tongyi(page, prompt, markdown, cache=True, cache_dir="./"):
ai_summary = cache_dict[page]["ai_summary"]
# asked before, but content changed
else:
ai_summary = ask(prompt + markdown)
ai_summary = ask(question)
# do not aksed before
else:
ai_summary = ask(prompt + markdown)
ai_summary = ask(question)
cache_dict[page] = {"content_md5": content_md5, "ai_summary": ai_summary}
with open(f"{cache_dir}/_ai_summary_cache.json", "w+") as f:
cache_dict = json.dump(cache_dict, f)
else:
ai_summary = ask(prompt + markdown)
ai_summary = ask(question)
return f"""!!! ai-summary "AI摘要 powered by [通义千问](https://tongyi.aliyun.com/)"
{ai_summary}
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ where = ["."]

[project]
name = "mkdocs-ai-summary"
version = "0.1.0"
version = "0.1.1"
requires-python = ">=3.10"
dependencies = [
"mkdocs>=1.5.3",
Expand Down

0 comments on commit e97fa31

Please sign in to comment.