AI Agent Note (0x01)
2025-11-28 00:00:00 # AI

Agent Tool Development ※

Using LangChain to call Tongyi Qianwen

0x01、Init LLM

1
2
3
4
5
6
7
8
9
10
11
from langchain_openai import ChatOpenAI
from pydantic import SecretStr

llm = ChatOpenAI(
model="qwen-max-latest",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
api_key=SecretStr("sk-*****"),
streaming=True
)

print(llm)

Using SecretStr Package to encode api_key, result for here

image-20251128000450148

Making a steam out func use to test

1
2
3
4
# steam out func
def Resp(resp_steam):
for chunk in resp_steam:
print(chunk.content, end="")