jack 11 місяців тому
батько
коміт
a6bb80aaef
3 змінених файлів з 54 додано та 38 видалено
  1. 10 26
      api_ollama.py
  2. 26 1
      config.json
  3. 18 11
      main.py

+ 10 - 26
api_ollama.py

@@ -5,21 +5,6 @@ import sys
 import timeit
 from ollama import Client as oClient
 
-'''
-可选模型:
-qwen:1.8b
-qwen2:1.5b
-qwen2.5:3b
-gemma2:2b
-'''
-model_list = [
-    'qwen:1.8b',
-    'qwen2:1.5b',
-    'qwen2.5:3b',
-    'gemma2:2b'
-]
-
-
 class ChatBot:
     def __init__(self, host, messages, model='qwen:1.8b', temperature=0.4):
         self.client = oClient(host=host)
@@ -42,14 +27,13 @@ class ChatBot:
             print(f"\n发生错误: {e}")
 
 
-# if __name__ == "__main__":
-#     for m in model_list:
-#         C = ChatBot('http://erhe.top:27381', 'hello,你好呀', m)
-#         start_time = time.time()
-#
-#         response_context = C.start_chat()
-#         print(response_context)
-#
-#         end_time = time.time()
-#         run_time = end_time - start_time
-#         print(f"程序运行时间:{run_time} 秒\n")
+if __name__ == "__main__":
+    C = ChatBot('http://192.168.31.28:11434', 'hello,你好呀', 'llava:13b')
+    start_time = time.time()
+
+    response_context = C.start_chat()
+    print(response_context)
+
+    end_time = time.time()
+    run_time = end_time - start_time
+    print(f"程序运行时间:{run_time} 秒\n")

+ 26 - 1
config.json

@@ -4,7 +4,32 @@
       "https://wublock123.com",
       "https://m.odaily.news/newsflash",
       "https://www.chaincatcher.com/news",
-      "https://m.marsbit.co/flash/"
+      "https://www.panewslab.com/",
+      "https://www.theblockbeats.info/newsflash",
+      "https://www.jinse.cn/lives",
+      "https://www.techflowpost.com/article/index.html",
+      "https://foresightnews.pro/news",
+      "https://www.web3sj.com/news/"
+    ],
+    "prompt_words": "给你一个或多个网页的源代码, 里面是未清洗的网页源代码,你可以无视网页源代码的部分,关注内容就行,重复的话就不用说了,帮我总结一下这些网站的内容, 请用中文回答"
+  },
+  "A": {
+    "target_url_list": [
+      "https://www.eastmoney.com/",
+      "https://www.jrj.com.cn/",
+      "https://www.10jqka.com.cn/",
+      "https://www.stcn.com/",
+      "https://www.cs.com.cn/",
+      "https://www.cnstock.com/",
+      "https://www.cls.cn/",
+      "https://www.yicai.com/",
+      "https://www.hexun.com/",
+      "https://www.wind.com.cn/",
+      "https://www.sse.com.cn/",
+      "https://www.szse.cn/",
+      "https://www.xueqiu.com/",
+      "https://www.jiemian.com/",
+      "https://www.caixin.com/"
     ],
     "prompt_words": "给你一个或多个网页的源代码, 里面是未清洗的网页源代码,你可以无视网页源代码的部分,关注内容就行,重复的话就不用说了,帮我总结一下这些网站的内容, 请用中文回答"
   }

+ 18 - 11
main.py

@@ -10,7 +10,7 @@ from api_kimi import *
 from api_deepseek import *
 from send_to_email import *
 
-key = 'web3'
+key = 'A'
 
 
 class AINEWS:
@@ -61,8 +61,15 @@ class AINEWS:
                     print(f'正在打开: {url}')
                     # 在上下文中打开新页面
                     page = await context.new_page()
+
+                    # 监听导航事件
+                    def handle_navigation(frame):
+                        print(f"导航发生: {frame.url}")
+
+                    page.on('framenavigated', handle_navigation)
+
                     # 导航到指定网址
-                    await page.goto(url)
+                    await page.goto(url, wait_until='networkidle')  # 等待网络空闲
 
                     # 滚动页面, 获取更多信息
                     await self.scroll_to_percentage(page)
@@ -99,15 +106,15 @@ class AINEWS:
             return text
 
     def main(self, target_url_list, prompt_words):
-        text = asyncio.run(self.get_htmls(target_url_list))
-
-        self.save_to_txt(text)
-
-        prompt_words += text
-
-        # C = ChatBot('http://erhe.top:27381', prompt_words, 'qwen2.5:3b')
-        # response_context = C.start_chat()
-        # print(response_context)
+        # text = asyncio.run(self.get_htmls(target_url_list))
+        #
+        # self.save_to_txt(text)
+        #
+        # prompt_words += text
+
+        C = ChatBot('http://192.168.31.28:11434', '你好', 'llava:13b')
+        response_context = C.start_chat()
+        print(response_context)
 
         # K = KIMI()
         # response_context = K.call_kimi(prompt_words)