# -*- coding: utf-8 -*- import time from ollama import Client as oClient class ChatBot: def __init__(self, host, messages, model='qwen:1.8b', 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': 'user', 'content': self.messages} ], options={"temperature": self.temperature}, stream=False) return response_iter['message']['content'] except Exception as e: print(f"\n发生错误: {e}") # if __name__ == "__main__": # C = ChatBot('http://127.0.0.1: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")