You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
611 B
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# my_main.py
from dotenv import load_dotenv
from my_llm import MyLLM # 注意:这里导入我们自己的类
# 加载环境变量
load_dotenv()
# 实例化我们重写的客户端并指定provider
llm = MyLLM(provider="modelscope")
# 准备消息
messages = [{"role": "user", "content": "你好,请介绍一下你自己。"}]
# 发起调用think等方法都已从父类继承无需重写
response_stream = llm.think(messages)
# 打印响应
print("ModelScope Response:")
for chunk in response_stream:
# chunk 已经是文本片段,可以直接使用
print(chunk, end="", flush=True)