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

重庆学校网站推广网站建设公司 佛山

重庆学校网站推广,网站建设公司 佛山,社交新零售,图片转文章转wordpress目录 问题描述#xff1a; 问题解决#xff1a; 问题描述#xff1a; 随着各种LLMs (Large Language Models#xff09;的出现#xff0c;如何调用各种LLMs的api成为了经常会遇见的问题。 问题解决#xff1a; 下面仅以生成给定sentence的复述句为例#xff0c;说明…目录 问题描述 问题解决 问题描述 随着各种LLMs (Large Language Models的出现如何调用各种LLMs的api成为了经常会遇见的问题。 问题解决 下面仅以生成给定sentence的复述句为例说明如何应用。 data: 存放在.txt文件中按行存放每一行是一个句子 ⚠️ 只能在本地运行不可以在服务器上运行并且要打开。 代码实现 import openai import time import os import random from tqdm import tqdm # openai.api_key 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 # openai.api_key sk-huUlpXTcDnvNevXgB1399aCa9dB247F599D81737B7CfD927 # 实验室共有openai.api_key YOUR API KEY # GPT4.0 openai.api_base https://api.ngapi.top/v1def get_response(prompt, temperature0.5, max_tokens2048):completion openai.ChatCompletion.create(# modelgpt-3.5-turbo,modelgpt-4,temperature0,top_p0,# max_tokensmax_tokens,messages[{role: user, content: f{prompt}}])return completion def generate_prompt(all_sentences): # all_asps是一个listprompts []for cur_sent in all_sentences: # all_compared_pair是一个list:[asp,sub,obj]# prompt Please generate just one synonymous sentence for the given sentence. The current given sentence is : {}.format(cur_sent)prompt fGenerate a paraphrased version of the following sentence: {cur_sent}prompts.append(prompt)return promptsimport redef process_sentence(sentence):# 定义要添加空格的特殊字符, 比如’sspecial_chars [,, ., \, ’, “, ”, (, ), [, ], {, }, :, ;, ?, !] # - 因为sub,obj中存在很多以-为连字符的sub,obj所以原始句子中这部分不可以加空格# 在特殊字符前添加空格for char in special_chars:if char (: # 特别的左括号是在后面加空格sentence sentence re.sub(rf([{char}]), r\1 , sentence)else:sentence re.sub(rf([{char}]), r \1, sentence)return sentencedef get_res(all_sentences, wirte_path):if os.path.exists(wirte_path):res_file open(wirte_path)begin len(res_file.readlines()) 1 # 断点续传res_file.close()else:begin 0with open(wirte_path, a, buffering1) as res_file:count 0for p in tqdm(generate_prompt(all_sentences), totallen(all_sentences)):print(p)count 1if count begin:continuetry:res get_response(p)[choices][0][message][content]# print(res, res)processed_res process_sentence(res) # 处理成以单词标点符号等为分隔符空格# print(processed_res, processed_res)if The server is overloaded or not ready yet in processed_res:time.sleep(30)res_file.write(#### \n)else:res_file.write(processed_res \n)except Exception as e:if isinstance(e, openai.error.RateLimitError):time.sleep(30) # 处理拥挤的函数就只是睡着而已res get_response(p)[choices][0][message][content]processed_res process_sentence(res) # res_file.write(processed_res \n)else:print(e)exit(-1)# print(the number of prompt is :, count) from pdb import set_trace as stopdataset_list [14lap,14res, 15res, 16res] name_list [train, test, dev]# name_list [dev] # dataset_list [14lap]for dataset in dataset_list:for name in name_list:# print(dataste, dataset)# print(name, name)sentence_path f/Users/qtxu/Workplace/Chatgpt/ATE_Task/{dataset}/{name}_sentence.txtwrite_path f/Users/qtxu/Workplace/Chatgpt/ATE_Task/{dataset}/{name}_paraphrase_sentence.txtwith open(sentence_path,r) as fr:lines fr.readlines()all_sentences []for line in lines:all_sentences.append(line)# print(all_sentences, all_sentences)get_res(all_sentences, write_path)
http://www.zqtcl.cn/news/977685/

相关文章:

  • 顺的网站建设案例如何上传网站
  • 网站管理和建设工作职责中国建设银行卖狗年纪念币官方网站
  • 如何快速开发一个网站干洗店投资多少钱可以营业了
  • 哪些分类网站WordPress商用收费吗
  • 南开网站建设优化seo福建凭祥建设工程有限公司网站
  • 建设工程消防设计备案凭证查询网站网站建设课程设计目的和内容
  • 网站开发要花多少钱wordpress网站邀请码
  • 社旗网站设计小程序制作用华网天下优惠
  • 建设产品网站代理注册企业邮箱
  • 购物网站建设费用珠海本地网站
  • 做电商网站前期做什么工作网站后台jsp怎么做分页
  • 百家利网站开发搜索引擎分哪三类
  • 安徽集团网站建设深圳最新通告今天
  • 公司网站主机流量30g每月够用吗攀枝花网站网站建设
  • 淘宝做图片的网站手机网站北京
  • 重庆网站首页排名公司网站公众号小程序开发公司
  • 河源网站制作1993seo福州室内设计公司排名
  • 哪里有做装修网站网站开发总出现出现404
  • 做a漫画在线观看网站策划营销型网站
  • 怎么 从头开始建设一个网站临沂高端网站建设
  • 网页设计制作网站素材传奇代理平台
  • 公司建站网站软文营销方案
  • 成品短视频网站源码搭建免费温州外贸网站制作
  • 旅游公司网站建设pptwordpress 用户增强
  • wordpress 最新东莞seo技术培训
  • 上海微网站开发网站 选项卡 图标
  • 淘宝网站建设的目标什么做网站公司 营销
  • 360企业网站认证wordpress 个人照片
  • 韩国私人网站服务器创业做网站APP开发
  • 成都网站建设推来客网站系统报价wordpress 本地图片 图床