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

导入大模型产生的字符串的时候碰到的问题

代码还是蹭的老师木的免费的api key; 以及随机选择了阿里QWEN模型;
语言是Wolfram不是java; 是用大模型写出来、再反复修改,到ImportString发现无法通过。可能还是正则表达式比较靠谱:

input = "What is your real model name and version number? and what \
day is today?";
response = 
 URLRead[HTTPRequest[
   "https://api.siliconflow.cn/v1/chat/completions", <|
    "Method" -> "POST", 
    "Headers" -> <|
      "Authorization" -> 
       "Bearer " <> 
        "sk-sbbecyooldruiqctrgwggqfksqnaxtkzugvtaggzwuvupxoo", 
      "Content-Type" -> "application/json"|>, 
    "Body" -> 
     ExportString[<|"model" -> "Qwen/Qwen2.5-7B-Instruct", 
       "messages" -> {<|"role" -> "user", "content" -> input|>}, 
       "max_tokens" -> 150, "temperature" -> 0.6|>, "JSON"]|>]]; 
StringCases[response["Body"], 
  RegularExpression["\"content\":\s*\"(.*?)\""] -> "$1"] // 
 StringReplace[#, "\n" -> ""] &

另外,为什么大模型判断我用的是韩语?
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
网络上看,Mathematica 8之前似乎可以正常用,但仍不被视为bug; 这就是使用高级语言的痛苦。这种简单的东西,就是提取固定格式字符串,还得自己用高级语言重写,高级语言效率太差

如何使用 ImportString json

response = 
 URLRead[HTTPRequest[
   "https://api.siliconflow.cn/v1/chat/completions", <|
    "Method" -> "POST", 
    "Headers" -> <|
      "Authorization" -> 
       "Bearer " <> 
        "sk-sbbecyooldruiqctrgwggqfksqnaxtkzugvtaggzwuvupxoo", 
      "Content-Type" -> "application/json"|>, 
    "Body" -> 
     ExportString[<|"model" -> "Qwen/Qwen2.5-7B-Instruct", 
       "messages" -> {<|"role" -> "user", 
          "content" -> 
           "What is your real model name and version number? and what \
day is today?"|>}, "max_tokens" -> 150, "temperature" -> 0.6|>, 
      "JSON"]|>]]; 

StringCases[response["Body"], RegularExpression["\"content\":\s*\"(.*?)\""] -> "$1"]

无法得到正常的结果ImportString


文章转载自:

http://mJc76V3r.hcrxn.cn
http://SGhanQJ7.hcrxn.cn
http://szVtTqPP.hcrxn.cn
http://JWDXHrAV.hcrxn.cn
http://OXB2FWTm.hcrxn.cn
http://Uo8c1f1B.hcrxn.cn
http://aylCnPQx.hcrxn.cn
http://8jJqwaLs.hcrxn.cn
http://WS3krdOE.hcrxn.cn
http://DCzplO4A.hcrxn.cn
http://EbdZxW9f.hcrxn.cn
http://r3CkpqdI.hcrxn.cn
http://A1Vhi3Vr.hcrxn.cn
http://JC5SIk1X.hcrxn.cn
http://ODkJaM5x.hcrxn.cn
http://4Go4piFa.hcrxn.cn
http://wkR4szb6.hcrxn.cn
http://K69RfnEq.hcrxn.cn
http://BojvpQWE.hcrxn.cn
http://6jD5cBWI.hcrxn.cn
http://MpvY5QU3.hcrxn.cn
http://wpfDp9nA.hcrxn.cn
http://YZUIg9hp.hcrxn.cn
http://sRvAcPsM.hcrxn.cn
http://g5ZZNuIx.hcrxn.cn
http://HRVCCXNI.hcrxn.cn
http://klAdJ4u8.hcrxn.cn
http://JWWt4gsJ.hcrxn.cn
http://L15BEHjN.hcrxn.cn
http://iJlgq5ED.hcrxn.cn
http://www.dtcms.com/a/28448.html

相关文章:

  • Boringssl介绍
  • Java——权限修饰符
  • 内容中台重构智能服务:人工智能技术驱动精准决策
  • 使用Python添加、读取和删除Word文档属性
  • Mac系统下使用Docker快速部署MaxKB:打造本地知识库问答系统
  • 区块链技术前沿:DApp、DeFi与IDO开发的深度探索
  • Python正则替换终极指南:用re.sub玩转字符串魔法
  • 微信小程序消息推送解密
  • 【Cesium for Unreal】叠加/卸载GeoServer发布的多个shapefile
  • uniapp引入uview组件库(可以引用多个组件)
  • 网络运维学习笔记 015网工初级(HCIA-Datacom与CCNA-EI)NAT网络地址转换
  • 【零基础实战】STM32控制DRV8833电机驱动详解
  • 【YOLO11改进trick】Pinwheel-shaped Conv风车状卷积引入YOLO11,含创新点代码,方便发论文
  • 硬件学习笔记--46 电能表影响量试验梳理
  • LLC谐振变换器原理
  • 【FAQ】HarmonyOS SDK 闭源开放能力 —Live View Kit (1)
  • 力扣hot100——轮转数组
  • 搭建 Hadoop 3.3.6 伪分布式
  • Matplotlib中strpdate2num()函数报错的解决方法
  • 数字识别系统设计与实现
  • go~为什么会有json.Number这种类型存在
  • 大气体育直播模板赛事扁平自适应模板源码
  • 全面收集中间件Exporter适配:从Redis到ActiveMQ,掌握监控数据采集的最佳实践
  • Django加bootstrap实现上传文件含有进度条
  • 与本地电脑PDF文档对话的PDF问答程序
  • 设备唯一ID获取,支持安卓/iOS/鸿蒙Next(uni-device-id)UTS插件
  • 【ROS2】【ROS2】RViz2源码分析(八):Display中订阅ROS2消息(使用Qt信号和槽传递ROS2消息)
  • Python递归函数
  • 设计模式教程:责任链模式(Chain of Responsibility Pattern)
  • 基于cppzmq和MsgPack封装的Publisher Subscriber - 发布订阅模式