当前位置: 首页 > news >正文

上海闸北网站建设永久免费微信小程序商城

上海闸北网站建设,永久免费微信小程序商城,邵阳网,营销型网站主页定制文章目录 一、如何直接将多模态数据传输给模型二、如何使用 mutimodal prompts 一、如何直接将多模态数据传输给模型 在这里,我们演示了如何将多模式输入直接传递给模型。对于其他的支持多模态输入的模型提供者,langchain 在类中提供了内在逻辑来转化为期…

文章目录

  • 一、如何直接将多模态数据传输给模型
  • 二、如何使用 mutimodal prompts


一、如何直接将多模态数据传输给模型

 在这里,我们演示了如何将多模式输入直接传递给模型。对于其他的支持多模态输入的模型提供者,langchain 在类中提供了内在逻辑来转化为期待的格式。
 传入图像最常用的方法是将其作为字节字符串传入。这应该适用于大多数模型集成。

import base64
import httpximage_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8")message = HumanMessage(content=[{"type": "text", "text": "describe the weather in this image"},{"type": "image_url","image_url": {"url": f"data:image/jpeg;base64,{image_data}"},},],
)
response = model.invoke([message]) # 自己定义一个 model
print(response.content)
"""
The weather in the image appears to be clear and pleasant. The sky is mostly blue with scattered, light clouds, suggesting a sunny day with minimal cloud cover. There is no indication of rain or strong winds, and the overall scene looks bright and calm. The lush green grass and clear visibility further indicate good weather conditions.
"""

 我们可以直接在 “image_URL” 类型的内容块中提供图像 URL。但是注意,只有一些模型提供程序支持此功能。

message = HumanMessage(content=[{"type": "text", "text": "describe the weather in this image"},{"type": "image_url", "image_url": {"url": image_url}},],
)
response = model.invoke([message])
print(response.content)

 我们也可以传多个图片。

message = HumanMessage(content=[{"type": "text", "text": "are these two images the same?"},{"type": "image_url", "image_url": {"url": image_url}},{"type": "image_url", "image_url": {"url": image_url}},],
)
response = model.invoke([message])
print(response.content)
"""
Yes, the two images are the same. They both depict a wooden boardwalk extending through a grassy field under a blue sky with light clouds. The scenery, lighting, and composition are identical.
"""

二、如何使用 mutimodal prompts

 在这里,我们将描述一下怎么使用 prompt templates 来为模型格式化 multimodal imputs。

import base64
import httpx
from langchain_core.prompts import ChatPromptTemplateimage_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8")prompt = ChatPromptTemplate.from_messages([("system", "Describe the image provided"),("user",[{"type": "image_url","image_url": {"url": "data:image/jpeg;base64,{image_data}"},}],),]
)chain = prompt | modelresponse = chain.invoke({"image_data": image_data})
print(response.content)
"""
The image depicts a sunny day with a beautiful blue sky filled with scattered white clouds. The sky has varying shades of blue, ranging from a deeper hue near the horizon to a lighter, almost pale blue higher up. The white clouds are fluffy and scattered across the expanse of the sky, creating a peaceful and serene atmosphere. The lighting and cloud patterns suggest pleasant weather conditions, likely during the daytime hours on a mild, sunny day in an outdoor natural setting.
"""

 我们也可以给模型传入多个图片。

prompt = ChatPromptTemplate.from_messages([("system", "compare the two pictures provided"),("user",[{"type": "image_url","image_url": {"url": "data:image/jpeg;base64,{image_data1}"},},{"type": "image_url","image_url": {"url": "data:image/jpeg;base64,{image_data2}"},},],),]
)chain = prompt | modelresponse = chain.invoke({"image_data1": image_data, "image_data2": image_data})
print(response.content)
"""
The two images provided are identical. Both images feature a wooden boardwalk path extending through a lush green field under a bright blue sky with some clouds. The perspective, colors, and elements in both images are exactly the same.
"""
http://www.yayakq.cn/news/693558/

相关文章:

  • 六安网站制作费用海商网做网站价格
  • 安徽论坛网站建设wordpress dopt
  • 国外app模板下载网站青岛城阳 软件网站开发
  • 做网站通过什么赚钱吗湛江市企业网站seo点击软件
  • 好网站建设网站郑州网站建设hndream
  • 网站目录做跳转快速建站的公司
  • 怎么看网站是否被收录劳动仲裁案例100例
  • 面备案网站建设网页设计与制作教程的页数是
  • 大连做网站wordpress5.0默认主题
  • 宁夏建设工程招标投标信息网站网页架构人才培训中心
  • 做网站快速排名帮人做网站一定要先收费
  • 微信小程序推广软件重庆seo排名软件
  • 还能用的wap网站seo关键词推广优化
  • 网站建设怎样找客户网站开发可以申请著作权吗
  • 咚咚抢网站怎么做的广州营销网站建设设计
  • 自己做一个模版网站是怎么做的北京市建设厅门户网站6
  • 电子商务网站开发平台图购物网站制作代码
  • 网站开发可以不使用备案的网站名吗
  • 如何做网页网站辽宁数据网站建设哪家便宜
  • 自建网站营销是什么交互设计大学世界排名
  • 网站备案地址不是我的地址怎么办个人可以开通微商城吗
  • 如何建设高大上的网站网站建设速成班培训
  • 做的网站提示不安全问题wordpress登录界面能改吗
  • 网站上怎么做动图注册公司代理记帐
  • 西宁 专业网站建设google优化师
  • 字体样式 网站特产网站建设方案
  • wordpress视频网站上传视频网业无法打开?
  • 承德网站制作公司网站上文章分享的代码怎么做
  • 哪里可以接一些网站项目做学网络技术培训学校
  • 婚纱摄影网站seo方案网站建设都包括什么