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

何做百度推广网站市场营销的主要应用领域

何做百度推广网站,市场营销的主要应用领域,怎样制作一个购物小程序,求好心人给个地址目录 问题描述: 问题解决: 问题描述: 随着各种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 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/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.yayakq.cn/news/251856/

相关文章:

  • 南昌企业网站制作五指山网站建设
  • 家具电商网站建设网站美工做专题尺寸多少
  • 制作网站用什么软件有哪些wordpress 仿北京时间
  • 沁阳建网站用vs做购物网站代码
  • 国外公司网站模板手机网站制作app
  • wordpress源码网站主题手机医疗网站模板
  • 网站 用cms 侵权免费公司网址怎么注册
  • 网站开发技术html5软件开发公司排行
  • 营销型网站的名词解释玉溪做网站
  • php网站开发班wordpress 快速安装失败
  • 网站规划与网页设计案例上海做网站公司有哪些
  • 太原智能化营销网站制作公司企业建站为什么选择网站定制
  • 网站建设阿胶膏的作用制作网页的步骤是什么
  • 网站怎么做访问量统计宣传类的网站
  • 中装建设集团有限公司股票搜索引擎优化英文简称为
  • 新手做淘宝哪个网站比较好wordpress 微信 微博
  • 福田网站设计公司免费网络推广方法
  • 成品门户网站源码免费腾云公司做网站
  • 沈阳自助模板建站网络推广引流最快方法
  • 游戏网站怎么建设上海关键词排名优化公司
  • 广告网站设计苏州工业园区限电
  • 公司做网站的费用入账苏州外贸网站建设制作方案
  • 网站建设规划设计任务书长沙网站平台建设公司
  • 网站开发资料河南航天建设工程有限公司网站
  • 南宁网站开发软件新开传奇网站站
  • 沧源网站建设怎么制作h5棋牌软件
  • 曲靖网站设计泊头市建设局网站
  • 山东 网站建设百度app官方正式版
  • 搜寻的网站有哪些建筑室内设计网
  • 网站图标用代码代替怎么创建自己的网址