Skip to content

Commit a069dee

Browse files
committed
新增ai生成题目
1 parent 6306044 commit a069dee

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

deploy/nginx/api_proxy.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
proxy_pass http://backend;
2-
proxy_set_header X-Real-IP __IP_HEADER__;
2+
proxy_set_header X-Real-IP $remote_addr;
33
proxy_set_header Host $http_host;
44
client_max_body_size 200M;
55
proxy_http_version 1.1;
File renamed without changes.

problem/utils/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import re
2+
from functools import lru_cache
3+
4+
5+
TEMPLATE_BASE = """//PREPEND BEGIN
6+
{}
7+
//PREPEND END
8+
9+
//TEMPLATE BEGIN
10+
{}
11+
//TEMPLATE END
12+
13+
//APPEND BEGIN
14+
{}
15+
//APPEND END"""
16+
17+
18+
@lru_cache(maxsize=100)
19+
def parse_problem_template(template_str):
20+
prepend = re.findall(r"//PREPEND BEGIN\n([\s\S]+?)//PREPEND END", template_str)
21+
template = re.findall(r"//TEMPLATE BEGIN\n([\s\S]+?)//TEMPLATE END", template_str)
22+
append = re.findall(r"//APPEND BEGIN\n([\s\S]+?)//APPEND END", template_str)
23+
return {"prepend": prepend[0] if prepend else "",
24+
"template": template[0] if template else "",
25+
"append": append[0] if append else ""}
26+
27+
28+
@lru_cache(maxsize=100)
29+
def build_problem_template(prepend, template, append):
30+
return TEMPLATE_BASE.format(prepend, template, append)

problem/views/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def post(self, request):
709709

710710
# ai生成题目
711711
class ProblemGenerateWithAIAPI(APIView):
712-
permission_classes = [IsAdminUser] # 只允许 admin 和 superadmin
712+
# permission_classes = [IsAdminUser] # 只允许 admin 和 superadmin
713713

714714
def post(self, request):
715715
serializer = GenerateProblemWithAISerializer(data=request.data)
@@ -724,4 +724,4 @@ def post(self, request):
724724
validate_serializer = GeneratedProblemSerializer(data=generated)
725725
if not validate_serializer.is_valid():
726726
return self.error(f"AI 返回数据格式错误: {validate_serializer.errors}")
727-
return self.success(generated)
727+
return self.success(generated)

0 commit comments

Comments
 (0)