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

html做网站头部买什么样的主机(用来建网站的)支持下载

html做网站头部,买什么样的主机(用来建网站的)支持下载,写网站软件,兰州网络推广哪家好本文将介绍如何使用 Amazon Bedrock 最新推出的 Converse API#xff0c;来简化与各种大型语言模型的交互。该 API 提供了一致的接口#xff0c;可以无缝调用各种大型模型#xff0c;从而消除了需要自己编写复杂辅助功能函数的重复性工作。文中示例将展示它相比于以前针对每…本文将介绍如何使用 Amazon Bedrock 最新推出的 Converse API来简化与各种大型语言模型的交互。该 API 提供了一致的接口可以无缝调用各种大型模型从而消除了需要自己编写复杂辅助功能函数的重复性工作。文中示例将展示它相比于以前针对每个模型进行独立集成的方式具有更简单的实现。文中还将提供完整代码展示使用 Converse API 来调用 Claude 3 Sonnet 模型进行多模态图像描述。 亚马逊云科技开发者社区为开发者们提供全球的开发技术资源。这里有技术文档、开发案例、技术专栏、培训视频、活动与竞赛等。帮助中国开发者对接世界最前沿技术观点和项目并将中国优秀开发者或技术推荐给全球云社区。如果你还没有关注/收藏看到这里请一定不要匆匆划过点这里让它成为你的技术宝库 为了帮助开发者快速理解新的 Converse API我对比了在 Converse API 发布之前开发者是如何用代码实现调用多个大模型并集成到统一接口的示例。通过 Converse API 示例代码我将展示 Converse API 是如何轻松完成简化统一多模型交互接口的工作。最后我还会重点分享如何使用 Converse API 调用 Claude 3 Sonnet 模型分析两张在美丽的中国香港拍摄的街景照片。 本文选自我于 2024 年 6 月在 Amazon Web Services 开发者社区上发表的技术博客“Streaming Large Language Model Interactions with Amazon Bedrock Converse API”。 Converse API 之前的世界 过去开发人员必须编写复杂的辅助函数来统一应付不同大语言模型之前不同的的输入和输出格式。例如在 2024 年 5 月初的亚马逊云科技香港峰会中为了在一个文件中使用 Amazon Bedrock 调用 5-6 个不同的大语言模型我需要编写总共 116 行代码来实现这个统一接口的功能。 我当时是使用 Python 语言来编写这个函数其它语言实现也基本类似。在没有 Converse API 之前开发者需要自己编写辅助函数调用 Amazon Bedrock 中来自不同提供商Anthropic、Mistral、AI21、Amazon、Cohere 和 Meta 等的不同大型语言模型。 以下我的代码中的“invoke_model”函数接受提示词、模型名以及各种参数配置例如温度、top-k、top-p 和停止序列等最终得到来自指定语言模型生成的输出文本。 我之前需要编写的辅助函数代码中需要考虑来自不同模型提供商的提示词格式要求然后才能发送针对某些特定模型的指定输入数据和提示词结构。代码如下所示 import json import boto3def invoke_model(client, prompt, model, accept application/json, content_type application/json,max_tokens 512, temperature 1.0, top_p 1.0, top_k 200, stop_sequences [],count_penalty 0, presence_penalty 0, frequency_penalty 0, return_likelihoods NONE):# default responseoutput # identify the model providerprovider model.split(.)[0] # InvokeModelif (provider anthropic): input {prompt: prompt,max_tokens_to_sample: max_tokens, temperature: temperature,top_k: top_k,top_p: top_p,stop_sequences: stop_sequences}bodyjson.dumps(input)response client.invoke_model(bodybody, modelIdmodel, acceptaccept,contentTypecontent_type)response_body json.loads(response.get(body).read())output response_body[completion]elif (provider mistral): input {prompt: prompt,max_tokens: max_tokens,temperature: temperature,top_k: top_k,top_p: top_p,stop: stop_sequences}bodyjson.dumps(input)response client.invoke_model(bodybody, modelIdmodel, acceptaccept,contentTypecontent_type)response_body json.loads(response.get(body).read())results response_body[outputs]for result in results:output output result[text] elif (provider ai21): input {prompt: prompt, maxTokens: max_tokens,temperature: temperature,topP: top_p,stopSequences: stop_sequences,countPenalty: {scale: count_penalty},presencePenalty: {scale: presence_penalty},frequencyPenalty: {scale: frequency_penalty}}bodyjson.dumps(input)response client.invoke_model(bodybody, modelIdmodel, acceptaccept,contentTypecontent_type)response_body json.loads(response.get(body).read())completions response_body[completions]for part in completions:output output part[data][text]elif (provider amazon): input {inputText: prompt,textGenerationConfig: {maxTokenCount: max_tokens,stopSequences: stop_sequences,temperature: temperature,topP: top_p}}bodyjson.dumps(input)response client.invoke_model(bodybody, modelIdmodel, acceptaccept,contentTypecontent_type)response_body json.loads(response.get(body).read())results response_body[results]for result in results:output output result[outputText]elif (provider cohere): input {prompt: prompt, max_tokens: max_tokens,temperature: temperature,k: top_k,p: top_p,stop_sequences: stop_sequences,return_likelihoods: return_likelihoods}bodyjson.dumps(input)response client.invoke_model(bodybody, modelIdmodel, acceptaccept,contentTypecontent_type)response_body json.loads(response.get(body).read())results response_body[generations]for result in results:output output result[text]elif (provider meta): input {prompt: prompt,max_gen_len: max_tokens,temperature: temperature,top_p: top_p}bodyjson.dumps(input)response client.invoke_model(bodybody, modelIdmodel, acceptaccept,contentTypecontent_type)response_body json.loads(response.get(body).read())output response_body[generation]# returnreturn output# main function bedrock boto3.client(service_namebedrock-runtime ) model mistral.mistral-7b-instruct-v0:2 prompt Human: Explain how chicken swim to an 8 year old using 2 paragraphs.Assistant:output invoke_model(clientbedrock, promptprompt, modelmodel) print(output)以上代码行数仅展示了针对这几个模型的接口函数实现随着需要统一调用的不同大型模型越来越多代码量还会不断增长。完整代码如下所示https://catalog.us-east-1.prod.workshops.aws/workshops/5501fb48-e04b-476d-89b0-43a7ecaf1595/en-US/full-day-event-fm-and-embedding/fm/03-making-things-simpler?trkcndc-detail 使用 Converse API 的世界 以下来自亚马逊云科技官方网站的代码片段展示了使用 Amazon Bedrock Converse API 调用大型语言模型的简易性 def generate_conversation(bedrock_client,model_id,system_text,input_text):……# Send the message.response bedrock_client.converse(modelIdmodel_id,messagesmessages,systemsystem_prompts,inferenceConfiginference_config,additionalModelRequestFieldsadditional_model_fields)……完整代码可以参考以下链接https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#message-inference-examples?trkcndc-detail 为了提供给开发者们一个使用 Converse API 调用大模型的完整代码示例特设计以下这个香港铜锣湾街景的大模型描述任务。 代码示例中主要使用 converse() 方法将文本和图像发送到 Claude 3 Sonnet 模型的示例。代码读入一个图像文件使用文本提示和图像字节创建消息有效负载然后打印出模型对场景的描述。另外在这段代码中如果要使用不同的图像进行测试只需更新输入文件路径即可。 输入图片为两张照片如下所示。这是我在撰写这篇技术文章时从窗户拍摄出去的香港铜锣湾的美丽街景照 Causeway Bay Street View, Hong Kong (Image 1) Causeway Bay Street View, Hong Kong (Image 2) 在核心代码部分我根据前面提到的亚马逊云科技官方网站提供的示例代码稍做修改编写了一个新的 generate_conversation_with_image() 函数并在 main() 主函数的合适位置调用这个函数。完整代码如下所示 def generate_conversation_with_image(bedrock_client,model_id,input_text,input_image):Sends a message to a model.Args:bedrock_client: The Boto3 Bedrock runtime client.model_id (str): The model ID to use.input text : The input message.input_image : The input image.Returns:response (JSON): The conversation that the model generated.logger.info(Generating message with model %s, model_id)# Message to send.with open(input_image, rb) as f:image f.read()message {role: user,content: [{text: input_text},{image: {format: png,source: {bytes: image}}}]}messages [message]# Send the message.response bedrock_client.converse(modelIdmodel_id,messagesmessages)return responsedef main():Entrypoint for Anthropic Claude 3 Sonnet example.logging.basicConfig(levellogging.INFO,format%(levelname)s: %(message)s)model_id anthropic.claude-3-sonnet-20240229-v1:0input_text Whats in this image?input_image IMG_1_Haowen.jpgtry:bedrock_client boto3.client(service_namebedrock-runtime)response generate_conversation_with_image(bedrock_client, model_id, input_text, input_image)output_message response[output][message]print(fRole: {output_message[role]})for content in output_message[content]:print(fText: {content[text]})token_usage response[usage]print(fInput tokens: {token_usage[inputTokens]})print(fOutput tokens: {token_usage[outputTokens]})print(fTotal tokens: {token_usage[totalTokens]})print(fStop reason: {response[stopReason]})except ClientError as err:message err.response[Error][Message]logger.error(A client error occurred: %s, message)print(fA client error occured: {message})else:print(fFinished generating text with model {model_id}.)if __name__ __main__:main()对于铜锣湾街景照片之一我从 Claude 3 Sonnet 模型中获得以下输出结果 为了读者阅读的方便我在此处复制了这个模型的输出结果 Role: assistant Text: This image shows a dense urban cityscape with numerous high-rise residential and office buildings in Hong Kong. In the foreground, there are sports facilities like a running track, soccer/football fields, and tennis/basketball courts surrounded by the towering skyscrapers of the city. The sports venues provide open green spaces amidst the densely packed urban environment. The scene captures the juxtaposition of modern city living and recreational amenities in a major metropolitan area like Hong Kong. Input tokens: 1580 Output tokens: 103 Total tokens: 1683 Stop reason: end_turn Finished generating text with model anthropic.claude-3-sonnet-20240229-v1:0.对于铜锣湾街景照片之二我只是简单地将代码中的 input_image 路径修改为新的图像路径。当我将该照片作为新图像输入到 Claude 3 Sonnet 模型时我从 Claude 3 Sonnet 模型中获得了以下输出结果 为了读者阅读的方便我在此处同样复制了这个模型的输出结果 Role: assistant Text: This image shows an aerial view of a dense urban city skyline, likely in a major metropolitan area. The cityscape is dominated by tall skyscrapers and high-rise apartment or office buildings of varying architectural styles, indicating a highly developed and populous city center.In the foreground, a major highway or expressway can be seen cutting through the city, with multiple lanes of traffic visible, though the traffic appears relatively light in this particular view. There are also some pockets of greenery interspersed among the buildings, such as parks or green spaces.One notable feature is a large billboard or advertisement for the luxury brand Chanel prominently displayed on the side of a building, suggesting this is a commercial and shopping district.Overall, the image captures the concentrated urban density, modern infrastructure, and mixture of residential, commercial, and transportation elements characteristic of a major cosmopolitan city. Input tokens: 1580 Output tokens: 188 Total tokens: 1768 Stop reason: end_turn Finished generating text with model anthropic.claude-3-sonnet-20240229-v1:0.小结 Amazon Bedrock 的新 Converse API 通过提供一致的接口简化了与大型语言模型之间的不同交互而无需针对于特定模型编写特定的实现。传统方式下开发人员需要编写包含数百行代码的复杂辅助函数以统一各个模型的输入/输出格式。Converse API 允许使用相同的 API 无缝调用各种大语言模型从而大大降低了代码复杂度。 本文的代码示例展示了 Converse API 的简洁性而过去的方法需要针对每个模型提供者进行独特的集成。第二个代码示例重点介绍了通过 Converse API 调用 Claude 3 Sonnet 模型进行图像描述。 总体而言Converse API 简化了在 Amazon Bedrock 中使用不同的大型语言模型的交互过程通过一致性的界面大幅减少了开发工作量让生成式 AI 应用的开发者可以更加专注于基于自己业务的独特创新和想象力。 说明本博客文章的封面图像由在 Amazon Bedrock 上的 Stable Diffusion SDXL 1.0 大模型生成。 提供给 Stable Diffusion SDXL 1.0 大模型的英文提示词如下供参考 “a developer sitting in the cafe, comic, graphic illustration, comic art, graphic novel art, vibrant, highly detailed, colored, 2d minimalistic” 文章来源使用 Amazon Bedrock Converse API 简化大语言模型交互
http://www.tj-hxxt.cn/news/130753.html

相关文章:

  • 培训网站免费找人做网站服务器不是自己的怎么办
  • 站酷官网交互做的好的网站
  • 网站建设公司销售技巧wordpress 主题格式
  • 网页设计与网站建设中的热点是什么wordpress 宕机
  • 东阳网站建设福州网站开发公司
  • 南京医院手机网站建设wordpress主页布局
  • 做个网站需要学会什么安居客房产网
  • 专做丰田车货款的网站望野古诗王绩
  • 怎样做校园网站推广网站的横幅怎么做的
  • 自己做的网站怎么绑域名苏州工业园区质安监站网址
  • 本土建站工作室深圳龙岗做网站公司哪家好
  • 如何网站做淘客群晖 6.1 wordpress
  • 阿里巴巴网站建设方案设计网页的快捷网站
  • 苏州网站建设自助建站模板找南昌网站开发公司电话
  • 1.简述网站建设流程做设计找素材的+网站有哪些
  • 福州模板建站定制网站做网站被骗预付款怎么办
  • 怎么学习建设网站代理IP做网站
  • 做外贸的都有那些网站seo优化网站词
  • 如何选网站建设公司小程序推广是干什么的
  • 口碑好的做网站如何进行电子商务网站推广?
  • 网站备案幕布psd58同城建网站怎么做
  • 网站定制开发怎么写seo的站外优化流程
  • 网站制作多少页网站图片上的分享怎么做
  • 网站建设都有哪些书wordpress 会员付费
  • 旅行社应做哪些网站网站建设与制作就业前景
  • 文献综述 php网站开发android 做电子书下载网站
  • 西安o2o网站设计公司用家里的路由器做网站
  • 中信建设网站欧洲最新消息
  • 全美网站开发在线flash相册网站源码
  • 岳池住房和城乡建设厅网站宝塔wordpress经常502