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

台州市城市建设规划局网站网站分析 案例

台州市城市建设规划局网站,网站分析 案例,牙医工具网站建设课程设计报告,wordpress图片美化文章目录 一.先利用langchain官方文档的AI功能问问二.langchain async api三.串行#xff0c;异步速度比较 一.先利用langchain官方文档的AI功能问问 然后看他给的 Verified Sources 这个页面里面虽然有些函数是异步函数#xff0c;但是并非专门讲解异步的 二.langchain asy… 文章目录 一.先利用langchain官方文档的AI功能问问二.langchain async api三.串行异步速度比较 一.先利用langchain官方文档的AI功能问问 然后看他给的 Verified Sources 这个页面里面虽然有些函数是异步函数但是并非专门讲解异步的 二.langchain async api 还不如直接谷歌搜 一下搜到 上面那个AI文档问答没给出这个链接 官方示例 import asyncio import timefrom langchain.llms import OpenAI from langchain.prompts import PromptTemplate from langchain.chains import LLMChaindef generate_serially():llm OpenAI(temperature0.9)prompt PromptTemplate(input_variables[product],templateWhat is a good name for a company that makes {product}?,)chain LLMChain(llmllm, promptprompt)for _ in range(5):resp chain.run(producttoothpaste)print(resp)async def async_generate(chain):resp await chain.arun(producttoothpaste)print(resp)async def generate_concurrently():llm OpenAI(temperature0.9)prompt PromptTemplate(input_variables[product],templateWhat is a good name for a company that makes {product}?,)chain LLMChain(llmllm, promptprompt)tasks [async_generate(chain) for _ in range(5)]await asyncio.gather(*tasks)s time.perf_counter() # If running this outside of Jupyter, use asyncio.run(generate_concurrently()) await generate_concurrently() elapsed time.perf_counter() - s print(\033[1m fConcurrent executed in {elapsed:0.2f} seconds. \033[0m)s time.perf_counter() generate_serially() elapsed time.perf_counter() - s print(\033[1m fSerial executed in {elapsed:0.2f} seconds. \033[0m)不过官方代码报错了 我让copilot修改一下能跑了 import time import asyncio from langchain.llms import OpenAI from langchain.prompts import PromptTemplate from langchain.chains import LLMChaindef generate_serially():llm OpenAI(temperature0.9)prompt PromptTemplate(input_variables[product],templateWhat is a good name for a company that makes {product}?,)chain LLMChain(llmllm, promptprompt)for _ in range(5):resp chain.run(producttoothpaste)print(resp)async def async_generate(chain):resp await chain.arun(producttoothpaste)print(resp)async def generate_concurrently():llm OpenAI(temperature0.9)prompt PromptTemplate(input_variables[product],templateWhat is a good name for a company that makes {product}?,)chain LLMChain(llmllm, promptprompt)tasks [async_generate(chain) for _ in range(5)]await asyncio.gather(*tasks)async def main():s time.perf_counter()await generate_concurrently()elapsed time.perf_counter() - sprint(\033[1m fConcurrent executed in {elapsed:0.2f} seconds. \033[0m)s time.perf_counter()generate_serially()elapsed time.perf_counter() - sprint(\033[1m fSerial executed in {elapsed:0.2f} seconds. \033[0m)asyncio.run(main()) 这还有一篇官方blog 三.串行异步速度比较 先学习一下掘金上看到的一篇https://juejin.cn/post/7231907374688436284为了更方便的看到异步效果我在原博主的基础上print里面加了一个提示 # 引入time和asyncio模块 import time import asyncio # 引入OpenAI类 from langchain.llms import OpenAI# 定义异步函数async_generate该函数接收一个llm参数和一个name参数 async def async_generate(llm, name):# 调用OpenAI类的agenerate方法传入字符串列表[Hello, how are you?]并等待响应resp await llm.agenerate([Hello, how are you?])# 打印响应结果的生成文本和函数名print(f{name}: {resp.generations[0][0].text})# 定义异步函数generate_concurrently async def generate_concurrently():# 创建OpenAI实例并设置temperature参数为0.9llm OpenAI(temperature0.9)# 创建包含10个async_generate任务的列表tasks [async_generate(llm, fFunction {i}) for i in range(10)]# 并发执行任务await asyncio.gather(*tasks)# 主函数 # 如果在Jupyter Notebook环境运行该代码则无需手动调用await generate_concurrently()直接在下方执行单元格即可执行该函数 # 如果在命令行或其他环境下运行该代码则需要手动调用asyncio.run(generate_concurrently())来执行该函数 asyncio.run(generate_concurrently())免费用户一分钟只能3次实在是有点难蚌 整合一下博主的代码对两个速度进行比较但是这个调用限制真的很搞人啊啊啊 import time import asyncio from langchain.llms import OpenAIasync def async_generate(llm, name):resp await llm.agenerate([Hello, how are you?])# print(f{name}: {resp.generations[0][0].text})async def generate_concurrently():llm OpenAI(temperature0.9)tasks [async_generate(llm, fFunction {i}) for i in range(3)]await asyncio.gather(*tasks)def generate_serially():llm OpenAI(temperature0.9)for _ in range(3):resp llm.generate([Hello, how are you?])# print(resp.generations[0][0].text)async def main():s time.perf_counter()await generate_concurrently()elapsed time.perf_counter() - sprint(\033[1m fConcurrent executed in {elapsed:0.2f} seconds. \033[0m)s time.perf_counter()generate_serially()elapsed time.perf_counter() - sprint(\033[1m fSerial executed in {elapsed:0.2f} seconds. \033[0m)asyncio.run(main())再看一篇blog 作者将代码开源在这里了https://github.com/gabrielcassimiro17/async-langchain测试一下它的async_chain.py文件 读取csv的时候路径一直报错还好不久前总结了一篇blogPython中如何获取各种目录路径 直接获取当前脚本路径了 import os import pandas as pd# Get the directory where the script is located script_directory os.path.dirname(os.path.abspath(__file__))# Construct the path to the CSV file csv_path os.path.join(script_directory, wine_subset.csv)# Read the CSV file df pd.read_csv(csv_path)sequential_run.py 就不跑了… 一天200次调用都快没了 主要是看看两者区别
http://www.w-s-a.com/news/465535/

相关文章:

  • 贵州 跨境电商网站建设做淘宝店铺有哪些好的网站
  • 广州正规网站制作公司网站搭建公司
  • ui设计零基础好学吗珠海网站建设优化推广
  • 网站开发多少费用火车头采集wordpress发布时间
  • 有没有做皮艺的网站教育培训网站建设ppt
  • 建设外贸商城网站制作如何建设景区旅游网站
  • 网站建设服务的具体条件怎么建设一个响应式网站
  • 做flash的网站wordpress设置前台投稿
  • 商务网站开发文档迅雷资源做下载网站
  • 无极磁铁网站如何把地图放到自己做的网站上
  • 青浦赵巷网站建设公司网站开发需求文档
  • 苏州网站建设的公司哪家好无锡网站制作那些
  • 装饰公司网站模板科技成果鉴定机构
  • 给公司做的东西放到私人网站上十堰为企业做网站的单位
  • 手机网站建设价钱手机自己做网站
  • 网站建设属于哪种公司电子商务查询网站
  • 工程建设标准强制性条文最新版本网站关键词排名优化应该怎么做
  • 网站网页设计内容品牌高端网站建设公司
  • 网站开发报价 福州中国建筑网官网手机版
  • 网站 图片 自动往右移专门做定制化的网站
  • 最好用的cms手机百度关键词排名 网站优化软件
  • 凉山州城乡规划建设局网站长沙网站建设哪家强
  • 广州网站开发创意设计公司企业自己怎么制作网站首页
  • 曲靖 曲靖网站建设软件(app)开发wordpress 没有远程发布
  • 官方网站开发与定制网站建设技术是干嘛的
  • 昆明网站建设工作室网站菜单导航怎么做的
  • 南京网站做的好的公司猪八戒网站做推广怎么样
  • 建站收费标准福州网站搭建
  • 做防护用品的网站欧美网站建设风格特点
  • 龙华做网站联系电话北京软件开发培训班