Skip to content

Commit

Permalink
bug fix, dashscope import error
Browse files Browse the repository at this point in the history
  • Loading branch information
AIboy996 committed Dec 27, 2024
1 parent 7656060 commit b6bba5e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist
test
build
!_ai_summary_cache_chatgpt.json
!_ai_summary_cache_tongyi.json
!_ai_summary_cache_tongyi.json
.DS_Store
1 change: 0 additions & 1 deletion mkdocs_ai_summary/chatgpt_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import logging
from hashlib import md5
from openai import OpenAI
Expand Down
7 changes: 3 additions & 4 deletions mkdocs_ai_summary/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re
import logging

from .tongyi_api import AiSummaryError

logger = logging.getLogger("mkdocs.plugins.ai-summary")

Expand Down Expand Up @@ -59,7 +58,7 @@ def on_page_markdown(
match api:
case "tongyi":
try:
from .tongyi_api import get_summary
from .tongyi_api import get_summary, AiSummaryRequestError
except ImportError as e:
logger.warning("tongyi is not available", repr(e))
return markdown
Expand All @@ -75,8 +74,8 @@ def on_page_markdown(
model=model,
logger=logger,
)
except AiSummaryError as e:
logger.warning("Ask AI Error", repr(e))
except AiSummaryRequestError as e:
logger.warning("Request Tongyi AI Error", repr(e))
return markdown
except Exception as e:
logger.warning(repr(e))
Expand Down
6 changes: 3 additions & 3 deletions mkdocs_ai_summary/tongyi_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from hashlib import md5
from http import HTTPStatus
from dashscope import Generation
import logging

from .cache import with_cache, load_cache, save_cache

MAX_LENGTH = 6000


class AiSummaryError(Exception):
class AiSummaryRequestError(Exception):

def __init__(self, *args: object) -> None:
super().__init__(*args)
Expand All @@ -30,7 +30,7 @@ def ask(prompt, model="qwen-turbo"):
if response.status_code == HTTPStatus.OK:
return response["output"]["text"]
else:
raise AiSummaryError(
raise AiSummaryRequestError(
"Request id: %s, Status code: %s, error code: %s, error message: %s"
% (
response.request_id,
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.2.5"
version = "0.2.6"
requires-python = ">=3.10"
dependencies = [
"mkdocs>=1.5.3",
Expand Down

0 comments on commit b6bba5e

Please sign in to comment.