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

做电商哪个平台好商丘seo优化

做电商哪个平台好,商丘seo优化,个人音乐网站源码搭建,扬州疫情最新通报spark-wenxin 1-讯飞星火1_1-SparkApi.py1_2- Chat_spark.py1_3-调用api 2-百度文心2_1.code 3-两者之间比较与openai 1-讯飞星火 进入讯飞官网进行创建应用,获取相关密钥APPID,APISecret,APIKey,选择最新版本 首次调用讯飞官方a…

spark-wenxin

        • 1-讯飞星火
          • 1_1-SparkApi.py
          • 1_2- Chat_spark.py
          • 1_3-调用api
        • 2-百度文心
          • 2_1.code
        • 3-两者之间比较与openai

1-讯飞星火

进入讯飞官网进行创建应用,获取相关密钥APPID,APISecret,APIKey,选择最新版本
首次调用讯飞官方api可能有两问题:

1-No module named 'websocket'#安装 pip install websocket_client==1.4.2
2-spark_url="ws(s)://spark-api.xf-yun.com/v3.1/chat" #改为"ws://spark-api.xf-yun.com/v3.1/chat"

现搞了个完整的代码如下:
第一个相关请求的代码:SparkApi.py 相关参数可自行修改

1_1-SparkApi.py
import _thread as thread
import base64
import datetime
import hashlib
import hmac
import json
from urllib.parse import urlparse
import ssl
from datetime import datetime
from time import mktime
from urllib.parse import urlencode
from wsgiref.handlers import format_date_timeimport websocket  # 
answer = ""class Ws_Param(object):# 初始化def __init__(self, APPID, APIKey, APISecret, Spark_url):self.APPID = APPIDself.APIKey = APIKeyself.APISecret = APISecretself.host = urlparse(Spark_url).netlocself.path = urlparse(Spark_url).pathself.Spark_url = Spark_url# 生成urldef create_url(self):# 生成RFC1123格式的时间戳now = datetime.now()date = format_date_time(mktime(now.timetuple()))# 拼接字符串signature_origin = "host: " + self.host + "\n"signature_origin += "date: " + date + "\n"signature_origin += "GET " + self.path + " HTTP/1.1"# 进行hmac-sha256进行加密signature_sha = hmac.new(self.APISecret.encode('utf-8'), signature_origin.encode('utf-8'),digestmod=hashlib.sha256).digest()signature_sha_base64 = base64.b64encode(signature_sha).decode(encoding='utf-8')authorization_origin = f'api_key="{self.APIKey}", algorithm="hmac-sha256", headers="host date request-line", signature="{signature_sha_base64}"'authorization = base64.b64encode(authorization_origin.encode('utf-8')).decode(encoding='utf-8')# 将请求的鉴权参数组合为字典v = {"authorization": authorization,"date": date,"host": self.host}# 拼接鉴权参数,生成urlurl = self.Spark_url + '?' + urlencode(v)# 此处打印出建立连接时候的url,参考本demo的时候可取消上方打印的注释,比对相同参数时生成的url与自己代码生成的url是否一致return url# 收到websocket错误的处理
def on_error(ws, error):print("### error:", error)# 收到websocket关闭的处理
def on_close(ws,one,two):print(" ")# 收到websocket连接建立的处理
def on_open(ws):thread.start_new_thread(run, (ws,))def run(ws, *args):data = json.dumps(gen_params(appid=ws.appid, domain= ws.domain,question=ws.question))ws.send(data)# 收到websocket消息的处理
def on_message(ws, message):# print(message)data = json.loads(message)code = data['header']['code']if code != 0:print(f'请求错误: {code}, {data}')ws.close()else:choices = data["payload"]["choices"]status = choices["status"]content = choices["text"][0]["content"]print(content,end ="")global answeranswer += content# print(1)if status == 2:ws.close()def gen_params(appid, domain,question):"""通过appid和用户的提问来生成请参数"""data = {"header": {"app_id": appid,"uid": "1234"},"parameter": {"chat": {"domain": domain,"random_threshold": 0.5,"max_tokens": 2048,#"auditing": "default"}},"payload": {"message": {"text": question}}}return datadef main(appid, api_key, api_secret, Spark_url,domain, question):# print("星火:")wsParam = Ws_Param(appid, api_key, api_secret, Spark_url)websocket.enableTrace(False)wsUrl = wsParam.create_url()ws = websocket.WebSocketApp(wsUrl, on_message=on_message, on_error=on_error, on_close=on_close, on_open=on_open)ws.appid = appidws.question = questionws.domain = domainws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})

1_2- Chat_spark.py

通过创建应用获取密钥,选择版本创建,这里用的是3.0版本

import SparkApiclass SparkProcessor:#以下密钥信息从控制台获取3.0appid = "xxx"     #填写控制台中获取的 APPID 信息api_secret = "xxxx"   #填写控制台中获取的 APISecret 信息api_key ="xxx"    #填写控制台中获取的 APIKey 信息# # #2.0# appid = "xxx"     #填写控制台中获取的 APPID 信息# api_secret = "xxx"   #填写控制台中获取的 APISecret 信息# api_key ="xxx"    #填写控制台中获取的 APIKey 信息#用于配置大模型版本,默认“general/generalv2”#domain = "general"   # v1.5版本# domain = "generalv2"    # v2.0版本domain = "generalv3"    # v3.0版本#云端环境的服务地址#Spark_url = "ws://spark-api.xf-yun.com/v1.1/chat"  # v1.5环境的地址# Spark_url = "ws://spark-api.xf-yun.com/v2.1/chat"  # v2.0环境的地址Spark_url = "ws://spark-api.xf-yun.com/v3.1/chat"import SparkApiclass SparkProcessor:@staticmethoddef _get_text(role, content):#jsoncon = {}jsoncon["role"] = rolejsoncon["content"] = contentreturn jsoncon#实例方法#def get_text(self, role, content):#    jsoncon = {}#   jsoncon["role"] = role#   jsoncon["content"] = content#    return jsoncon@staticmethoddef _get_length(text):length = 0for content in text:temp = content["content"]leng = len(temp)length += lengreturn length@staticmethoddef _check_len(text):#私有方法while SparkProcessor._get_length(text) > 8000:del text[0]return text#类方法@classmethoddef spark_api(cls, question):text = []question = cls._check_len([cls._get_text("user", question)])SparkApi.answer = ""SparkApi.main(cls._get_appid(),cls._get_api_key(),cls._get_api_secret(),cls._get_spark_url(),cls._get_domain(),question,)text.clear()return SparkApi.answer# 私有方法获取敏感信息@staticmethoddef _get_appid():return "xxx"@staticmethoddef _get_api_secret():return "xxx"@staticmethoddef _get_api_key():return "xxx"@staticmethoddef _get_domain():return "xxx"@staticmethoddef _get_spark_url():return "xxx"
1_3-调用api

prompt的基本写法规则:
任务:明确而简洁地陈述Prompt 要求模型生成的内容
指令:模型在生成文本时应遵循的指令。
角色:模型在生成文本时应扮演的角色。

prompt1="""将文本分类为中性、负面或正面。文本:我认为这次假期还可以。情感:"""
from Chat_spark import SparkProcessor
result = SparkProcessor.spark_api(prompt1)
print(result)#中性
2-百度文心

人设+任务目标及解决方式+附加条件完整陈述

2_1.code

创建应用获取相关密钥

# -*- coding: utf-8 -*-
# @Author  : Elvis
# @Time    : 2023/11/13 10:56
# @File    : get_chat.py
# @describe: ""
api_key = 'xxx'
api_id = 'xxx'
secret_key = 'xxx'
name = 'CHAT'import requests
import jsondef get_access_token(api_k, secret_k):"""使用 API Key,Secret Key 获取access_token,替换下列示例中的应用API Key、应用Secret Key"""url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=%s&client_secret=%s" % (api_k, secret_k)
#     print('url: ', url)payload = json.dumps("")headers = {'Content-Type': 'application/json','Accept': 'application/json'}response = requests.request("POST", url, headers=headers, data=payload)return response.json().get("access_token")def get_main(prompt,sys=None):res = get_access_token(api_key, secret_key)
#     print('res: ', res)#     url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token=" + get_access_token()url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=" + respayload = json.dumps({"messages": [{"role": "user","content": prompt}],
#          "stream": True,"temperature":0.1,#(0, 1.0]"system":sys})headers = {'Content-Type': 'application/json'}response = requests.request("POST", url, headers=headers, data=payload)res = response.textprint(res)res1 = json.loads(res)
#     print(res1)return res1['result']
3-两者之间比较与openai

目前国内的效果在某些方面还是差点意思,没有公开过prompt实例,文心对格式控制很难把控,很难去掉提示语,星火给出的结果有时候偏差很大,估计还得明年中旬,训练慢慢好起来。

相关promot guide
想写好prompt,可以先上B站看一下关于吴恩达对openai 的prompt 视频。


文章转载自:
http://pete.c7625.cn
http://infielder.c7625.cn
http://mucous.c7625.cn
http://glaze.c7625.cn
http://lumber.c7625.cn
http://actualistic.c7625.cn
http://curtate.c7625.cn
http://worrywart.c7625.cn
http://succose.c7625.cn
http://knp.c7625.cn
http://thy.c7625.cn
http://cavelike.c7625.cn
http://archanthropine.c7625.cn
http://magyar.c7625.cn
http://tsarina.c7625.cn
http://tetramorphic.c7625.cn
http://extramental.c7625.cn
http://stirp.c7625.cn
http://pinnatifid.c7625.cn
http://bachelor.c7625.cn
http://unaptly.c7625.cn
http://chariot.c7625.cn
http://hegemonist.c7625.cn
http://hankerchief.c7625.cn
http://luxate.c7625.cn
http://whipray.c7625.cn
http://disaster.c7625.cn
http://dominate.c7625.cn
http://hcl.c7625.cn
http://midships.c7625.cn
http://bashful.c7625.cn
http://extinguishable.c7625.cn
http://dihydric.c7625.cn
http://insurance.c7625.cn
http://swad.c7625.cn
http://mariculture.c7625.cn
http://pistillate.c7625.cn
http://compaction.c7625.cn
http://gyro.c7625.cn
http://sieva.c7625.cn
http://dinero.c7625.cn
http://laptop.c7625.cn
http://discouragement.c7625.cn
http://swim.c7625.cn
http://identity.c7625.cn
http://roo.c7625.cn
http://marcia.c7625.cn
http://cerous.c7625.cn
http://headmaster.c7625.cn
http://dicom.c7625.cn
http://telescript.c7625.cn
http://for.c7625.cn
http://reindict.c7625.cn
http://selenium.c7625.cn
http://wallasey.c7625.cn
http://rejaser.c7625.cn
http://imparl.c7625.cn
http://pretender.c7625.cn
http://stiffness.c7625.cn
http://aplastic.c7625.cn
http://ambrosial.c7625.cn
http://bespectacled.c7625.cn
http://aymaran.c7625.cn
http://deciding.c7625.cn
http://burghley.c7625.cn
http://semicommercial.c7625.cn
http://homotaxis.c7625.cn
http://spongeable.c7625.cn
http://worthy.c7625.cn
http://totter.c7625.cn
http://paganism.c7625.cn
http://cordelle.c7625.cn
http://widest.c7625.cn
http://yakow.c7625.cn
http://impeller.c7625.cn
http://relinquishment.c7625.cn
http://showplace.c7625.cn
http://jdisplay.c7625.cn
http://scarifier.c7625.cn
http://oscillation.c7625.cn
http://zebeck.c7625.cn
http://swaggie.c7625.cn
http://embrace.c7625.cn
http://fiduciary.c7625.cn
http://accordionist.c7625.cn
http://runtishly.c7625.cn
http://sadhana.c7625.cn
http://congregational.c7625.cn
http://blacksploitation.c7625.cn
http://clarionet.c7625.cn
http://burn.c7625.cn
http://bodhisattva.c7625.cn
http://subterranean.c7625.cn
http://readme.c7625.cn
http://spine.c7625.cn
http://nidering.c7625.cn
http://concertinist.c7625.cn
http://analects.c7625.cn
http://afoul.c7625.cn
http://ballcarrier.c7625.cn
http://www.zhongyajixie.com/news/95299.html

相关文章:

  • 浙江苏省城乡建设厅网站百度竞价入口
  • dreamweaver动态网页制作重庆黄埔seo整站优化
  • 千秋网络是家西安做网站的公司国际域名注册网站
  • 网站模版一样 内容不同侵权吗熊猫关键词工具官网
  • wordpress用户名无效手机关键词排名优化
  • 做销售网站怎么在百度免费推广
  • 开锁都在什么网站做seo智能优化软件
  • 长沙专门做网站公司有哪些台湾新闻最新消息今天
  • vs做网站怎么调试宁波专业seo外包
  • 强大的技术团队网站建设湖南关键词优化品牌价格
  • 攀枝花做网站广告媒体资源平台
  • 民治网站设计圳网站建设公司广州关于进一步优化疫情防控措施
  • 网站同时做竞价和优化可以吗现在最火的推广平台有哪些
  • 各种网站底部图标代码开平网站设计
  • 平面图网站青岛网站建设优化
  • 技术支持 创思佳网站建设网站推广软件费用是多少
  • 如何用asp做视频网站市场调研报告怎么做
  • wordpress图像桂平seo关键词优化
  • 织梦做的网站打开空白全国人大常委会委员长
  • 怎么做网页注册登录教程北京seo主管
  • 网站规划与建设进度百度服务电话
  • 用群晖nas做网站就业seo好还是sem
  • 视频网站如何做微信营销专业提升关键词排名工具
  • 惠州cms建站系统什么是seo
  • 滕州市做网站软文营销推广
  • 网站兼容性测试怎么做培训心得体会2000字
  • wap网站生成小程序巨量引擎app
  • 桂林游漓江长沙seo计费管理
  • 网站建设公司深圳东莞关键词排名优化
  • 如何建设网站挣钱如何做一个网站