|
@@ -14,6 +14,29 @@ key = 'web3'
|
|
|
|
|
|
|
|
|
|
|
|
|
class AINEWS:
|
|
class AINEWS:
|
|
|
|
|
+ def create_config_if_not_exists():
|
|
|
|
|
+ # 获取当前文件的目录路径
|
|
|
|
|
+ current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
+
|
|
|
|
|
+ # 构建 config.json 文件的完整路径
|
|
|
|
|
+ config_path = os.path.join(current_dir, 'config.json')
|
|
|
|
|
+
|
|
|
|
|
+ # 检查 config.json 文件是否存在
|
|
|
|
|
+ if not os.path.exists(config_path):
|
|
|
|
|
+ # 如果不存在,创建并写入默认的 JSON 数据
|
|
|
|
|
+ default_config = {
|
|
|
|
|
+ "example": {
|
|
|
|
|
+ "target_url_list": [],
|
|
|
|
|
+ "prompt_words": "",
|
|
|
|
|
+ "role": ""
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # 写入 JSON 数据到 config.json 文件
|
|
|
|
|
+ with open(config_path, 'w', encoding='utf-8') as f:
|
|
|
|
|
+ json.dump(default_config, f, indent=4)
|
|
|
|
|
+
|
|
|
|
|
+ print(f"Created {config_path} with default configuration.")
|
|
|
def save_to_txt(self, url_to_text):
|
|
def save_to_txt(self, url_to_text):
|
|
|
current_file_path = os.path.dirname(__file__)
|
|
current_file_path = os.path.dirname(__file__)
|
|
|
save_file_path = os.path.join(current_file_path, 'save_txt')
|
|
save_file_path = os.path.join(current_file_path, 'save_txt')
|
|
@@ -32,10 +55,10 @@ class AINEWS:
|
|
|
|
|
|
|
|
if not config:
|
|
if not config:
|
|
|
print('config.json is not exist!')
|
|
print('config.json is not exist!')
|
|
|
- exit()
|
|
|
|
|
|
|
+ exit(0)
|
|
|
|
|
|
|
|
k = config[key]
|
|
k = config[key]
|
|
|
- return k['target_url_list'], k['prompt_words']
|
|
|
|
|
|
|
+ return k['target_url_list'], k['prompt_words'], k['role']
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
async def scroll_to_percentage(page):
|
|
async def scroll_to_percentage(page):
|
|
@@ -97,7 +120,7 @@ class AINEWS:
|
|
|
|
|
|
|
|
return url_to_text
|
|
return url_to_text
|
|
|
|
|
|
|
|
- def main(self, target_url_list, prompt_words):
|
|
|
|
|
|
|
+ def main(self, target_url_list, prompt_words, role):
|
|
|
url_to_text = asyncio.run(self.get_htmls(target_url_list))
|
|
url_to_text = asyncio.run(self.get_htmls(target_url_list))
|
|
|
|
|
|
|
|
# 创建消息bot实例
|
|
# 创建消息bot实例
|
|
@@ -105,18 +128,12 @@ class AINEWS:
|
|
|
|
|
|
|
|
self.save_to_txt(url_to_text)
|
|
self.save_to_txt(url_to_text)
|
|
|
|
|
|
|
|
- role = '你是一个新闻报播员'
|
|
|
|
|
-
|
|
|
|
|
- prompt_words += ''
|
|
|
|
|
-
|
|
|
|
|
O = OllamaChat()
|
|
O = OllamaChat()
|
|
|
for k, v in url_to_text.items():
|
|
for k, v in url_to_text.items():
|
|
|
response_context = O.call_ollama('http://127.0.0.1:11434', role, v, prompt_words)
|
|
response_context = O.call_ollama('http://127.0.0.1:11434', role, v, prompt_words)
|
|
|
message = f'{k}\n{response_context}\n'
|
|
message = f'{k}\n{response_context}\n'
|
|
|
-
|
|
|
|
|
# 发送消息
|
|
# 发送消息
|
|
|
bot.send_message(message)
|
|
bot.send_message(message)
|
|
|
-
|
|
|
|
|
|
|
|
|
|
# K = KIMI()
|
|
# K = KIMI()
|
|
|
# response_context = K.call_kimi(prompt_words)
|
|
# response_context = K.call_kimi(prompt_words)
|
|
@@ -130,8 +147,10 @@ class AINEWS:
|
|
|
# message = f'{k}\n{response_context}\n'
|
|
# message = f'{k}\n{response_context}\n'
|
|
|
# print(message)
|
|
# print(message)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
ainews = AINEWS()
|
|
ainews = AINEWS()
|
|
|
- target_url_list, prompt_words = ainews.load_config(key)
|
|
|
|
|
- ainews.main(target_url_list, prompt_words)
|
|
|
|
|
|
|
+ ainews.create_config_if_not_exists()
|
|
|
|
|
+ target_url_list, prompt_words, role = ainews.load_config(key)
|
|
|
|
|
+ ainews.main(target_url_list, prompt_words, role)
|
|
|
print('done!')
|
|
print('done!')
|