|
@@ -1,16 +1,51 @@
|
|
# -*- coding:utf-8 -*-
|
|
# -*- coding:utf-8 -*-
|
|
#
|
|
#
|
|
-import requests
|
|
|
|
-import time
|
|
|
|
import json
|
|
import json
|
|
|
|
+import time
|
|
from functools import wraps
|
|
from functools import wraps
|
|
|
|
+from random import shuffle,sample,randint
|
|
|
|
+from threading import Thread
|
|
|
|
+from concurrent.futures import ThreadPoolExecutor,wait
|
|
|
|
+
|
|
|
|
+import httpx
|
|
|
|
+import requests
|
|
|
|
+from pydantic import BaseModel
|
|
|
|
+from typing import List
|
|
|
|
+
|
|
|
|
|
|
product_adress = "http://111.231.167.191"
|
|
product_adress = "http://111.231.167.191"
|
|
test_address = "http://111.231.167.191:8004"
|
|
test_address = "http://111.231.167.191:8004"
|
|
|
|
+test_address2 = "http://111.231.167.191:8003"
|
|
|
|
+
|
|
local_adress = "http://127.0.0.1:9000"
|
|
local_adress = "http://127.0.0.1:9000"
|
|
|
|
|
|
use_address = local_adress
|
|
use_address = local_adress
|
|
|
|
|
|
|
|
+class DifficultSentence(BaseModel):
|
|
|
|
+ english: str
|
|
|
|
+ chinese: str
|
|
|
|
+
|
|
|
|
+class Candidate(BaseModel):
|
|
|
|
+ label: str
|
|
|
|
+ text: str
|
|
|
|
+ isRight: int
|
|
|
|
+
|
|
|
|
+class Question(BaseModel):
|
|
|
|
+ trunk: str
|
|
|
|
+ analysis: str
|
|
|
|
+ candidates: List[Candidate]
|
|
|
|
+
|
|
|
|
+class Article(BaseModel):
|
|
|
|
+ difficultSentences: List[DifficultSentence]
|
|
|
|
+ usedMeanIds: List[int]
|
|
|
|
+ questions: List[Question]
|
|
|
|
+ englishArticle: str
|
|
|
|
+ chineseArticle: str
|
|
|
|
+ allWordAmount: int
|
|
|
|
+
|
|
|
|
+class ArticleData(BaseModel):
|
|
|
|
+ articles: List[Article]
|
|
|
|
+
|
|
|
|
|
|
def time_use(fn):
|
|
def time_use(fn):
|
|
@wraps(fn)
|
|
@wraps(fn)
|
|
@@ -23,7 +58,7 @@ def time_use(fn):
|
|
print(f'函数:{fn.__name__} 一共用时', cha, '秒')
|
|
print(f'函数:{fn.__name__} 一共用时', cha, '秒')
|
|
return res
|
|
return res
|
|
|
|
|
|
- return cc
|
|
|
|
|
|
+ return cc
|
|
|
|
|
|
|
|
|
|
def test_connect():
|
|
def test_connect():
|
|
@@ -98,47 +133,163 @@ def get_article2():
|
|
@time_use
|
|
@time_use
|
|
def get_article2_1():
|
|
def get_article2_1():
|
|
"""新的获取文章"""
|
|
"""新的获取文章"""
|
|
- json_data = {'core_words': [{'spell': 'sudden', 'meaning': '突然的, 意外的', 'word_id': 1114468, 'meaning_id': 1734},
|
|
|
|
- {'spell': 'frighten', 'meaning': '惊吓, 惊恐', 'word_id': 899278, 'meaning_id': 1735},
|
|
|
|
- {'spell': 'relation', 'meaning': '关系, 联系, 亲戚, 亲属', 'word_id': 1061800, 'meaning_id': 1736},
|
|
|
|
- {'spell': 'Japanese', 'meaning': '日本的', 'word_id': 727384, 'meaning_id': 1737},
|
|
|
|
- {'spell': 'trick', 'meaning': '恶作剧, 戏法, 作假, 欺骗', 'word_id': 1140881, 'meaning_id': 1740},
|
|
|
|
- {'spell': 'yours', 'meaning': '你(们)的东西', 'word_id': 1169496, 'meaning_id': 1741},
|
|
|
|
- {'spell': 'panda', 'meaning': '熊猫', 'word_id': 1015908, 'meaning_id': 1742},
|
|
|
|
- {'spell': 'agreement', 'meaning': '协议,协定', 'word_id': 753401, 'meaning_id': 1743},
|
|
|
|
- {'spell': 'pool', 'meaning': '游泳池, 池子', 'word_id': 1035634, 'meaning_id': 1747},
|
|
|
|
- {'spell': 'risk', 'meaning': '冒险, 风险', 'word_id': 1069002, 'meaning_id': 1748},
|
|
|
|
- {'spell': 'centre', 'meaning': '中心', 'word_id': 806629, 'meaning_id': 1749},
|
|
|
|
- {'spell': 'shut', 'meaning': '关上, 关闭', 'word_id': 1088662, 'meaning_id': 1751},
|
|
|
|
- {'spell': 'piano', 'meaning': '钢琴', 'word_id': 1027211, 'meaning_id': 1752},
|
|
|
|
- {'spell': 'trust', 'meaning': '信任, 信赖', 'word_id': 1142977, 'meaning_id': 1753},
|
|
|
|
- {'spell': 'camera', 'meaning': '照相机', 'word_id': 799656, 'meaning_id': 1754},
|
|
|
|
- {'spell': 'course', 'meaning': '课程', 'word_id': 834016, 'meaning_id': 399},
|
|
|
|
- {'spell': 'carry', 'meaning': '携带', 'word_id': 803106, 'meaning_id': 460},
|
|
|
|
- {'spell': 'sometimes', 'meaning': '有时, 间或', 'word_id': 1097431, 'meaning_id': 495},
|
|
|
|
- {'spell': 'interesting', 'meaning': '有趣的, 令人感兴趣的', 'word_id': 944231, 'meaning_id': 600},
|
|
|
|
- {'spell': 'thought', 'meaning': '思想, 想法', 'word_id': 1130826, 'meaning_id': 685}],
|
|
|
|
- 'extend_words': [{'spell': 'destroy', 'meaning': '破坏, 摧毁', 'word_id': 848592, 'meaning_id': 1288},
|
|
|
|
- {'spell': 'project', 'meaning': '放映, 展现', 'word_id': 1044528, 'meaning_id': 1290},
|
|
|
|
- {'spell': 'waste', 'meaning': '浪费, 荒芜, 废物', 'word_id': 1160701, 'meaning_id': 1292},
|
|
|
|
- {'spell': 'environment', 'meaning': '环境, 外界', 'word_id': 873514, 'meaning_id': 1293},
|
|
|
|
- {'spell': 'memory', 'meaning': '记忆, 记忆力, 回忆', 'word_id': 981104, 'meaning_id': 1294}],
|
|
|
|
- 'take_count': 1, 'student_stage': 3, 'demo_name': '春笋英语',"article_difficulty":800}
|
|
|
|
|
|
+ core_words_list = [{'spell': 'sudden', 'meaning': '突然的, 意外的', 'word_id': 1114468, 'meaning_id': 1734},
|
|
|
|
+ {'spell': 'frighten', 'meaning': '惊吓, 惊恐', 'word_id': 899278, 'meaning_id': 1735},
|
|
|
|
+ {'spell': 'relation', 'meaning': '关系, 联系, 亲戚, 亲属', 'word_id': 1061800, 'meaning_id': 1736},
|
|
|
|
+ {'spell': 'agreement', 'meaning': '协议,协定', 'word_id': 753401, 'meaning_id': 1743},
|
|
|
|
+ {'spell': 'risk', 'meaning': '冒险, 风险', 'word_id': 1069002, 'meaning_id': 1748},
|
|
|
|
+ {'spell': 'centre', 'meaning': '中心', 'word_id': 806629, 'meaning_id': 1749},
|
|
|
|
+ {'spell': 'shut', 'meaning': '关上, 关闭', 'word_id': 1088662, 'meaning_id': 1751},
|
|
|
|
+ {'spell': 'thought', 'meaning': '思想, 想法', 'word_id': 1130826, 'meaning_id': 685},
|
|
|
|
+ {'spell': 'information', 'meaning': '消息, 信息', 'word_id': 940351, 'meaning_id': 487, 'serial': 330},
|
|
|
|
+ {'spell': 'bright', 'meaning': '聪明的', 'word_id': 793695, 'meaning_id': 1451, 'serial': 1048},
|
|
|
|
+ {'spell': 'international', 'meaning': '国际的', 'word_id': 945460, 'meaning_id': 1683, 'serial': 1232},
|
|
|
|
+ {'spell': 'shelf', 'meaning': '架子, 搁板', 'word_id': 1086743, 'meaning_id': 1838, 'serial': 1366},
|
|
|
|
+ {'spell': 'cave', 'meaning': '洞穴, 山洞', 'word_id': 805431, 'meaning_id': 2167, 'serial': 1639},
|
|
|
|
+ {'spell': 'gym', 'meaning': '健身房, 体育馆', 'word_id': 915473, 'meaning_id': 2217, 'serial': 1683},
|
|
|
|
+ {'spell': 'properly', 'meaning': '适当地, 正确地', 'word_id': 1045343, 'meaning_id': 2257, 'serial': 1720},
|
|
|
|
+ {'spell': 'platform', 'meaning': '平台', 'word_id': 1031256, 'meaning_id': 2269, 'serial': 1730},
|
|
|
|
+ {'spell': 'sweep', 'meaning': '打扫, 清扫', 'word_id': 1118098, 'meaning_id': 2321, 'serial': 1775},
|
|
|
|
+ {'spell': 'clinic', 'meaning': '诊所, 门诊部', 'word_id': 815699, 'meaning_id': 2471, 'serial': 1898},
|
|
|
|
+ {'spell': 'sauce', 'meaning': '酱油, 调味料', 'word_id': 1076452, 'meaning_id': 2501, 'serial': 1927},
|
|
|
|
+ {'spell': 'retell', 'meaning': '重讲, 复述', 'word_id': 1065717, 'meaning_id': 2546, 'serial': 1970},
|
|
|
|
+ {'spell': 'specific', 'meaning': '具体的, 明确的', 'word_id': 1099668, 'meaning_id': 3089, 'serial': 2421},
|
|
|
|
+ {'spell': 'religion', 'meaning': '宗教', 'word_id': 1062490, 'meaning_id': 3358, 'serial': 2626},
|
|
|
|
+ {'spell': 'collapse', 'meaning': '倒塌, 崩溃', 'word_id': 819500, 'meaning_id': 3667, 'serial': 2872},
|
|
|
|
+ {'spell': 'bare', 'meaning': '光秃秃的', 'word_id': 777035, 'meaning_id': 4592, 'serial': 3650},
|
|
|
|
+ {'spell': 'defendant', 'meaning': '被告的, 被告人', 'word_id': 1174797, 'meaning_id': 4975, 'serial': 3979},
|
|
|
|
+ {'spell': 'interact', 'meaning': '互相作用, 互动', 'word_id': 943776, 'meaning_id': 5117, 'serial': 4103},
|
|
|
|
+ {'spell': 'fact', 'meaning': '事实, 真相', 'word_id': 882302, 'meaning_id': 425, 'serial': 289},
|
|
|
|
+ {'spell': 'except', 'meaning': '除了…之外', 'word_id': 878228, 'meaning_id': 814, 'serial': 561},
|
|
|
|
+ {'spell': 'opposite', 'meaning': '相反, 对面', 'word_id': 1008508, 'meaning_id': 1650, 'serial': 1207},
|
|
|
|
+ {'spell': 'clerk', 'meaning': '职员, 店员', 'word_id': 815428, 'meaning_id': 1826, 'serial': 1354},
|
|
|
|
+ {'spell': 'chief', 'meaning': '主要的,首要的', 'word_id': 810493, 'meaning_id': 2067, 'serial': 1552},
|
|
|
|
+ {'spell': 'congratulation', 'meaning': '祝贺, 贺辞', 'word_id': 826539, 'meaning_id': 2187, 'serial': 1657},
|
|
|
|
+ {'spell': 'chest', 'meaning': '大箱子', 'word_id': 810293, 'meaning_id': 2223, 'serial': 1689},
|
|
|
|
+ {'spell': 'monitor', 'meaning': '班长', 'word_id': 988984, 'meaning_id': 2262, 'serial': 1724},
|
|
|
|
+ {'spell': 'accurate', 'meaning': '正确的, 精确的', 'word_id': 747138, 'meaning_id': 2278, 'serial': 1739},
|
|
|
|
+ {'spell': 'investigate', 'meaning': '调查, 研究', 'word_id': 947316, 'meaning_id': 2359, 'serial': 1806},
|
|
|
|
+ {'spell': 'forecast', 'meaning': '预报, 预测', 'word_id': 895859, 'meaning_id': 2495, 'serial': 1921},
|
|
|
|
+ {'spell': 'sausage', 'meaning': '香肠, 腊肠', 'word_id': 1076506, 'meaning_id': 2536, 'serial': 1961},
|
|
|
|
+ {'spell': 'insurance', 'meaning': '保险', 'word_id': 943100, 'meaning_id': 3044, 'serial': 2380},
|
|
|
|
+ {'spell': 'reveal', 'meaning': '揭示, 暴露, 展现', 'word_id': 1066342, 'meaning_id': 3246, 'serial': 2544},
|
|
|
|
+ {'spell': 'perception', 'meaning': '观念, 知觉, 觉察', 'word_id': 1174551, 'meaning_id': 3516, 'serial': 2749},
|
|
|
|
+ {'spell': 'violation', 'meaning': '妨碍, 侵犯, 违犯', 'word_id': 1174695, 'meaning_id': 4452, 'serial': 3528},
|
|
|
|
+ {'spell': 'convey', 'meaning': '表达', 'word_id': 830280, 'meaning_id': 4931, 'serial': 3938},
|
|
|
|
+ {'spell': 'migration', 'meaning': '迁移, 移居', 'word_id': 1175117, 'meaning_id': 5069, 'serial': 4063}
|
|
|
|
+ ]
|
|
|
|
+ shuffle(core_words_list)
|
|
|
|
+ core_words_chiose_list = sample(core_words_list,5)
|
|
|
|
+ json_data = {'core_words': core_words_chiose_list,
|
|
|
|
+ 'take_count': 8, 'student_stage': 2, 'demo_name': '春笋英语', "exercise_id": randint(100,999),
|
|
|
|
+ "article_length": 120, "reading_level": 5}
|
|
|
|
|
|
r = requests.post(f"{use_address}/article/reading-comprehension", json=json_data)
|
|
r = requests.post(f"{use_address}/article/reading-comprehension", json=json_data)
|
|
r_json = r.json()
|
|
r_json = r.json()
|
|
|
|
+ print(r_json)
|
|
try:
|
|
try:
|
|
return r_json
|
|
return r_json
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print("春笋文章reading-comprehension错误", e)
|
|
print("春笋文章reading-comprehension错误", e)
|
|
print("错误数据", r_json)
|
|
print("错误数据", r_json)
|
|
|
|
|
|
|
|
+@time_use
|
|
|
|
+def get_article2_2():
|
|
|
|
+ """测试通过requests来直接访问openai"""
|
|
|
|
+ core_words_list = [{'spell': 'sudden', 'meaning': '突然的, 意外的', 'word_id': 1114468, 'meaning_id': 1734},
|
|
|
|
+ {'spell': 'frighten', 'meaning': '惊吓, 惊恐', 'word_id': 899278, 'meaning_id': 1735},
|
|
|
|
+ {'spell': 'relation', 'meaning': '关系, 联系, 亲戚, 亲属', 'word_id': 1061800, 'meaning_id': 1736},
|
|
|
|
+ {'spell': 'agreement', 'meaning': '协议,协定', 'word_id': 753401, 'meaning_id': 1743},
|
|
|
|
+ {'spell': 'risk', 'meaning': '冒险, 风险', 'word_id': 1069002, 'meaning_id': 1748},
|
|
|
|
+ {'spell': 'centre', 'meaning': '中心', 'word_id': 806629, 'meaning_id': 1749},
|
|
|
|
+ {'spell': 'shut', 'meaning': '关上, 关闭', 'word_id': 1088662, 'meaning_id': 1751},
|
|
|
|
+ {'spell': 'thought', 'meaning': '思想, 想法', 'word_id': 1130826, 'meaning_id': 685},
|
|
|
|
+ {'spell': 'information', 'meaning': '消息, 信息', 'word_id': 940351, 'meaning_id': 487, 'serial': 330},
|
|
|
|
+ {'spell': 'bright', 'meaning': '聪明的', 'word_id': 793695, 'meaning_id': 1451, 'serial': 1048},
|
|
|
|
+ {'spell': 'international', 'meaning': '国际的', 'word_id': 945460, 'meaning_id': 1683, 'serial': 1232},
|
|
|
|
+ {'spell': 'shelf', 'meaning': '架子, 搁板', 'word_id': 1086743, 'meaning_id': 1838, 'serial': 1366},
|
|
|
|
+ {'spell': 'cave', 'meaning': '洞穴, 山洞', 'word_id': 805431, 'meaning_id': 2167, 'serial': 1639},
|
|
|
|
+ {'spell': 'gym', 'meaning': '健身房, 体育馆', 'word_id': 915473, 'meaning_id': 2217, 'serial': 1683},
|
|
|
|
+ {'spell': 'properly', 'meaning': '适当地, 正确地', 'word_id': 1045343, 'meaning_id': 2257, 'serial': 1720},
|
|
|
|
+ {'spell': 'platform', 'meaning': '平台', 'word_id': 1031256, 'meaning_id': 2269, 'serial': 1730},
|
|
|
|
+ {'spell': 'sweep', 'meaning': '打扫, 清扫', 'word_id': 1118098, 'meaning_id': 2321, 'serial': 1775},
|
|
|
|
+ {'spell': 'clinic', 'meaning': '诊所, 门诊部', 'word_id': 815699, 'meaning_id': 2471, 'serial': 1898},
|
|
|
|
+ {'spell': 'sauce', 'meaning': '酱油, 调味料', 'word_id': 1076452, 'meaning_id': 2501, 'serial': 1927},
|
|
|
|
+ {'spell': 'retell', 'meaning': '重讲, 复述', 'word_id': 1065717, 'meaning_id': 2546, 'serial': 1970},
|
|
|
|
+ {'spell': 'specific', 'meaning': '具体的, 明确的', 'word_id': 1099668, 'meaning_id': 3089, 'serial': 2421},
|
|
|
|
+ {'spell': 'religion', 'meaning': '宗教', 'word_id': 1062490, 'meaning_id': 3358, 'serial': 2626},
|
|
|
|
+ {'spell': 'collapse', 'meaning': '倒塌, 崩溃', 'word_id': 819500, 'meaning_id': 3667, 'serial': 2872},
|
|
|
|
+ {'spell': 'bare', 'meaning': '光秃秃的', 'word_id': 777035, 'meaning_id': 4592, 'serial': 3650},
|
|
|
|
+ {'spell': 'defendant', 'meaning': '被告的, 被告人', 'word_id': 1174797, 'meaning_id': 4975, 'serial': 3979},
|
|
|
|
+ {'spell': 'interact', 'meaning': '互相作用, 互动', 'word_id': 943776, 'meaning_id': 5117, 'serial': 4103},
|
|
|
|
+ {'spell': 'fact', 'meaning': '事实, 真相', 'word_id': 882302, 'meaning_id': 425, 'serial': 289},
|
|
|
|
+ {'spell': 'except', 'meaning': '除了…之外', 'word_id': 878228, 'meaning_id': 814, 'serial': 561},
|
|
|
|
+ {'spell': 'opposite', 'meaning': '相反, 对面', 'word_id': 1008508, 'meaning_id': 1650, 'serial': 1207},
|
|
|
|
+ {'spell': 'clerk', 'meaning': '职员, 店员', 'word_id': 815428, 'meaning_id': 1826, 'serial': 1354},
|
|
|
|
+ {'spell': 'chief', 'meaning': '主要的,首要的', 'word_id': 810493, 'meaning_id': 2067, 'serial': 1552},
|
|
|
|
+ {'spell': 'congratulation', 'meaning': '祝贺, 贺辞', 'word_id': 826539, 'meaning_id': 2187, 'serial': 1657},
|
|
|
|
+ {'spell': 'chest', 'meaning': '大箱子', 'word_id': 810293, 'meaning_id': 2223, 'serial': 1689},
|
|
|
|
+ {'spell': 'monitor', 'meaning': '班长', 'word_id': 988984, 'meaning_id': 2262, 'serial': 1724},
|
|
|
|
+ {'spell': 'accurate', 'meaning': '正确的, 精确的', 'word_id': 747138, 'meaning_id': 2278, 'serial': 1739},
|
|
|
|
+ {'spell': 'investigate', 'meaning': '调查, 研究', 'word_id': 947316, 'meaning_id': 2359, 'serial': 1806},
|
|
|
|
+ {'spell': 'forecast', 'meaning': '预报, 预测', 'word_id': 895859, 'meaning_id': 2495, 'serial': 1921},
|
|
|
|
+ {'spell': 'sausage', 'meaning': '香肠, 腊肠', 'word_id': 1076506, 'meaning_id': 2536, 'serial': 1961},
|
|
|
|
+ {'spell': 'insurance', 'meaning': '保险', 'word_id': 943100, 'meaning_id': 3044, 'serial': 2380},
|
|
|
|
+ {'spell': 'reveal', 'meaning': '揭示, 暴露, 展现', 'word_id': 1066342, 'meaning_id': 3246, 'serial': 2544},
|
|
|
|
+ {'spell': 'perception', 'meaning': '观念, 知觉, 觉察', 'word_id': 1174551, 'meaning_id': 3516, 'serial': 2749},
|
|
|
|
+ {'spell': 'violation', 'meaning': '妨碍, 侵犯, 违犯', 'word_id': 1174695, 'meaning_id': 4452, 'serial': 3528},
|
|
|
|
+ {'spell': 'convey', 'meaning': '表达', 'word_id': 830280, 'meaning_id': 4931, 'serial': 3938},
|
|
|
|
+ {'spell': 'migration', 'meaning': '迁移, 移居', 'word_id': 1175117, 'meaning_id': 5069, 'serial': 4063}
|
|
|
|
+ ]
|
|
|
|
+ shuffle(core_words_list)
|
|
|
|
+ core_words_chiose_list = sample(core_words_list,5)
|
|
|
|
+ core_words_meaning_str = "; ".join([f"[{i['meaning_id']} {i['spell']} {i['meaning']}]" for i in core_words_chiose_list])
|
|
|
|
+
|
|
|
|
+ question = f"""下面我会为你提供一组数据,[单词组](里面包含词义id,英语单词,中文词义),请根据这些单词的中文词义,生成一篇带中文翻译的考场英语文章,英语文章和中文翻译要有[标题]。注意这个单词有多个词义时,生成的英语文章一定要用提供的中文词义。并挑选一句复杂的句子和其中文翻译,放入difficultSentences。英语文章,放入"englishArticle"中。中文翻译,放入"chineseArticle"中。最终文中使用到的单词id放入"usedMeanIds"中。4个选择题,放入questions字段。questions结构下有4个选择题对象,其中trunk是[英语]问题文本,analysis是[中文]的问题分析,candidates是4个ABCD选项,内部有label是指选项序号A B C D ,text是[英语]选项文本,isRight是否正确答案1是正确0是错误。
|
|
|
|
+
|
|
|
|
+要求:
|
|
|
|
+1.必须用提供的这个词义的单词,其他单词使用最简单最容易没有难度的单词。文章整体非常简洁,通俗易懂,适合初学者,刚入门,单词全是最常见的,语句通顺即可。选择题难度尽可能简单,参考中国小学生水平
|
|
|
|
+2.优先保证文章语句通顺,意思不要太生硬。不要为了使用特定的单词,造成文章语义前后不搭,允许不使用个别词义。
|
|
|
|
+3.文章中使用提供单词,一定要和提供单词的中文词义匹配,尤其是一词多义时,务必使用提供单词的词义。必须要用提供单词的词义。如果用到的词义与提供单词词义不一致,请不要使用这个单词。
|
|
|
|
+4.生成的文章要求120词左右,可以用\\n\\n字符分段,一般1-2个段落左右。第一段是文章标题。
|
|
|
|
+5.允许不使用[单词组]的个别单词,优先保证文章整体意思通顺连贯和故事完整。
|
|
|
|
+6.注意回复字段的中英文,englishArticle是英文,chineseArticle是中文,其中trunk是英文,analysis是中文,text是英文。
|
|
|
|
+
|
|
|
|
+提供[单词组]:{core_words_meaning_str}
|
|
|
|
+"""
|
|
|
|
+
|
|
|
|
+ url = "http://170.106.108.95/v1/chat/completions"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ headers = {
|
|
|
|
+ "Authorization": f"Bearer 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",
|
|
|
|
+ "Content-Type": "application/json"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ data = {
|
|
|
|
+ "model": "gpt-4.1",
|
|
|
|
+ "messages": [
|
|
|
|
+
|
|
|
|
+ {"role": "user", "content": question}
|
|
|
|
+ ],
|
|
|
|
+ "max_tokens": 4000,
|
|
|
|
+ "temperature": 1.2,
|
|
|
|
+ "n":8,
|
|
|
|
+ "response_format": {'type': 'json_schema', 'json_schema': {'name': 'Article', 'schema': {'$defs': {'Candidate': {'properties': {'label': {'title': 'Label', 'type': 'string'}, 'text': {'title': 'Text', 'type': 'string'}, 'isRight': {'title': 'Isright', 'type': 'integer'}}, 'required': ['label', 'text', 'isRight'], 'title': 'Candidate', 'type': 'object'}, 'DifficultSentence': {'properties': {'english': {'title': 'English', 'type': 'string'}, 'chinese': {'title': 'Chinese', 'type': 'string'}}, 'required': ['english', 'chinese'], 'title': 'DifficultSentence', 'type': 'object'}, 'Question': {'properties': {'trunk': {'title': 'Trunk', 'type': 'string'}, 'analysis': {'title': 'Analysis', 'type': 'string'}, 'candidates': {'items': {'$ref': '#/$defs/Candidate'}, 'title': 'Candidates', 'type': 'array'}}, 'required': ['trunk', 'analysis', 'candidates'], 'title': 'Question', 'type': 'object'}}, 'properties': {'difficultSentences': {'items': {'$ref': '#/$defs/DifficultSentence'}, 'title': 'Difficultsentences', 'type': 'array'}, 'usedMeanIds': {'items': {'type': 'integer'}, 'title': 'Usedmeanids', 'type': 'array'}, 'questions': {'items': {'$ref': '#/$defs/Question'}, 'title': 'Questions', 'type': 'array'}, 'englishArticle': {'title': 'Englisharticle', 'type': 'string'}, 'chineseArticle': {'title': 'Chinesearticle', 'type': 'string'}, 'allWordAmount': {'title': 'Allwordamount', 'type': 'integer'}}, 'required': ['difficultSentences', 'usedMeanIds', 'questions', 'englishArticle', 'chineseArticle', 'allWordAmount'], 'title': 'Article', 'type': 'object'}}}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ response = httpx.post(url, headers=headers, json=data,timeout=300)
|
|
|
|
+ print(response.json())
|
|
|
|
+ return response.json()
|
|
|
|
+
|
|
|
|
|
|
def download_word():
|
|
def download_word():
|
|
- from make_docx_demo.data import test_json1
|
|
|
|
|
|
+ from make_docx_demo.data import test_json2
|
|
params = {"document_format": 2, "scanpage_format": 1}
|
|
params = {"document_format": 2, "scanpage_format": 1}
|
|
|
|
|
|
- r = requests.post(f"{use_address}/make_word/vocabulary_assault", params=params, json=test_json1)
|
|
|
|
|
|
+ r = requests.post(f"{use_address}/make_word/vocabulary_assault", params=params, json=test_json2)
|
|
r.raise_for_status()
|
|
r.raise_for_status()
|
|
suffix = {1: "docx", 2: "pdf"}[params['document_format']]
|
|
suffix = {1: "docx", 2: "pdf"}[params['document_format']]
|
|
with open(f"test.{suffix}", "wb") as f:
|
|
with open(f"test.{suffix}", "wb") as f:
|
|
@@ -193,12 +344,31 @@ def run_all_test_cese():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+@time_use
|
|
|
|
+def multi_request():
|
|
|
|
+ with ThreadPoolExecutor(max_workers=50) as executor:
|
|
|
|
+
|
|
|
|
+ futures = [executor.submit(get_article2_1) for _ in range(30)]
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ wait(futures)
|
|
|
|
+ print("完成等待")
|
|
|
|
+ for index,future in enumerate(futures,start=1):
|
|
|
|
+ future.result()
|
|
|
|
+ print(f"完成循环{index}")
|
|
|
|
+
|
|
|
|
+
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
|
|
|
-
|
|
|
|
|
|
+ multi_request()
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
- print(get_article2_1())
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|