Create PyLint2.yaml #2
Annotations
35 errors and 1 warning
/home/runner/work/LLSA-Fixed/LLSA-Fixed/AI.py#L9
from tkinter import filedialog
import uvicorn
from typing import Generator, List, Dict, Union
import json
except ImportError as e:
- print('[Error] 无法正确引入库。错误信息:' + e)
+ print("[Error] 无法正确引入库。错误信息:" + e)
+
def Logo_Print():
- Logo = f''' ____ _ _ _ ___
+ Logo = f""" ____ _ _ _ ___
/ ___| ___ | | _ _ __| | / \\ |_ _|
| | / _ \\ | | | | | | / _` | / _ \\ | |
| |___ | (_) | | | | |_| | | (_| | / ___ \\ | |
- \\____| \\___/ |_| \\__,_| \\__,_| /_/ \\_\\ |___|'''
+ \\____| \\___/ |_| \\__,_| \\__,_| /_/ \\_\\ |___|"""
print(Logo)
def ReadConfigFile():
"""配置文件读取"""
- with open("config.json", 'r', encoding='utf-8') as file:
+ with open("config.json", "r", encoding="utf-8") as file:
config_content = file.read()
return json.loads(config_content)
+
Config = ReadConfigFile()
-Headers = {
- "ca":Config["ca"]
-}
+Headers = {"ca": Config["ca"]}
+
class AIApiClient:
- def __init__(self, api_endpoint: str = 'https://ai.coludai.cn/'):
+ def __init__(self, api_endpoint: str = "https://ai.coludai.cn/"):
"""
初始化 AIApiClient 类实例
Args:
api_endpoint (str): API 的基础 URL,默认为 'https://ai.coludai.cn/'。
|
/home/runner/work/LLSA-Fixed/LLSA-Fixed/AI.py#L45
self.api_endpoint = api_endpoint
def md5(self, text: str) -> str:
"""生成字符串的 MD5 哈希值"""
m = hashlib.md5()
- m.update(text.encode('utf-8'))
+ m.update(text.encode("utf-8"))
return m.hexdigest()
def gen_token(self, text: str) -> str:
"""生成基于当前日期和输入文本的 token"""
now_date = date.today().strftime("%Y-%m-%d")
date_md5 = self.md5(now_date)[:6]
return self.md5(text + date_md5)
- def make_request(self, endpoint: str, data: dict, headers: dict = Headers, download: bool = False, file_key: str = None) -> Union[Dict[str, str], Generator[str, None, None]]:
+ def make_request(
+ self,
+ endpoint: str,
+ data: dict,
+ headers: dict = Headers,
+ download: bool = False,
+ file_key: str = None,
+ ) -> Union[Dict[str, str], Generator[str, None, None]]:
"""
通用的请求封装函数
Args:
endpoint (str): API 的具体端点(例如 '/api/tts')。
|
/home/runner/work/LLSA-Fixed/LLSA-Fixed/AI.py#L73
url = f"{self.api_endpoint}{endpoint}"
if file_key:
files = {file_key: open(data[file_key], "rb")}
res = requests.post(url, headers=headers, files=files).json()
else:
- res = requests.post(url, json=data, headers=headers, stream=data.get("stream", False))
+ res = requests.post(
+ url, json=data, headers=headers, stream=data.get("stream", False)
+ )
if data.get("stream"):
return (line.decode("utf-8") for line in res.iter_lines() if line)
res = res.json()
if download:
|
AI.py#L16
Expected 2 blank lines, found 1 (E302)
|
/home/runner/work/LLSA-Fixed/LLSA-Fixed/AI.py#L91
f.write(chunk)
return res
def stream_chat(self, prompt: str) -> Generator[str, None, None]:
"""流式聊天函数"""
- return self.make_request("/api/chat", data={"prompt": prompt, "token": self.gen_token(prompt), "stream": True})
+ return self.make_request(
+ "/api/chat",
+ data={"prompt": prompt, "token": self.gen_token(prompt), "stream": True},
+ )
def tts(self, text: str, download: bool = False) -> Dict[str, str]:
"""文本转语音函数"""
- return self.make_request("/api/tts", data={"text": text, "token": self.gen_token(text)}, download=download)
+ return self.make_request(
+ "/api/tts",
+ data={"text": text, "token": self.gen_token(text)},
+ download=download,
+ )
def txt2img(self, text: str, download: bool = False) -> Dict[str, str]:
"""文本转图像函数"""
- return self.make_request("/api/txt2img", data={"text": text, "token": self.gen_token(text)}, download=download)
+ return self.make_request(
+ "/api/txt2img",
+ data={"text": text, "token": self.gen_token(text)},
+ download=download,
+ )
def img_desc(self, file_path: str) -> Dict[str, str]:
"""获取图像描述函数"""
- return self.make_request("/api/img_desc", data={"file": file_path}, file_key="file")
+ return self.make_request(
+ "/api/img_desc", data={"file": file_path}, file_key="file"
+ )
@staticmethod
def open_files_dialog() -> List[str]:
"""打开文件选择对话框函数"""
root = tk.Tk()
root.withdraw()
files_paths = filedialog.askopenfilenames()
return list(files_paths)
+
# 创建FastAPI应用实例
app = FastAPI()
+
class ChatRequest(BaseModel):
prompt: str
+
class TTSRequest(BaseModel):
text: str
download: bool = False
+
class TextToImageRequest(BaseModel):
text: str
download: bool = False
+
# 初始化AIApiClient对象
ai_client = AIApiClient()
+
@app.post("/chat")
async def chat(request: ChatRequest) -> StreamingResponse:
return StreamingResponse(ai_client.stream_chat(request.prompt))
+
@app.post("/tts")
async def text_to_speech(request: TTSRequest) -> JSONResponse:
return JSONResponse(ai_client.tts(request.text, request.download))
+
@app.post("/txt2img")
async def text_to_image(request: TextToImageRequest) -> JSONResponse:
return JSONResponse(ai_client.txt2img(request.text, request.download))
+
@app.post("/img_desc")
async def image_description(file: UploadFile = File()) -> JSONResponse:
file_path = file.filename
contents = await file.read()
|
AI.py#L17
F-string is missing placeholders (F541)
|
AI.py#L17
Trailing whitespace (W291)
|
AI.py#L19
Trailing whitespace (W291)
|
AI.py#L20
Trailing whitespace (W291)
|
AI.py#L31
Expected 2 blank lines after class or function definition, found 1 (E305)
|
AI.py#L34
Missing whitespace after ':' (E231)
|
AI.py#L37
Expected 2 blank lines, found 1 (E302)
|
AI.py#L59
Line too long (178 > 79 characters) (E501)
|
AI.py#L71
Line too long (85 > 79 characters) (E501)
|
AI.py#L78
Line too long (98 > 79 characters) (E501)
|
AI.py#L80
Line too long (82 > 79 characters) (E501)
|
AI.py#L87
Line too long (85 > 79 characters) (E501)
|
AI.py#L96
Line too long (119 > 79 characters) (E501)
|
AI.py#L100
Line too long (115 > 79 characters) (E501)
|
AI.py#L104
Line too long (119 > 79 characters) (E501)
|
AI.py#L108
Line too long (92 > 79 characters) (E501)
|
AI.py#L119
Expected 2 blank lines after class or function definition, found 1 (E305)
|
AI.py#L121
Expected 2 blank lines, found 1 (E302)
|
AI.py#L124
Expected 2 blank lines, found 1 (E302)
|
AI.py#L128
Expected 2 blank lines, found 1 (E302)
|
AI.py#L133
Expected 2 blank lines after class or function definition, found 1 (E305)
|
AI.py#L135
Expected 2 blank lines, found 1 (E302)
|
AI.py#L139
Expected 2 blank lines, found 1 (E302)
|
AI.py#L143
Expected 2 blank lines, found 1 (E302)
|
AI.py#L147
Expected 2 blank lines, found 1 (E302)
|
build (3.9)
Process completed with exit code 28.
|
build (3.8)
The job was canceled because "_3_9" failed.
|
build (3.8)
Process completed with exit code 28.
|
build (3.10)
The job was canceled because "_3_9" failed.
|
build (3.10)
The operation was canceled.
|
build (3.9)
The following actions use a deprecated Node.js version and will be forced to run on node20: actions/setup-python@v3. For more info: https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/
|