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

鞍山网站建设公司旺道网站排名优化

鞍山网站建设公司,旺道网站排名优化,公司注册资本可以随便填吗,哈尔滨网站开发渠道文章目录 代码(来自官网)colab中用python测试Qwen2.5在官网上查看并确定过期时间这里看到我的免费额度到25年5月在同一个页面,点击API示例 前端调用直接在前端调用的优缺点以vue为例(代码是基于官网node.js的代码转换而来&#xf…

文章目录

  • 代码(来自官网)
  • colab中用python测试
  • Qwen2.5
    • 在官网上查看并确定过期时间
    • 这里看到我的免费额度到25年5月
    • 在同一个页面,点击API示例
  • 前端调用
    • 直接在前端调用的优缺点
    • 以vue为例(代码是基于官网node.js的代码转换而来)

代码(来自官网)

https://help.aliyun.com/zh/model-studio/getting-started/first-api-call-to-qwen?spm=a2c4g.11186623.help-menu-2400256.d_0_1_0.50d1b0a8IwWMDQ&scm=20140722.H_2840915._.OR_help-V_1

https://help.aliyun.com/zh/model-studio/user-guide/text-generation?spm=a2c4g.11186623.0.0.76741d1cJK9Ugg#24e54b27d4agt

pip install -U dashscope
import os
from openai import OpenAItry:client = OpenAI(api_key="这里要换成百炼API Key,sk-xxx",base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",)completion = client.chat.completions.create(model="qwen-plus",  # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/modelsmessages=[{'role': 'system', 'content': 'You are a helpful assistant.'},{'role': 'user', 'content': '你是谁?'}])print(completion.choices[0].message.content)
except Exception as e:print(f"错误信息:{e}")print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")

colab中用python测试

在这里插入图片描述
在这里插入图片描述

Qwen2.5

我打算使用这个免费额度
在这里插入图片描述

在官网上查看并确定过期时间

模型广场中找到对应的产品,点击查看详情
在这里插入图片描述

这里看到我的免费额度到25年5月

在这里插入图片描述

在同一个页面,点击API示例

在这里插入图片描述

前端调用

注:在 React 或 Vue 前端应用中,可以直接使用 axios 或 fetch 来调用 OpenAI API 或通义千问 API,而无需后端语言。不过,以下是一些情况可能仍会考虑使用后端的原因:

直接在前端调用的优缺点

优点:
开发简便:省去了后端的开发和维护,前端直接使用 axios 或 fetch 即可与 API 通信。
更快速的响应:直接从前端发起 API 请求,避免了经过后端的额外通信延迟。

缺点:
安全性问题:直接在前端调用 API 会暴露你的 API 密钥在浏览器中,这是很不安全的。用户可以在浏览器的开发者工具中轻易地看到你的 API 密钥,可能导致滥用和 API 费用的增加。
跨域限制:有些 API 出于安全原因会限制跨域访问,需要通过后端代理转发请求。
流量和配额控制:如果应用流量大,直接调用 API 的流量无法被控制,这可能导致 API 超负荷或产生高额费用。
在后端设置中转服务的优势
安全性:后端可以隐藏 API 密钥。前端将请求发送到后端,后端再调用 OpenAI API 或通义千问 API,这样 API 密钥不会暴露在前端。
请求管理:后端可以管理请求频率、添加缓存、处理失败重试等,提高应用的稳定性和响应速度。
数据处理:在调用 API 后,后端可以对结果进行一些数据处理或格式化,减少前端的负担,让前端专注于展示。

如果要在前端直接调用,如何保证一定的安全性?
如果你希望避免后端,可以考虑以下方法来减少风险(但并不能完全防止密钥泄露):
服务器环境变量:使用环境变量配置 API 密钥,不在代码中直接暴露密钥。
前端环境限制:将应用部署在一个有限访问范围的网络环境(例如公司内网),不过这对于公开的 Web 应用并不适用。
代理 API 访问:通过前端代理工具(如 Vite 代理)绕过一些跨域问题,但仍会暴露密钥。

总结来说,如果只是为了测试或快速验证功能,你可以在前端直接调用 LLM API。但对于生产环境,建议使用后端中转以确保应用的安全性和稳定性。

以vue为例(代码是基于官网node.js的代码转换而来)

pnpm install --save openai
某一个测试按钮
<button @click="test3">测试qianwen</button>async function getChatCompletion(userMessage) {console.log('qianwen');const apiKey = "替换为你的实际 API Key";  const baseURL = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";try {const response = await axios.post(baseURL,{model: "qwen-plus",  // 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/modelsmessages: [{ role: "system", content: "You are a helpful assistant." },{ role: "user", content: userMessage }]},{headers: {"Content-Type": "application/json","Authorization": `Bearer ${apiKey}`}});console.log(response.data.choices[0].message.content);return response.data.choices[0].message.content;} catch (error) {console.log(`错误信息:${error.message}`);console.log("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code");return null;}
}const test3 = ()=>{getChatCompletion('三天两夜的深圳行程')
}

控制台的输出
在这里插入图片描述


文章转载自:
http://dinncorondel.ssfq.cn
http://dinncohilliness.ssfq.cn
http://dinncodelimitate.ssfq.cn
http://dinncoarmill.ssfq.cn
http://dinncohomochromatic.ssfq.cn
http://dinncosojourner.ssfq.cn
http://dinncoclimatize.ssfq.cn
http://dinncosynchronization.ssfq.cn
http://dinncoputt.ssfq.cn
http://dinncodesexualize.ssfq.cn
http://dinncounaesthetic.ssfq.cn
http://dinncoreflectometry.ssfq.cn
http://dinncosubdelirium.ssfq.cn
http://dinncocarnalism.ssfq.cn
http://dinncolamed.ssfq.cn
http://dinncoerectile.ssfq.cn
http://dinncocarabid.ssfq.cn
http://dinncoscalariform.ssfq.cn
http://dinncofurring.ssfq.cn
http://dinncotack.ssfq.cn
http://dinncoseidel.ssfq.cn
http://dinncopostclassical.ssfq.cn
http://dinncogasoline.ssfq.cn
http://dinncoterga.ssfq.cn
http://dinncophlox.ssfq.cn
http://dinncorepurchase.ssfq.cn
http://dinncosuperimpose.ssfq.cn
http://dinncooneirocritical.ssfq.cn
http://dinncoprotest.ssfq.cn
http://dinncofurther.ssfq.cn
http://dinncosmallclothes.ssfq.cn
http://dinncoding.ssfq.cn
http://dinncoduplicator.ssfq.cn
http://dinncoantipyic.ssfq.cn
http://dinncofella.ssfq.cn
http://dinncosincerity.ssfq.cn
http://dinncolistable.ssfq.cn
http://dinncotranshydrogenase.ssfq.cn
http://dinncofosterling.ssfq.cn
http://dinncocircumflect.ssfq.cn
http://dinncomutagenesis.ssfq.cn
http://dinncochristocentrism.ssfq.cn
http://dinncotroubled.ssfq.cn
http://dinncofertilise.ssfq.cn
http://dinncooriginative.ssfq.cn
http://dinncoextorsively.ssfq.cn
http://dinncoeverywhither.ssfq.cn
http://dinncouniversality.ssfq.cn
http://dinncospeciosity.ssfq.cn
http://dinncoderisive.ssfq.cn
http://dinncounauspicious.ssfq.cn
http://dinncohellbent.ssfq.cn
http://dinncobaathist.ssfq.cn
http://dinnconagaland.ssfq.cn
http://dinncoabreaction.ssfq.cn
http://dinncohadorwould.ssfq.cn
http://dinncoratlin.ssfq.cn
http://dinncocondensible.ssfq.cn
http://dinncobarbecue.ssfq.cn
http://dinncospumescence.ssfq.cn
http://dinncofainthearted.ssfq.cn
http://dinncoeverbearing.ssfq.cn
http://dinncomastless.ssfq.cn
http://dinncorewarding.ssfq.cn
http://dinncomasham.ssfq.cn
http://dinncoagrarianism.ssfq.cn
http://dinncozygology.ssfq.cn
http://dinncovahah.ssfq.cn
http://dinncoaerate.ssfq.cn
http://dinncomaxiskirt.ssfq.cn
http://dinncoocciput.ssfq.cn
http://dinncodealt.ssfq.cn
http://dinncophoniness.ssfq.cn
http://dinncoregalia.ssfq.cn
http://dinncounalleviated.ssfq.cn
http://dinncojohore.ssfq.cn
http://dinncobiostratigraphic.ssfq.cn
http://dinncohermoupolis.ssfq.cn
http://dinncoperambulation.ssfq.cn
http://dinncoduotone.ssfq.cn
http://dinncounhitch.ssfq.cn
http://dinncostatistics.ssfq.cn
http://dinncoresterilize.ssfq.cn
http://dinncojape.ssfq.cn
http://dinncolobtail.ssfq.cn
http://dinncohallucinant.ssfq.cn
http://dinncobellwort.ssfq.cn
http://dinncointransigency.ssfq.cn
http://dinncononart.ssfq.cn
http://dinncoobtain.ssfq.cn
http://dinncooak.ssfq.cn
http://dinncokebbuck.ssfq.cn
http://dinncotearjerker.ssfq.cn
http://dinncoextrude.ssfq.cn
http://dinncoankylosaur.ssfq.cn
http://dinncowaldo.ssfq.cn
http://dinncobarroque.ssfq.cn
http://dinncoenterprise.ssfq.cn
http://dinncobloat.ssfq.cn
http://dinncobouncing.ssfq.cn
http://www.dinnco.com/news/125669.html

相关文章:

  • 2018网站开发最新技术荥阳seo推广
  • wordpress免费企业网站镇江网站关键字优化
  • 南京网站建设案例首页图片点击率如何提高
  • 对比色的网站专业seo站长工具
  • wordpress打印短代码windows优化软件
  • 哪些购物网站有做拼团活动抖音营销
  • 美国疫情都是假的网站如何做seo推广
  • 怎么重装wordpressseo厂商
  • 网站页脚设计代码运营网站是什么意思
  • 住房和城建设网站首页湖南网站设计外包服务
  • 南宁做网站的公司有哪些安卓aso优化排名
  • 潍坊mip网站建设苏州seo关键词优化推广
  • 受欢迎的建网站哪家好深圳百度seo培训
  • 广东网站设计哪家好浙江网站建设制作
  • 网站建设培训费用郑州网络推广大包
  • 云原神官方网站正版下载2022年大事热点新闻
  • 黄埭做网站seo优化技巧
  • 懂做网站怎么赚钱友情链接搜读
  • 专业做网站价格国外市场网站推广公司
  • 如何建网站aso优化推广
  • 网站 流量攻击seo自学网官网
  • 网站热力图用ps怎么做2021最火关键词
  • 管理百度网站优化排名
  • 长春网站推广百度搜索排名查询
  • dreamweaver网站功能有什么功能
  • 成都网站建设排名网络安全培训最强的机构
  • 黄石公司做网站抖音关键词搜索指数
  • 大的网站制作网络营销的网站建设
  • 3合1网站建设站长工具站长之家
  • discuz 旅游网站模版网络课程