langchain-learning/helloworld/helloworld_siliconflow.py
2026-04-12 17:39:33 +08:00

27 lines
722 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logging
from langchain_siliconflow import ChatSiliconFlow
import os
import dotenv
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
dotenv.load_dotenv()
## 设置环境变量
os.environ['SILICONFLOW_API_KEY'] = os.getenv("SILICONFLOW_API_KEY")
os.environ['SILICONFLOW_BASE_URL'] = os.getenv("SILICONFLOW_BASE_URL")
# 默认的 'model_name': 'deepseek-ai/DeepSeek-V3.1',
llm = ChatSiliconFlow(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B")
for chunk in llm.stream("一句话介绍一下你自己50字以内"):
print(chunk.text, end="", flush=True)
# response = llm.invoke("一句话介绍一下你自己50字以内")
# print(response)