Skip to content

Commit

Permalink
Added static check at PR CI (infiniflow#3921)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

Added static check at PR CI

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] Refactoring
  • Loading branch information
yuzhichang authored Dec 8, 2024
1 parent 0d68a6c commit 1254ecf
Show file tree
Hide file tree
Showing 24 changed files with 146 additions and 140 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ jobs:
fetch-depth: 0
fetch-tags: true

# https://github.com/astral-sh/ruff-action
- name: Static check with Ruff
uses: astral-sh/ruff-action@v2
with:
version: ">=0.8.2"

- name: Build ragflow:dev-slim
run: |
RUNNER_WORKSPACE_PREFIX=${RUNNER_WORKSPACE_PREFIX:-$HOME}
Expand Down
30 changes: 15 additions & 15 deletions api/apps/api_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from functools import partial


@manager.route('/new_token', methods=['POST'])
@manager.route('/new_token', methods=['POST']) # noqa: F821
@login_required
def new_token():
req = request.json
Expand Down Expand Up @@ -75,7 +75,7 @@ def new_token():
return server_error_response(e)


@manager.route('/token_list', methods=['GET'])
@manager.route('/token_list', methods=['GET']) # noqa: F821
@login_required
def token_list():
try:
Expand All @@ -90,7 +90,7 @@ def token_list():
return server_error_response(e)


@manager.route('/rm', methods=['POST'])
@manager.route('/rm', methods=['POST']) # noqa: F821
@validate_request("tokens", "tenant_id")
@login_required
def rm():
Expand All @@ -104,7 +104,7 @@ def rm():
return server_error_response(e)


@manager.route('/stats', methods=['GET'])
@manager.route('/stats', methods=['GET']) # noqa: F821
@login_required
def stats():
try:
Expand Down Expand Up @@ -135,7 +135,7 @@ def stats():
return server_error_response(e)


@manager.route('/new_conversation', methods=['GET'])
@manager.route('/new_conversation', methods=['GET']) # noqa: F821
def set_conversation():
token = request.headers.get('Authorization').split()[1]
objs = APIToken.query(token=token)
Expand Down Expand Up @@ -175,7 +175,7 @@ def set_conversation():
return server_error_response(e)


@manager.route('/completion', methods=['POST'])
@manager.route('/completion', methods=['POST']) # noqa: F821
@validate_request("conversation_id", "messages")
def completion():
token = request.headers.get('Authorization').split()[1]
Expand Down Expand Up @@ -341,7 +341,7 @@ def stream():
return server_error_response(e)


@manager.route('/conversation/<conversation_id>', methods=['GET'])
@manager.route('/conversation/<conversation_id>', methods=['GET']) # noqa: F821
# @login_required
def get(conversation_id):
token = request.headers.get('Authorization').split()[1]
Expand Down Expand Up @@ -372,7 +372,7 @@ def get(conversation_id):
return server_error_response(e)


@manager.route('/document/upload', methods=['POST'])
@manager.route('/document/upload', methods=['POST']) # noqa: F821
@validate_request("kb_name")
def upload():
token = request.headers.get('Authorization').split()[1]
Expand Down Expand Up @@ -484,7 +484,7 @@ def upload():
return get_json_result(data=doc_result.to_json())


@manager.route('/document/upload_and_parse', methods=['POST'])
@manager.route('/document/upload_and_parse', methods=['POST']) # noqa: F821
@validate_request("conversation_id")
def upload_parse():
token = request.headers.get('Authorization').split()[1]
Expand All @@ -507,7 +507,7 @@ def upload_parse():
return get_json_result(data=doc_ids)


@manager.route('/list_chunks', methods=['POST'])
@manager.route('/list_chunks', methods=['POST']) # noqa: F821
# @login_required
def list_chunks():
token = request.headers.get('Authorization').split()[1]
Expand Down Expand Up @@ -547,7 +547,7 @@ def list_chunks():
return get_json_result(data=res)


@manager.route('/list_kb_docs', methods=['POST'])
@manager.route('/list_kb_docs', methods=['POST']) # noqa: F821
# @login_required
def list_kb_docs():
token = request.headers.get('Authorization').split()[1]
Expand Down Expand Up @@ -587,7 +587,7 @@ def list_kb_docs():
return server_error_response(e)


@manager.route('/document/infos', methods=['POST'])
@manager.route('/document/infos', methods=['POST']) # noqa: F821
@validate_request("doc_ids")
def docinfos():
token = request.headers.get('Authorization').split()[1]
Expand All @@ -601,7 +601,7 @@ def docinfos():
return get_json_result(data=list(docs.dicts()))


@manager.route('/document', methods=['DELETE'])
@manager.route('/document', methods=['DELETE']) # noqa: F821
# @login_required
def document_rm():
token = request.headers.get('Authorization').split()[1]
Expand Down Expand Up @@ -660,7 +660,7 @@ def document_rm():
return get_json_result(data=True)


@manager.route('/completion_aibotk', methods=['POST'])
@manager.route('/completion_aibotk', methods=['POST']) # noqa: F821
@validate_request("Authorization", "conversation_id", "word")
def completion_faq():
import base64
Expand Down Expand Up @@ -802,7 +802,7 @@ def fillin_conv(ans):
return server_error_response(e)


@manager.route('/retrieval', methods=['POST'])
@manager.route('/retrieval', methods=['POST']) # noqa: F821
@validate_request("kb_id", "question")
def retrieval():
token = request.headers.get('Authorization').split()[1]
Expand Down
16 changes: 8 additions & 8 deletions api/apps/canvas_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
from peewee import MySQLDatabase, PostgresqlDatabase


@manager.route('/templates', methods=['GET'])
@manager.route('/templates', methods=['GET']) # noqa: F821
@login_required
def templates():
return get_json_result(data=[c.to_dict() for c in CanvasTemplateService.get_all()])


@manager.route('/list', methods=['GET'])
@manager.route('/list', methods=['GET']) # noqa: F821
@login_required
def canvas_list():
return get_json_result(data=sorted([c.to_dict() for c in \
UserCanvasService.query(user_id=current_user.id)], key=lambda x: x["update_time"]*-1)
)


@manager.route('/rm', methods=['POST'])
@manager.route('/rm', methods=['POST']) # noqa: F821
@validate_request("canvas_ids")
@login_required
def rm():
Expand All @@ -52,7 +52,7 @@ def rm():
return get_json_result(data=True)


@manager.route('/set', methods=['POST'])
@manager.route('/set', methods=['POST']) # noqa: F821
@validate_request("dsl", "title")
@login_required
def save():
Expand All @@ -77,7 +77,7 @@ def save():
return get_json_result(data=req)


@manager.route('/get/<canvas_id>', methods=['GET'])
@manager.route('/get/<canvas_id>', methods=['GET']) # noqa: F821
@login_required
def get(canvas_id):
e, c = UserCanvasService.get_by_id(canvas_id)
Expand All @@ -86,7 +86,7 @@ def get(canvas_id):
return get_json_result(data=c.to_dict())


@manager.route('/completion', methods=['POST'])
@manager.route('/completion', methods=['POST']) # noqa: F821
@validate_request("id")
@login_required
def run():
Expand Down Expand Up @@ -163,7 +163,7 @@ def sse():
return get_json_result(data={"answer": final_ans["content"], "reference": final_ans.get("reference", [])})


@manager.route('/reset', methods=['POST'])
@manager.route('/reset', methods=['POST']) # noqa: F821
@validate_request("id")
@login_required
def reset():
Expand All @@ -186,7 +186,7 @@ def reset():
return server_error_response(e)


@manager.route('/test_db_connect', methods=['POST'])
@manager.route('/test_db_connect', methods=['POST']) # noqa: F821
@validate_request("db_type", "database", "username", "host", "port", "password")
@login_required
def test_db_connect():
Expand Down
16 changes: 8 additions & 8 deletions api/apps/chunk_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import re


@manager.route('/list', methods=['POST'])
@manager.route('/list', methods=['POST']) # noqa: F821
@login_required
@validate_request("doc_id")
def list_chunk():
Expand Down Expand Up @@ -84,7 +84,7 @@ def list_chunk():
return server_error_response(e)


@manager.route('/get', methods=['GET'])
@manager.route('/get', methods=['GET']) # noqa: F821
@login_required
def get():
chunk_id = request.args["chunk_id"]
Expand Down Expand Up @@ -113,7 +113,7 @@ def get():
return server_error_response(e)


@manager.route('/set', methods=['POST'])
@manager.route('/set', methods=['POST']) # noqa: F821
@login_required
@validate_request("doc_id", "chunk_id", "content_with_weight",
"important_kwd", "question_kwd")
Expand Down Expand Up @@ -164,7 +164,7 @@ def set():
return server_error_response(e)


@manager.route('/switch', methods=['POST'])
@manager.route('/switch', methods=['POST']) # noqa: F821
@login_required
@validate_request("chunk_ids", "available_int", "doc_id")
def switch():
Expand All @@ -184,7 +184,7 @@ def switch():
return server_error_response(e)


@manager.route('/rm', methods=['POST'])
@manager.route('/rm', methods=['POST']) # noqa: F821
@login_required
@validate_request("chunk_ids", "doc_id")
def rm():
Expand All @@ -203,7 +203,7 @@ def rm():
return server_error_response(e)


@manager.route('/create', methods=['POST'])
@manager.route('/create', methods=['POST']) # noqa: F821
@login_required
@validate_request("doc_id", "content_with_weight")
def create():
Expand Down Expand Up @@ -255,7 +255,7 @@ def create():
return server_error_response(e)


@manager.route('/retrieval_test', methods=['POST'])
@manager.route('/retrieval_test', methods=['POST']) # noqa: F821
@login_required
@validate_request("kb_id", "question")
def retrieval_test():
Expand Down Expand Up @@ -314,7 +314,7 @@ def retrieval_test():
return server_error_response(e)


@manager.route('/knowledge_graph', methods=['GET'])
@manager.route('/knowledge_graph', methods=['GET']) # noqa: F821
@login_required
def knowledge_graph():
doc_id = request.args["doc_id"]
Expand Down
22 changes: 11 additions & 11 deletions api/apps/conversation_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from graphrag.mind_map_extractor import MindMapExtractor


@manager.route('/set', methods=['POST'])
@manager.route('/set', methods=['POST']) # noqa: F821
@login_required
def set_conversation():
req = request.json
Expand Down Expand Up @@ -72,7 +72,7 @@ def set_conversation():
return server_error_response(e)


@manager.route('/get', methods=['GET'])
@manager.route('/get', methods=['GET']) # noqa: F821
@login_required
def get():
conv_id = request.args["conversation_id"]
Expand All @@ -94,7 +94,7 @@ def get():
return server_error_response(e)


@manager.route('/rm', methods=['POST'])
@manager.route('/rm', methods=['POST']) # noqa: F821
@login_required
def rm():
conv_ids = request.json["conversation_ids"]
Expand All @@ -117,7 +117,7 @@ def rm():
return server_error_response(e)


@manager.route('/list', methods=['GET'])
@manager.route('/list', methods=['GET']) # noqa: F821
@login_required
def list_convsersation():
dialog_id = request.args["dialog_id"]
Expand All @@ -136,7 +136,7 @@ def list_convsersation():
return server_error_response(e)


@manager.route('/completion', methods=['POST'])
@manager.route('/completion', methods=['POST']) # noqa: F821
@login_required
@validate_request("conversation_id", "messages")
def completion():
Expand Down Expand Up @@ -209,7 +209,7 @@ def stream():
return server_error_response(e)


@manager.route('/tts', methods=['POST'])
@manager.route('/tts', methods=['POST']) # noqa: F821
@login_required
def tts():
req = request.json
Expand Down Expand Up @@ -243,7 +243,7 @@ def stream_audio():
return resp


@manager.route('/delete_msg', methods=['POST'])
@manager.route('/delete_msg', methods=['POST']) # noqa: F821
@login_required
@validate_request("conversation_id", "message_id")
def delete_msg():
Expand All @@ -266,7 +266,7 @@ def delete_msg():
return get_json_result(data=conv)


@manager.route('/thumbup', methods=['POST'])
@manager.route('/thumbup', methods=['POST']) # noqa: F821
@login_required
@validate_request("conversation_id", "message_id")
def thumbup():
Expand All @@ -293,7 +293,7 @@ def thumbup():
return get_json_result(data=conv)


@manager.route('/ask', methods=['POST'])
@manager.route('/ask', methods=['POST']) # noqa: F821
@login_required
@validate_request("question", "kb_ids")
def ask_about():
Expand All @@ -319,7 +319,7 @@ def stream():
return resp


@manager.route('/mindmap', methods=['POST'])
@manager.route('/mindmap', methods=['POST']) # noqa: F821
@login_required
@validate_request("question", "kb_ids")
def mindmap():
Expand All @@ -341,7 +341,7 @@ def mindmap():
return get_json_result(data=mind_map)


@manager.route('/related_questions', methods=['POST'])
@manager.route('/related_questions', methods=['POST']) # noqa: F821
@login_required
@validate_request("question")
def related_questions():
Expand Down
Loading

0 comments on commit 1254ecf

Please sign in to comment.