18 lines
496 B
Python
18 lines
496 B
Python
import os
|
|
|
|
from langchain.chat_models import init_chat_model
|
|
|
|
|
|
def get_llm(
|
|
model: str = "openai:qwen3.6-flash",
|
|
base_url: str | None = None,
|
|
api_key: str | None = None,
|
|
**kwargs,
|
|
):
|
|
"""初始化 ChatModel,默认从环境变量读取 BASE_URL / API_KEY。"""
|
|
if base_url is None:
|
|
base_url = os.getenv("BASE_URL")
|
|
if api_key is None:
|
|
api_key = os.getenv("API_KEY")
|
|
return init_chat_model(model=model, base_url=base_url, api_key=api_key, **kwargs)
|