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

漳州正规网站建设公司wordpress google插件

漳州正规网站建设公司,wordpress google插件,马化腾称视频号是全公司希望,网站开发需要注册账户吗目录 问题描述: 问题解决: 问题描述: 随着各种LLMs (Large Language Models)的出现,如何调用各种LLMs的api成为了经常会遇见的问题。 问题解决: 下面仅以生成给定sentence的复述句为例,说明…

目录

问题描述:

问题解决:


问题描述:

随着各种LLMs (Large Language Models)的出现,如何调用各种LLMs的api成为了经常会遇见的问题。

问题解决:

下面仅以生成给定sentence的复述句为例,说明如何应用。

data: 存放在.txt文件中,按行存放,每一行是一个句子

⚠️: 只能在本地运行,不可以在服务器上运行,并且,🪜要打开。

代码实现:

import openai
import time
import os
import random from tqdm import tqdmopenai.api_key = "YOUR API KEY" # GPT4.0
openai.api_base = 'https://api.ngapi.top/v1'def get_response(prompt, temperature=0.5, max_tokens=2048):completion = openai.ChatCompletion.create(# model="gpt-3.5-turbo",model="gpt-4",temperature=0,top_p=0,# max_tokens=max_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 = f"Generate a paraphrased version of the following sentence: {cur_sent}"prompts.append(prompt)return prompts
import 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', buffering=1) as res_file:count = 0for p in tqdm(generate_prompt(all_sentences), total=len(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.txt"write_path = f'/Users/qtxu/Workplace/Chatgpt/ATE_Task/{dataset}/{name}_paraphrase_sentence.txt'with 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.dtcms.com/a/462355.html

相关文章:

  • 营销网站首页设计wordpress 博客主题
  • 鸿蒙路上的那些事:从初学者到资源创作者
  • 河北网站开发联系电话4a网站建设公司
  • 在 VS Code 中让整个工作区只读
  • 优秀网站菜单wordpress注册收不到邮件
  • 合肥网站建设pqiw目录网站做外链
  • 泉州自主建站模板网站设计费用价目表
  • 让水分子“导航”,突破蛋白–糖类分子对接难题
  • 在dify工作流中如何定义filename自动生成
  • asp 网站后台免费的企业网页制作网站
  • ILSpy下载和安装教程(附安装包,图文并茂)
  • 微信小程序-9-上滑加载更多和下拉刷新及小程序更新分享和转发
  • 【AES加密专题】1.AES的原理详解和加密过程
  • hello_servlet
  • 易拉罐和瓶子分类数据集 6059张图片,支持yolo,coco json,paschal voc xml格式,识别率可达92.5%,文末提供下载地址
  • 1 玩转Linux命令行:基础文件操作实战教程
  • 图观 流渲染打包服务器
  • 为什么只有中国做网站需要备案建站技术博客
  • 最好的微网站建设价格搜索引擎排名国内
  • 自动化测试中元素定位失败的解决策略
  • 心痛之窗:滑动窗口算法解爱与愁的心痛(洛谷P1614)
  • 鸿蒙HTTP请求老是发不出去?一文带你彻底排查所有坑!
  • c# 开发网站开发做市级网站需要什么
  • 购物网站建设的必要性电商设计年终总结
  • 元宵节html+css+js 5页
  • 基于单片机的温度烟雾与漏电综合火灾报警系统设计
  • NX565NX578美光SSD固态闪存NX579NX580
  • 永久解决ubuntu网络连接问题
  • Linux timeout 命令详解:精准控制程序运行时长,避免资源浪费
  • 免费php域名网站专业品牌网站设计公司