Files

1 line
11 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "bg2mkj/runara", "files": {"chat.py": {"ab4e11d2694595b02cafa82acb9988f650a7ab89": {"t": 1785745977.7261467, "n": 2268, "h": "4bd90d223c00a779", "c": "from openai import OpenAI\nimport requests\nfrom multiprocessing import Queue\nimport json\n\nclass Chat_Api:\n api_key = ''\n client = OpenAI(api_key=api_key,base_url=\"https://api.deepseek.com\")\n\n\n def __init__(self,set_api_key,data_queue:Queue):\n self.api_key = set_api_key\n self.client.api_key=set_api_key\n self.data_queue = data_queue\n\n def set_ley(self,key:str):\n self.api_key = key\n\n def send_data(self,head:str,data):\n send = (head,data)\n self.data_queue.put(send)\n\n def generate_promots(self,num_of_questions):\n promots = f\"接下来我将给你{num_of_questions}道题目,帮我解答,注意B选项可能错误识别为8。你只需要告诉我答案不需要写解析,你要快速输出。\"+\"输出格式:题干+换行+答案标号和答案内容+换行+解释+换行+换行\"\n return promots\n\n def format_output(self,answer):\n j_answer = json.loads(answer)\n format_output = []\n for e in j_answer:\n format_output.append([e[\"question\"],e[\"type\"],e[\"options\"],e[\"answer\"],e[\"explanation\"]])\n return format_output\n \n def chat_to_ai(self,question):\n messages = [{\"role\": \"user\", \"content\": question}]\n response = self.client.chat.completions.create(model=\"deepseek-reasoner\",messages=messages)\n content = response.choices[0].message.content\n return content\n \n def request_balance(self):\n print(\"asking\")\n url = \"https://api.deepseek.com/user/balance\"\n payload={}\n headers = {\n 'Accept': 'application/json',\n 'Authorization': 'Bearer ' + self.api_key\n }\n try:\n response = requests.request(\"GET\", url, headers=headers, data=payload)\n response_json = json.loads(response.text)\n balance = (response_json[\"balance_infos\"][0][\"total_balance\"])\n except Exception as e:\n print(e)\n return None\n self.send_data(\"balance\",balance)\n return balance\n\n def ask_question(self,questions:str):\n text_question = self.generate_promots(len(questions))\n for q in questions:\n text_question+=q\n print(\"requesting...\")\n answers = self.chat_to_ai(text_question)\n\n return answers\n \n def print_single_answer(self,format_output):\n for e in format_output:\n print(e[0],e[1],e[3])\n \n"}, "bcb4c3078f6410c0afe9ce587dd9584f724026e4": {"t": 1785758442.2789397, "n": 2476, "h": "506e5a718f7f6950", "c": "from openai import OpenAI\nimport requests\nfrom multiprocessing import Queue\nimport json\n\nclass Chat_Api:\n api_key = ''\n client = OpenAI(api_key=api_key,base_url=\"https://api.deepseek.com\")\n\n\n def __init__(self,set_api_key,data_queue:Queue):\n self.api_key = set_api_key\n self.client.api_key=set_api_key\n self.data_queue = data_queue\n\n def set_ley(self,key:str):\n self.api_key = key\n\n def send_data(self,head:str,data):\n send = (head,data)\n self.data_queue.put(send)\n\n def generate_promots(self,num_of_questions):\n promots = f\"接下来我将给你{num_of_questions}道题目,帮我解答,注意B选项可能错误识别为8。你只需要告诉我答案不需要写解析,你要快速输出。\"+\"请按以下 JSON 格式输出: [{ \\\"question\\\": \\\"题目内容\\\", \\\"type\\\": \\\"题目类型(single_choice/multiple_choice/true_false)\\\", \\\"options\\\": {\\\"A\\\": \\\"选项A内容\\\", \\\"B\\\": \\\"选项B内容\\\", ...}, \\\"answer\\\": \\\"正确答案(单选/判断为字符串,多选为数组)\\\", \\\"explanation\\\": \\\"解析\\\" }下一道题....]\"\n return promots\n\n def format_output(self,answer):\n j_answer = json.loads(answer)\n format_output = []\n for e in j_answer:\n format_output.append([e[\"question\"],e[\"type\"],e[\"options\"],e[\"answer\"],e[\"explanation\"]])\n return format_output\n \n def chat_to_ai(self,question):\n messages = [{\"role\": \"user\", \"content\": question}]\n response = self.client.chat.completions.create(model=\"deepseek-reasoner\",messages=messages)\n content = response.choices[0].message.content\n return content\n \n def request_balance(self):\n print(\"asking\")\n url = \"https://api.deepseek.com/user/balance\"\n payload={}\n headers = {\n 'Accept': 'application/json',\n 'Authorization': 'Bearer ' + self.api_key\n }\n try:\n response = requests.request(\"GET\", url, headers=headers, data=payload)\n response_json = json.loads(response.text)\n balance = (response_json[\"balance_infos\"][0][\"total_balance\"])\n except Exception as e:\n print(e)\n return None\n self.send_data(\"balance\",balance)\n return balance\n\n def ask_question(self,questions:str):\n text_question = self.generate_promots(len(questions))\n for q in questions:\n text_question+=q\n print(\"requesting...\")\n answers = self.chat_to_ai(text_question)\n\n return answers\n \n def print_single_answer(self,format_output):\n for e in format_output:\n print(e[0],e[1],e[3])\n \n"}, "232574f62104d1e9709cb7bec7fa6d1da20ee188": {"t": 1785758443.4720829, "n": 2161, "h": "4a7104a41fa3ba66", "c": "from openai import OpenAI\nimport requests\nimport json\n\nclass Chat_Api:\n api_key = ''\n client = OpenAI(api_key=api_key,base_url=\"https://api.deepseek.com\")\n\n\n def __init__(self,set_api_key):\n self.api_key = set_api_key\n self.client.api_key=set_api_key\n\n def generate_promots(self,num_of_questions):\n promots = f\"接下来我将给你{num_of_questions}道题目,帮我解答,注意B选项可能错误识别为8。你只需要告诉我答案不需要写解析,你要快速输出。\"+\"请按以下 JSON 格式输出: [{ \\\"question\\\": \\\"题目内容\\\", \\\"type\\\": \\\"题目类型(single_choice/multiple_choice/true_false)\\\", \\\"options\\\": {\\\"A\\\": \\\"选项A内容\\\", \\\"B\\\": \\\"选项B内容\\\", ...}, \\\"answer\\\": \\\"正确答案(单选/判断为字符串,多选为数组)\\\", \\\"explanation\\\": \\\"解析\\\" }下一道题....]\"\n return promots\n\n def format_output(self,answer):\n j_answer = json.loads(answer)\n format_output = []\n for e in j_answer:\n format_output.append([e[\"question\"],e[\"type\"],e[\"options\"],e[\"answer\"],e[\"explanation\"]])\n return format_output\n \n def chat_to_ai(self,question):\n messages = [{\"role\": \"user\", \"content\": question}]\n response = self.client.chat.completions.create(model=\"deepseek-reasoner\",messages=messages)\n content = response.choices[0].message.content\n return content\n \n def request_balance(self):\n url = \"https://api.deepseek.com/user/balance\"\n payload={}\n headers = {\n 'Accept': 'application/json',\n 'Authorization': 'Bearer ' + self.api_key\n }\n try:\n response = requests.request(\"GET\", url, headers=headers, data=payload)\n response_json = json.loads(response.text)\n balance = (response_json[\"balance_infos\"][0][\"total_balance\"])\n except Exception as e:\n print(e)\n return None\n return balance\n\n def ask_question(self,questions:str):\n text_question = self.generate_promots(len(questions))\n for q in questions:\n text_question+=q\n print(\"requesting...\")\n answers = self.chat_to_ai(text_question)\n return answers\n \n def print_single_answer(self,format_output):\n for e in format_output:\n print(e[0],e[1],e[3])\n \n"}, "6ca977661c6f8ea2ffe2ec617537ec85a0553f8b": {"t": 1785758446.2226412, "n": 1527, "h": "ad0b4d38855a8bb8", "c": "from openai import OpenAI\nimport requests\nimport json\n\nclass Chat_Api:\n api_key = ''\n client = OpenAI(api_key=api_key,base_url=\"https://api.deepseek.com\")\n\n\n def __init__(self,set_api_key):\n self.api_key = set_api_key\n self.client.api_key=set_api_key\n \n def generate_promots(self,num_of_questions):\n promots = f\"接下来我将给你{num_of_questions}道题目,帮我解答,注意B选项可能错误识别为8。:\"\n return promots\n\n\n def chat_to_ai(self,question):\n messages = [{\"role\": \"user\", \"content\": question}]\n response = self.client.chat.completions.create(model=\"deepseek-reasoner\",messages=messages)\n content = response.choices[0].message.content\n return content\n \n def request_balance(self):\n url = \"https://api.deepseek.com/user/balance\"\n payload={}\n headers = {\n 'Accept': 'application/json',\n 'Authorization': 'Bearer ' + self.api_key\n }\n try:\n response = requests.request(\"GET\", url, headers=headers, data=payload)\n response_json = json.loads(response.text)\n balance = (response_json[\"balance_infos\"][0][\"total_balance\"])\n except Exception as e:\n print(e)\n return None\n return balance\n\n def ask_question(self,questions):\n text_question = self.generate_promots(len(questions))\n for q in questions:\n text_question+=q\n print(\"requesting...\")\n answers = self.chat_to_ai(text_question)\n return answers\n \n \n\n"}, "142880c879ae2533f3aac9cca1ddc14efbf00380": {"t": 1785758447.868417, "n": 1194, "h": "2bf24f0f952ff3e8", "c": "from openai import OpenAI\nimport requests\nimport json\n\nclass Chat_Api:\n api_key = ''\n client = OpenAI(api_key=api_key,base_url=\"https://api.deepseek.com\")\n def __init__(self,set_api_key):\n self.api_key = set_api_key\n self.client.api_key=set_api_key\n \n def chat_to_ai(self,question):\n messages = [{\"role\": \"user\", \"content\": question}]\n response = self.client.chat.completions.create(model=\"deepseek-reasoner\",messages=messages)\n content = response.choices[0].message.content\n return content\n \n def request_balance(self):\n url = \"https://api.deepseek.com/user/balance\"\n payload={}\n headers = {\n 'Accept': 'application/json',\n 'Authorization': 'Bearer ' + self.api_key\n }\n try:\n response = requests.request(\"GET\", url, headers=headers, data=payload)\n response_json = json.loads(response.text)\n balance = (response_json[\"balance_infos\"][0][\"total_balance\"])\n except Exception as e:\n print(e)\n return None\n return balance\n\nchat_api = Chat_Api(\"sk-4dd7b73b63a149518ffd105c7a464634\")\nprint(chat_api.request_balance())\n"}}}}