赞
踩
ZHIPUAI_API_KEY
从https://open.bigmodel.cn/获取from langchain_community.chat_models import ChatZhipuAI
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
import os
os.environ["ZHIPUAI_API_KEY"] = "xxx"
chat = ChatZhipuAI(
model="glm-4",
temperature=0.5,
)
messages = [
# AIMessage(content="Hi."),
# SystemMessage(content="你是一个数学家,只会回答数学问题."),
HumanMessage(content="已知一张桌子的价钱是一把椅子的10倍,又知一张桌子比一把椅子多288元,一张桌子和一把椅子各多少元?"),
]
response = chat.invoke(messages)
print(response.content)
from langchain_community.utilities import SQLDatabase
from langchain_community.chat_models import ChatSparkLLM
from langchain_core.messages import HumanMessage
# 星火3.5
# app_id = 'xx'
# api_key = 'xxx'
# api_secret = 'xxx'
# 星火3.0
app_id = 'xx'
api_key = 'xxx'
api_secret = 'xxx'
spark_llm = ChatSparkLLM(
spark_app_id=app_id, spark_api_key=api_key, spark_api_secret=api_secret
)
message = HumanMessage(content="Hello")
spark_llm([message])
api-key
:https://help.aliyun.com/document_detail/611472.html?spm=a2c4g.2399481.0.0import os
os.environ["DASHSCOPE_API_KEY"] = 'sk-xx'
from langchain_community.chat_models.tongyi import ChatTongyi
from langchain_core.messages import HumanMessage
chatLLM = ChatTongyi(
streaming=True,
)
res = chatLLM.stream([HumanMessage(content="hi")], streaming=True)
for r in res:
print("chat resp:", r)
from langchain_core.messages import HumanMessage, SystemMessage
messages = [
SystemMessage(
content="你是一个数学家,只会回答数学问题."
),
HumanMessage(
content="已知一张桌子的价钱是一把椅子的10倍,又知一张桌子比一把椅子多288元,一张桌子和一把椅子各多少元?"
),
]
print(chatLLM(messages))
content=‘设一把椅子的价格为
x 元,那么根据题目描述,一张桌子的价格是椅子的10倍,即10x 元。\n\n根据题目中的第二个条件,桌子比椅子多288元,可以得到以下等式:\n\n\n\n解这个方程,我们可以找到10x−x=288 x 的值:\n\n\n9x=288 \nx=2889 \n\n所以一把椅子的价格是32元,一张桌子的价格就是:\n\nx=32 \n\n因此,一张桌子320元,一把椅子32元。’ response_metadata={‘model_name’: ‘qwen-turbo’, ‘finish_reason’: ‘stop’, ‘request_id’: ‘8d3720a4-129d-946f-9631-26ae1ebbf22d’, ‘token_usage’: {‘input_tokens’: 59, ‘output_tokens’: 170, ‘total_tokens’: 229}} id=‘run-93ca5458-feda-4b71-9d20-1a00e591b722-0’10x=10×32=320
from langchain_core.messages import HumanMessage, SystemMessage
messages = [
SystemMessage(
content="你是一个历史学家,只会回答历史问题."
),
HumanMessage(
content="多尔衮是谁?"
),
]
print(chatLLM(messages))
content=‘多尔衮是清朝开国功臣之一,努尔哈赤的第十四子,皇太极的同母弟。在清军入关前,他作为八旗中的镶白旗旗主,参与了多次重要战役,如萨尔浒之战、松锦之战等,对清朝的建立和发展有着重大贡献。在皇太极去世后,多尔衮摄政,辅佐年幼的顺治帝福临,实际上执掌朝政,期间推行了一系列改革和稳定措施。然而,他的权力过大引起了其他满洲贵族的不满,最终在顺治帝亲政后被削去大权,并在顺治五年(1650年)去世,死因存有争议。多尔衮是中国清朝前期的重要人物之一。’ response_metadata={‘model_name’: ‘qwen-turbo’, ‘finish_reason’: ‘stop’, ‘request_id’: ‘dba7bbfc-7bb1-9a1e-9a98-45d3eab7cf38’, ‘token_usage’: {‘input_tokens’: 28, ‘output_tokens’: 164, ‘total_tokens’: 192}} id=‘run-5d90cbfd-ddfc-4abe-a17f-1273a49a2813-0’
from langchain_core.messages import HumanMessage, SystemMessage
messages = [
SystemMessage(
content="你擅长翻译英文到中文,达到信达雅的翻译能力."
),
HumanMessage(
content="Studies serve for delight, for ornament, and for ability. Their chief use for delight, is in privateness and retiring; for ornament, is in discourse; and for ability, is in the judgment and disposition of business."
),
]
print(chatLLM(messages))
content=‘研习之目的,在于怡情、为了装饰,并增长才干。其主要的娱乐作用在于独处之时;用以交谈,则可作为点缀;而要处理事务,还得依赖于判断力和处事才能。’ response_metadata={‘model_name’: ‘qwen-turbo’, ‘finish_reason’: ‘stop’, ‘request_id’: ‘600f49c5-1268-96e6-ad83-61a0ff4a6c57’, ‘token_usage’: {‘input_tokens’: 74, ‘output_tokens’: 48, ‘total_tokens’: 122}} id=‘run-223b18f1-d055-44c6-8880-34b3e6784c19-0’
大家觉得翻译的怎么样?
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。