mock_request.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. # -*- coding:utf-8 -*-
  2. #
  3. import json
  4. import time
  5. from functools import wraps
  6. from random import shuffle,sample,randint
  7. from threading import Thread
  8. from concurrent.futures import ThreadPoolExecutor,wait
  9. import httpx
  10. import requests
  11. from pydantic import BaseModel
  12. from typing import List
  13. product_adress = "http://111.231.167.191"
  14. test_address = "http://111.231.167.191:8004"
  15. test_address2 = "http://111.231.167.191:8003"
  16. local_adress = "http://127.0.0.1:9000"
  17. use_address = local_adress
  18. class DifficultSentence(BaseModel):
  19. english: str
  20. chinese: str
  21. class Candidate(BaseModel):
  22. label: str
  23. text: str
  24. isRight: int
  25. class Question(BaseModel):
  26. trunk: str
  27. analysis: str
  28. candidates: List[Candidate]
  29. class Article(BaseModel):
  30. difficultSentences: List[DifficultSentence]
  31. usedMeanIds: List[int]
  32. questions: List[Question]
  33. englishArticle: str
  34. chineseArticle: str
  35. allWordAmount: int
  36. class ArticleData(BaseModel):
  37. articles: List[Article]
  38. def time_use(fn):
  39. @wraps(fn)
  40. def cc(*args, **kwargs):
  41. f_time = time.time()
  42. res = fn(*args, **kwargs)
  43. cha = round(time.time() - f_time, 3)
  44. if cha > 0.1:
  45. print(f'函数:{fn.__name__} 一共用时', cha, '秒')
  46. return res
  47. return cc
  48. def test_connect():
  49. """连接测试"""
  50. try:
  51. r = requests.post(use_address)
  52. assert r.text == 'hello world'
  53. r = requests.get(use_address)
  54. assert r.text == 'hello world'
  55. print("测试连接成功")
  56. except AssertionError:
  57. print("测试连接失败")
  58. def get_article():
  59. """同时检验article接口和query_oss_file接口"""
  60. json_data = {"meaning_ids": [300751, 300756, 300757, 300758, 300454, 302096, 302102], "callback_url": "http://localhost/callback",
  61. "student_stage": 1, "vocabulary": 700, "class_id": 123456}
  62. r = requests.post(f"{use_address}/article", json=json_data)
  63. key = r.json()['key']
  64. time.sleep(120)
  65. query_file_content(key)
  66. def query_file_content(key):
  67. json_data = {"key": key}
  68. try:
  69. r = requests.post(f"{use_address}/query_oss_file", json=json_data)
  70. r.raise_for_status()
  71. response_data = r.json()
  72. assert response_data['wordCount'] > 0, "词数为0"
  73. except requests.RequestException as e:
  74. print(f"请求失败: {e}")
  75. except json.JSONDecodeError as e:
  76. print(f"JSON解析错误: {e}")
  77. except AssertionError as e:
  78. print(f"断言错误: {e}")
  79. except Exception as e:
  80. print(f"未知错误: {e}")
  81. def get_audio():
  82. word = "cat"
  83. r1 = requests.post(f"{use_address}/tts", json={"text": word, "type": 0})
  84. r2 = requests.post(f"{use_address}/tts", json={"text": word, "type": 2})
  85. r3 = requests.post(f"{use_address}/tts", json={"text": word, "type": 1})
  86. assert r1.json()['code'] == 200
  87. assert r2.json()['code'] == 200
  88. assert r3.status_code == 200
  89. @time_use
  90. def get_article2():
  91. json_data = {"words": [
  92. {'spell': 'term', 'meaning': '学期'}, {'spell': 'ordinary', 'meaning': '平常的, 普通的, 一般的'},
  93. {'spell': 'discussion', 'meaning': '讨论, 谈论'}, {'spell': 'shine', 'meaning': '照耀, 发光, 闪耀'},
  94. {'spell': 'million', 'meaning': '百万'}, {'spell': 'greet', 'meaning': '问候'}
  95. ], "take_count": 1, "student_stage": 3, "demo_name": "测试项目"}
  96. r = requests.post(f"{use_address}/article/reading-comprehension", json=json_data)
  97. r_json = r.json()
  98. try:
  99. assert len(r_json['articles']) == 1
  100. return r_json
  101. except Exception as e:
  102. print("春笋文章reading-comprehension错误", e)
  103. print("错误数据", r_json)
  104. @time_use
  105. def get_article2_1():
  106. """新的获取文章"""
  107. core_words_list = [{'spell': 'sudden', 'meaning': '突然的, 意外的', 'word_id': 1114468, 'meaning_id': 1734},
  108. {'spell': 'frighten', 'meaning': '惊吓, 惊恐', 'word_id': 899278, 'meaning_id': 1735},
  109. {'spell': 'relation', 'meaning': '关系, 联系, 亲戚, 亲属', 'word_id': 1061800, 'meaning_id': 1736},
  110. {'spell': 'agreement', 'meaning': '协议,协定', 'word_id': 753401, 'meaning_id': 1743},
  111. {'spell': 'risk', 'meaning': '冒险, 风险', 'word_id': 1069002, 'meaning_id': 1748},
  112. {'spell': 'centre', 'meaning': '中心', 'word_id': 806629, 'meaning_id': 1749},
  113. {'spell': 'shut', 'meaning': '关上, 关闭', 'word_id': 1088662, 'meaning_id': 1751},
  114. {'spell': 'thought', 'meaning': '思想, 想法', 'word_id': 1130826, 'meaning_id': 685},
  115. {'spell': 'information', 'meaning': '消息, 信息', 'word_id': 940351, 'meaning_id': 487, 'serial': 330},
  116. {'spell': 'bright', 'meaning': '聪明的', 'word_id': 793695, 'meaning_id': 1451, 'serial': 1048},
  117. {'spell': 'international', 'meaning': '国际的', 'word_id': 945460, 'meaning_id': 1683, 'serial': 1232},
  118. {'spell': 'shelf', 'meaning': '架子, 搁板', 'word_id': 1086743, 'meaning_id': 1838, 'serial': 1366},
  119. {'spell': 'cave', 'meaning': '洞穴, 山洞', 'word_id': 805431, 'meaning_id': 2167, 'serial': 1639},
  120. {'spell': 'gym', 'meaning': '健身房, 体育馆', 'word_id': 915473, 'meaning_id': 2217, 'serial': 1683},
  121. {'spell': 'properly', 'meaning': '适当地, 正确地', 'word_id': 1045343, 'meaning_id': 2257, 'serial': 1720},
  122. {'spell': 'platform', 'meaning': '平台', 'word_id': 1031256, 'meaning_id': 2269, 'serial': 1730},
  123. {'spell': 'sweep', 'meaning': '打扫, 清扫', 'word_id': 1118098, 'meaning_id': 2321, 'serial': 1775},
  124. {'spell': 'clinic', 'meaning': '诊所, 门诊部', 'word_id': 815699, 'meaning_id': 2471, 'serial': 1898},
  125. {'spell': 'sauce', 'meaning': '酱油, 调味料', 'word_id': 1076452, 'meaning_id': 2501, 'serial': 1927},
  126. {'spell': 'retell', 'meaning': '重讲, 复述', 'word_id': 1065717, 'meaning_id': 2546, 'serial': 1970},
  127. {'spell': 'specific', 'meaning': '具体的, 明确的', 'word_id': 1099668, 'meaning_id': 3089, 'serial': 2421},
  128. {'spell': 'religion', 'meaning': '宗教', 'word_id': 1062490, 'meaning_id': 3358, 'serial': 2626},
  129. {'spell': 'collapse', 'meaning': '倒塌, 崩溃', 'word_id': 819500, 'meaning_id': 3667, 'serial': 2872},
  130. {'spell': 'bare', 'meaning': '光秃秃的', 'word_id': 777035, 'meaning_id': 4592, 'serial': 3650},
  131. {'spell': 'defendant', 'meaning': '被告的, 被告人', 'word_id': 1174797, 'meaning_id': 4975, 'serial': 3979},
  132. {'spell': 'interact', 'meaning': '互相作用, 互动', 'word_id': 943776, 'meaning_id': 5117, 'serial': 4103},
  133. {'spell': 'fact', 'meaning': '事实, 真相', 'word_id': 882302, 'meaning_id': 425, 'serial': 289},
  134. {'spell': 'except', 'meaning': '除了…之外', 'word_id': 878228, 'meaning_id': 814, 'serial': 561},
  135. {'spell': 'opposite', 'meaning': '相反, 对面', 'word_id': 1008508, 'meaning_id': 1650, 'serial': 1207},
  136. {'spell': 'clerk', 'meaning': '职员, 店员', 'word_id': 815428, 'meaning_id': 1826, 'serial': 1354},
  137. {'spell': 'chief', 'meaning': '主要的,首要的', 'word_id': 810493, 'meaning_id': 2067, 'serial': 1552},
  138. {'spell': 'congratulation', 'meaning': '祝贺, 贺辞', 'word_id': 826539, 'meaning_id': 2187, 'serial': 1657},
  139. {'spell': 'chest', 'meaning': '大箱子', 'word_id': 810293, 'meaning_id': 2223, 'serial': 1689},
  140. {'spell': 'monitor', 'meaning': '班长', 'word_id': 988984, 'meaning_id': 2262, 'serial': 1724},
  141. {'spell': 'accurate', 'meaning': '正确的, 精确的', 'word_id': 747138, 'meaning_id': 2278, 'serial': 1739},
  142. {'spell': 'investigate', 'meaning': '调查, 研究', 'word_id': 947316, 'meaning_id': 2359, 'serial': 1806},
  143. {'spell': 'forecast', 'meaning': '预报, 预测', 'word_id': 895859, 'meaning_id': 2495, 'serial': 1921},
  144. {'spell': 'sausage', 'meaning': '香肠, 腊肠', 'word_id': 1076506, 'meaning_id': 2536, 'serial': 1961},
  145. {'spell': 'insurance', 'meaning': '保险', 'word_id': 943100, 'meaning_id': 3044, 'serial': 2380},
  146. {'spell': 'reveal', 'meaning': '揭示, 暴露, 展现', 'word_id': 1066342, 'meaning_id': 3246, 'serial': 2544},
  147. {'spell': 'perception', 'meaning': '观念, 知觉, 觉察', 'word_id': 1174551, 'meaning_id': 3516, 'serial': 2749},
  148. {'spell': 'violation', 'meaning': '妨碍, 侵犯, 违犯', 'word_id': 1174695, 'meaning_id': 4452, 'serial': 3528},
  149. {'spell': 'convey', 'meaning': '表达', 'word_id': 830280, 'meaning_id': 4931, 'serial': 3938},
  150. {'spell': 'migration', 'meaning': '迁移, 移居', 'word_id': 1175117, 'meaning_id': 5069, 'serial': 4063}
  151. ]
  152. shuffle(core_words_list)
  153. core_words_chiose_list = sample(core_words_list,5)
  154. json_data = {'core_words': core_words_chiose_list,
  155. 'take_count': 8, 'student_stage': 2, 'demo_name': '春笋英语', "exercise_id": randint(100,999),
  156. "article_length": 120, "reading_level": 5}
  157. r = requests.post(f"{use_address}/article/reading-comprehension", json=json_data)
  158. r_json = r.json()
  159. print(r_json)
  160. try:
  161. return r_json
  162. except Exception as e:
  163. print("春笋文章reading-comprehension错误", e)
  164. print("错误数据", r_json)
  165. @time_use
  166. def get_article2_2():
  167. """测试通过requests来直接访问openai"""
  168. core_words_list = [{'spell': 'sudden', 'meaning': '突然的, 意外的', 'word_id': 1114468, 'meaning_id': 1734},
  169. {'spell': 'frighten', 'meaning': '惊吓, 惊恐', 'word_id': 899278, 'meaning_id': 1735},
  170. {'spell': 'relation', 'meaning': '关系, 联系, 亲戚, 亲属', 'word_id': 1061800, 'meaning_id': 1736},
  171. {'spell': 'agreement', 'meaning': '协议,协定', 'word_id': 753401, 'meaning_id': 1743},
  172. {'spell': 'risk', 'meaning': '冒险, 风险', 'word_id': 1069002, 'meaning_id': 1748},
  173. {'spell': 'centre', 'meaning': '中心', 'word_id': 806629, 'meaning_id': 1749},
  174. {'spell': 'shut', 'meaning': '关上, 关闭', 'word_id': 1088662, 'meaning_id': 1751},
  175. {'spell': 'thought', 'meaning': '思想, 想法', 'word_id': 1130826, 'meaning_id': 685},
  176. {'spell': 'information', 'meaning': '消息, 信息', 'word_id': 940351, 'meaning_id': 487, 'serial': 330},
  177. {'spell': 'bright', 'meaning': '聪明的', 'word_id': 793695, 'meaning_id': 1451, 'serial': 1048},
  178. {'spell': 'international', 'meaning': '国际的', 'word_id': 945460, 'meaning_id': 1683, 'serial': 1232},
  179. {'spell': 'shelf', 'meaning': '架子, 搁板', 'word_id': 1086743, 'meaning_id': 1838, 'serial': 1366},
  180. {'spell': 'cave', 'meaning': '洞穴, 山洞', 'word_id': 805431, 'meaning_id': 2167, 'serial': 1639},
  181. {'spell': 'gym', 'meaning': '健身房, 体育馆', 'word_id': 915473, 'meaning_id': 2217, 'serial': 1683},
  182. {'spell': 'properly', 'meaning': '适当地, 正确地', 'word_id': 1045343, 'meaning_id': 2257, 'serial': 1720},
  183. {'spell': 'platform', 'meaning': '平台', 'word_id': 1031256, 'meaning_id': 2269, 'serial': 1730},
  184. {'spell': 'sweep', 'meaning': '打扫, 清扫', 'word_id': 1118098, 'meaning_id': 2321, 'serial': 1775},
  185. {'spell': 'clinic', 'meaning': '诊所, 门诊部', 'word_id': 815699, 'meaning_id': 2471, 'serial': 1898},
  186. {'spell': 'sauce', 'meaning': '酱油, 调味料', 'word_id': 1076452, 'meaning_id': 2501, 'serial': 1927},
  187. {'spell': 'retell', 'meaning': '重讲, 复述', 'word_id': 1065717, 'meaning_id': 2546, 'serial': 1970},
  188. {'spell': 'specific', 'meaning': '具体的, 明确的', 'word_id': 1099668, 'meaning_id': 3089, 'serial': 2421},
  189. {'spell': 'religion', 'meaning': '宗教', 'word_id': 1062490, 'meaning_id': 3358, 'serial': 2626},
  190. {'spell': 'collapse', 'meaning': '倒塌, 崩溃', 'word_id': 819500, 'meaning_id': 3667, 'serial': 2872},
  191. {'spell': 'bare', 'meaning': '光秃秃的', 'word_id': 777035, 'meaning_id': 4592, 'serial': 3650},
  192. {'spell': 'defendant', 'meaning': '被告的, 被告人', 'word_id': 1174797, 'meaning_id': 4975, 'serial': 3979},
  193. {'spell': 'interact', 'meaning': '互相作用, 互动', 'word_id': 943776, 'meaning_id': 5117, 'serial': 4103},
  194. {'spell': 'fact', 'meaning': '事实, 真相', 'word_id': 882302, 'meaning_id': 425, 'serial': 289},
  195. {'spell': 'except', 'meaning': '除了…之外', 'word_id': 878228, 'meaning_id': 814, 'serial': 561},
  196. {'spell': 'opposite', 'meaning': '相反, 对面', 'word_id': 1008508, 'meaning_id': 1650, 'serial': 1207},
  197. {'spell': 'clerk', 'meaning': '职员, 店员', 'word_id': 815428, 'meaning_id': 1826, 'serial': 1354},
  198. {'spell': 'chief', 'meaning': '主要的,首要的', 'word_id': 810493, 'meaning_id': 2067, 'serial': 1552},
  199. {'spell': 'congratulation', 'meaning': '祝贺, 贺辞', 'word_id': 826539, 'meaning_id': 2187, 'serial': 1657},
  200. {'spell': 'chest', 'meaning': '大箱子', 'word_id': 810293, 'meaning_id': 2223, 'serial': 1689},
  201. {'spell': 'monitor', 'meaning': '班长', 'word_id': 988984, 'meaning_id': 2262, 'serial': 1724},
  202. {'spell': 'accurate', 'meaning': '正确的, 精确的', 'word_id': 747138, 'meaning_id': 2278, 'serial': 1739},
  203. {'spell': 'investigate', 'meaning': '调查, 研究', 'word_id': 947316, 'meaning_id': 2359, 'serial': 1806},
  204. {'spell': 'forecast', 'meaning': '预报, 预测', 'word_id': 895859, 'meaning_id': 2495, 'serial': 1921},
  205. {'spell': 'sausage', 'meaning': '香肠, 腊肠', 'word_id': 1076506, 'meaning_id': 2536, 'serial': 1961},
  206. {'spell': 'insurance', 'meaning': '保险', 'word_id': 943100, 'meaning_id': 3044, 'serial': 2380},
  207. {'spell': 'reveal', 'meaning': '揭示, 暴露, 展现', 'word_id': 1066342, 'meaning_id': 3246, 'serial': 2544},
  208. {'spell': 'perception', 'meaning': '观念, 知觉, 觉察', 'word_id': 1174551, 'meaning_id': 3516, 'serial': 2749},
  209. {'spell': 'violation', 'meaning': '妨碍, 侵犯, 违犯', 'word_id': 1174695, 'meaning_id': 4452, 'serial': 3528},
  210. {'spell': 'convey', 'meaning': '表达', 'word_id': 830280, 'meaning_id': 4931, 'serial': 3938},
  211. {'spell': 'migration', 'meaning': '迁移, 移居', 'word_id': 1175117, 'meaning_id': 5069, 'serial': 4063}
  212. ]
  213. shuffle(core_words_list)
  214. core_words_chiose_list = sample(core_words_list,5)
  215. core_words_meaning_str = "; ".join([f"[{i['meaning_id']} {i['spell']} {i['meaning']}]" for i in core_words_chiose_list])
  216. 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是错误。
  217. 要求:
  218. 1.必须用提供的这个词义的单词,其他单词使用最简单最容易没有难度的单词。文章整体非常简洁,通俗易懂,适合初学者,刚入门,单词全是最常见的,语句通顺即可。选择题难度尽可能简单,参考中国小学生水平
  219. 2.优先保证文章语句通顺,意思不要太生硬。不要为了使用特定的单词,造成文章语义前后不搭,允许不使用个别词义。
  220. 3.文章中使用提供单词,一定要和提供单词的中文词义匹配,尤其是一词多义时,务必使用提供单词的词义。必须要用提供单词的词义。如果用到的词义与提供单词词义不一致,请不要使用这个单词。
  221. 4.生成的文章要求120词左右,可以用\\n\\n字符分段,一般1-2个段落左右。第一段是文章标题。
  222. 5.允许不使用[单词组]的个别单词,优先保证文章整体意思通顺连贯和故事完整。
  223. 6.注意回复字段的中英文,englishArticle是英文,chineseArticle是中文,其中trunk是英文,analysis是中文,text是英文。
  224. 提供[单词组]:{core_words_meaning_str}
  225. """
  226. url = "http://170.106.108.95/v1/chat/completions"
  227. headers = {
  228. "Authorization": f"Bearer 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",
  229. "Content-Type": "application/json"
  230. }
  231. data = {
  232. "model": "gpt-4.1",
  233. "messages": [
  234. {"role": "user", "content": question}
  235. ],
  236. "max_tokens": 4000,
  237. "temperature": 1.2,
  238. "n":8,
  239. "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'}}}
  240. }
  241. response = httpx.post(url, headers=headers, json=data,timeout=300)
  242. print(response.json())
  243. return response.json()
  244. def download_word():
  245. from make_docx_demo.data import test_json2
  246. params = {"document_format": 2, "scanpage_format": 1}
  247. r = requests.post(f"{use_address}/make_word/vocabulary_assault", params=params, json=test_json2)
  248. r.raise_for_status()
  249. suffix = {1: "docx", 2: "pdf"}[params['document_format']]
  250. with open(f"test.{suffix}", "wb") as f:
  251. f.write(r.content)
  252. def spoken_language():
  253. url = f"{use_address}/spoken_language"
  254. with open(r"1.mp3", "rb") as f:
  255. audio_data = {'file': ('file.bin', f, 'application/octet-stream')}
  256. data = {"text": "You must study to be frank with the world"}
  257. r1 = requests.post(url, data=data, files=audio_data)
  258. assert r1.json()['code'] == 0
  259. data = {"text": "apple Life is like a box of chocolates, you never know what you're gonna",
  260. "url": "https://yunzhixue.blob.core.chinacloudapi.cn/download/ttsmaker-file-2025-1-13-10-47-47.mp3"}
  261. r2 = requests.post(url, data=data)
  262. assert r2.json()['code'] == 0
  263. @time_use
  264. def get_article3():
  265. json_data = {"words": [
  266. {'spell': 'term', 'meaning': '学期'}, {'spell': 'ordinary', 'meaning': '平常的, 普通的, 一般的'},
  267. {'spell': 'discussion', 'meaning': '讨论, 谈论'}, {'spell': 'shine', 'meaning': '照耀, 发光, 闪耀'},
  268. {'spell': 'million', 'meaning': '百万'}, {'spell': 'greet', 'meaning': '问候'}
  269. ], "take_count": 1, "student_stage": 3, "demo_name": "测试项目"}
  270. r = requests.post(f"{use_address}/article/reading-comprehension/deepseek", json=json_data)
  271. r_json = r.json()
  272. try:
  273. assert r_json['articles'][0]["english"]
  274. assert r_json['articles'][0]["difficultSentences"]
  275. assert r_json['articles'][0]["questions"]
  276. assert r_json['articles'][0]["allWordAmount"] > 10
  277. return r_json
  278. except Exception as e:
  279. print("deepseek生成文章出错", e)
  280. print(r_json)
  281. @time_use
  282. def run_all_test_cese():
  283. test_connect()
  284. get_audio()
  285. spoken_language()
  286. download_word()
  287. print(get_article2_1())
  288. @time_use
  289. def multi_request():
  290. with ThreadPoolExecutor(max_workers=50) as executor:
  291. futures = [executor.submit(get_article2_1) for _ in range(30)]
  292. wait(futures)
  293. print("完成等待")
  294. for index,future in enumerate(futures,start=1):
  295. future.result()
  296. print(f"完成循环{index}")
  297. if __name__ == '__main__':
  298. multi_request()