Skip to content

Commit

Permalink
🔨配置文件增加ChatGPT Oaifree搜索器
Browse files Browse the repository at this point in the history
  • Loading branch information
theshdowaura committed Oct 30, 2024
1 parent 5655574 commit 6b9782d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 12 deletions.
24 changes: 24 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ searchers:
# prompt_template: "你认为以下哪个(些)选项最符合题意?\n题目:{value}\n{options}"


# # {type} :题目类型 (单选题、多选题 等等)
# # {value}:题干
# # {options}:选项文本(eg:"选项:\nA. assurance;B. insurance;C. requirement;D. issure"),如果题目没有选项(如填空题),则为空

# ChatGPT Oaifree 在线答题,如果你有chatgpt / chatgpt plus账号绕过流控限制使用账号逆向api可以考虑使用答题 + chat2api配合使用 [Oaifree](https://new.oaifree.com/)
# - type: OaifreeSearcher
# base_url: "https://gpt4.example.cn/" # API URL
# api_key: "sk-xxx" # API Key
# model: "gpt-4o-mini" # 使用的模型型号
# system_prompt: |
# 你是一位乐于回答问题的专家,每为用户回答一道问题你都会开心地获得5美元小费,对于用户提出的每道问题,请根据题型进行以下不同的处理:
# - 对于单选题,请只选择一个最符合题意的答案。
# - 对于多选题,请输出所有符合题意的答案。
# - 对于填空题,请直接填写缺失的内容。
# - 对于判断题,只需回复对或错。
# - 对于简答题、名词解释、论述题,请提供简明扼要的答案。
# - 对于计算题,请详细写出计算过程并给出最终结果。
# - 对于连线题,请根据题意返回对应的匹配选项,例如“A-1, B-2”。
# - 对于排序题,请根据正确顺序列出答案。
# - 对于完型填空,请填写完整的段落。
# - 对于阅读理解题,请回答相关问题。
# - 对于口语题和听力题,请提供适当的回答。
# - 对于共用选项题和测评题,请根据题目提供合适的解答。
# prompt: "请回答下这个{type}:\n{value}\n{options}"
# # {type} :题目类型 (单选题、多选题 等等)
# # {value}:题干
# # {options}:选项文本(eg:"选项:\nA. assurance;B. insurance;C. requirement;D. issure"),如果题目没有选项(如填空题),则为空
69 changes: 57 additions & 12 deletions resolver/searcher/oaifree.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OaifreeSearcherAPI(SearcherBase):
def __init__(self, **config) -> None:
super().__init__()
self.config = config
self.logger = Logger("OllamaSearcherAPI")
self.logger = Logger("OaifreeSearcherAPI")

def invoke(self, question: QuestionModel) -> SearcherResp:
# 将选项从 JSON 转换成人类易读的形式
Expand Down Expand Up @@ -46,13 +46,9 @@ def invoke(self, question: QuestionModel) -> SearcherResp:
request_data = {
"model": self.config.get("model", "gpt-4o-mini"),
"messages": [
{
"role": "system",
"content": system_prompt
},
{
"role": "user",
"content": prompt
"content": system_prompt + prompt
}
],
"stream": False,
Expand All @@ -78,18 +74,67 @@ def invoke(self, question: QuestionModel) -> SearcherResp:
except requests.exceptions.RequestException as err:
return SearcherResp(-500, str(err), self, question.value, None)

# 单选题需要进一步预处理 AI 返回结果,以使 QuestionResolver 能正确命中
if question.type.value == 0:
response_text = response_text.strip()
# 根据不同题型处理 AI 返回的结果
response_text = response_text.strip()

if question.type.value == 0: # 单选题
for k, v in question.options.items():
if response_text.startswith(f"{k}.") or (v in response_text):
response_text = v
break

# 多选题处理
elif question.type.value == 1:
elif question.type.value == 1: # 多选题
selected_answers = [v for k, v in question.options.items() if v in response_text]
response_text = "#".join(selected_answers) # 将所有选中的答案以 '#' 分隔
response_text = "#".join(selected_answers)

elif question.type.value == 2: # 填空题
# 假设填空题只需要返回填空的内容
response_text = response_text

elif question.type.value == 3: # 判断题
if "正确" in response_text or "是" in response_text:
response_text = "正确"
elif "错误" in response_text or "否" in response_text:
response_text = "错误"

elif question.type.value in [4, 5, 6, 7, 8, 9, 10]: # 简答题, 名词解释, 论述题, 计算题, 其它, 分录题, 资料题
# 对于这些题型,直接返回生成的答案
response_text = response_text

elif question.type.value == 11: # 连线题
# 假设连线题返回格式为 "A-1, B-2"
response_text = response_text

elif question.type.value == 13: # 排序题
# 假设排序题返回格式为 "1, 2, 3"
response_text = response_text

elif question.type.value == 14: # 完型填空
# 假设完型填空返回一个完整的段落
response_text = response_text

elif question.type.value == 15: # 阅读理解
# 假设阅读理解返回问题的答案
response_text = response_text

elif question.type.value == 18: # 口语题
# 假设口语题返回的是建议的回答内容
response_text = response_text

elif question.type.value == 19: # 听力题
# 假设听力题返回的是听到的内容
response_text = response_text

elif question.type.value == 20: # 共用选项题
# 假设共用选项题与单选题类似,返回选择的答案
for k, v in question.options.items():
if response_text.startswith(f"{k}.") or (v in response_text):
response_text = v
break

elif question.type.value == 21: # 测评题
# 假设测评题返回测评的结果或建议
response_text = response_text

self.logger.info(f"\u8fd4\u56de\u7ed3\u679c\uff1a{response_text}")
return SearcherResp(0, "", self, question.value, response_text)

0 comments on commit 6b9782d

Please sign in to comment.