jack 11 months ago
parent
commit
f27cdea4f9
2 changed files with 14 additions and 17 deletions
  1. 5 6
      api_ollama.py
  2. 9 11
      main.py

+ 5 - 6
api_ollama.py

@@ -3,18 +3,17 @@ import time
 from ollama import Client as oClient
 
 class ChatBot:
-    def __init__(self, host, messages, model='qwen:1.8b', temperature=0.4):
+    def call_ollama(self, host, messages, model='llava:13b', temperature=0.4):
         self.client = oClient(host=host)
         self.model = model
         self.messages = messages
         self.temperature = temperature
 
-    def start_chat(self):
         print(f'use model: {self.model}')
         try:
             response_iter = self.client.chat(model=self.model,
                                              messages=[
-                                                 {'role': 'user', 'content': '你是一个新闻整理专员'},
+                                                 {'role': 'system', 'content': '你是一个新闻整理专员'},
                                                  {'role': 'user', 'content': self.messages}
                                              ],
                                              options={"temperature": self.temperature},
@@ -25,12 +24,12 @@ class ChatBot:
 
 
 # if __name__ == "__main__":
-#     C = ChatBot('http://127.0.0.1:11434', 'hello,你好呀', 'llava:13b')
+#     C = ChatBot()
 #     start_time = time.time()
 #
-#     response_context = C.start_chat()
+#     response_context = C.call_ollama('http://127.0.0.1:11434', 'hello,你好呀', 'llava:13b')
 #     print(response_context)
 #
 #     end_time = time.time()
 #     run_time = end_time - start_time
-#     print(f"程序运行时间:{run_time} 秒\n")
+#     print(f"程序运行时间:{run_time} 秒\n")

+ 9 - 11
main.py

@@ -100,18 +100,21 @@ class AINEWS:
     def main(self, target_url_list, prompt_words):
         url_to_text = asyncio.run(self.get_htmls(target_url_list))
 
-        self.save_to_txt(url_to_text)
+        # 创建消息bot实例
+        bot = MatrixBot('message-bot', 'aaaAAA111!!!')
 
-        prepare_to_send = ''
+        self.save_to_txt(url_to_text)
 
         prompt_words += '帮我总结一下内容, 并且分析一下今天数字币为什么会跌'
 
-        C = ChatBot('http://127.0.0.1:11434', k, prompt_words, 'llava:13b')
+        O = OllamaChat()
         for k, v in url_to_text.items():
-            response_context = C.call_deepseek(v, prompt_words)
+            response_context = O.call_ollama('http://127.0.0.1:11434', v, prompt_words)
             message = f'{k}\n{response_context}\n'
-            prepare_to_send += message
-            print(message)
+
+            # 发送消息
+            bot.send_message(message)
+            
 
         # K = KIMI()
         # response_context = K.call_kimi(prompt_words)
@@ -123,13 +126,8 @@ class AINEWS:
 
         #     # 保存每一个字符串准备发送信息
         #     message = f'{k}\n{response_context}\n'
-        #     prepare_to_send += message
         #     print(message)
 
-        # 发送消息
-        bot = MatrixBot('message-bot', 'aaaAAA111!!!')
-        bot.send_message(message)
-
 if __name__ == "__main__":
     ainews = AINEWS()
     target_url_list, prompt_words = ainews.load_config(key)