我的微信小程序上线了,AI识图生诗词文案,识别图片生成古诗词,欢迎大家使用。
(用户日访问量太少了,大家帮我踩一下,谢谢!)
以下是我在开发中的一些经验和心得。
下面是一个简单的调用通义千问大模型api,实现问答的功能,因为我做的是生成文案的小程序,所以user_prompt是输入,result是大模型的输出。
# 先pip安装dashscope
import dashscope
# 你的通义千问API key,可以在https://www.aliyun.com/阿里云官网注册并申请
dashscope.api_key='sk-****************************'
from http import HTTPStatus
def call_with_prompt(prompt):
response = dashscope.Generation.call(
model=dashscope.Generation.Models.qwen_max,
prompt=prompt
)
if response.status_code == HTTPStatus.OK:
#print(response.output.text) # The output text
#print(response.usage) # The usage information
return response.output.text
else:
#print(response.code) # The error code.
#print(response.message) # The error message.
return None
theme = '您过奖了'
user_prompt = '将我的回答:' + theme +',改写为高情商、幽默、机智的回答'
result = call_with_prompt(user_prompt)
print(result)