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

OPC UA遇见chatGPT

     

         最近opc 基金会将召开一个会议,主题是”OPC UA meets IT“。由此可见,工业自动化行业也开始研究和评估chatGPT带来的影响了。

本文谈谈本人对OPC UA 与chatGPT结合的初步实验和思考。

构建OPC UA 信息模型

         chatGPT 的确非常强大了,使用自然语言描述一个设备的信息模型,它能够直接生成该设备的OPC UA 信息模型,并且以OPCUA nodeset2.xml 格式输出:

代码


from openai import OpenAIclient = OpenAI(api_key="sk-xxxxxx",base_url="https://api.chatanywhere.tech/v1"
)completion = client.chat.completions.create(model="gpt-3.5-turbo",messages=[{"role": "system", "content": "creat opc ua information model ,output modeset2 xml format"},{"role": "user", "content": "typename motor ,attributes include current,voltage temperature,power data type float"}],temperature=0.3,
)print(completion.choices[0].message.content)

结果

runfile('E:/yao2024/python2024/chatgptSimple.py', wdir='E:/yao2024/python2024')
```xml
<?xml version="1.0" encoding="UTF-8"?>
<opc:Model xmlns:opc="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><opc:ObjectType NodeId="ns=1;i=1001" BrowseName="MotorType"><opc:DisplayName>Motor</opc:DisplayName><opc:References><opc:Reference ReferenceType="HasProperty" IsForward="false">i=47</opc:Reference><opc:Reference ReferenceType="HasProperty" IsForward="false">i=48</opc:Reference><opc:Reference ReferenceType="HasProperty" IsForward="false">i=49</opc:Reference><opc:Reference ReferenceType="HasProperty" IsForward="false">i=50</opc:Reference></opc:References></opc:ObjectType><opc:Variable NodeId="ns=1;i=47" BrowseName="Current" DataType="Float"><opc:DisplayName>Current</opc:DisplayName></opc:Variable><opc:Variable NodeId="ns=1;i=48" BrowseName="Voltage" DataType="Float"><opc:DisplayName>Voltage</opc:DisplayName></opc:Variable><opc:Variable NodeId="ns=1;i=49" BrowseName="Temperature" DataType="Float"><opc:DisplayName>Temperature</opc:DisplayName></opc:Variable><opc:Variable NodeId="ns=1;i=50" BrowseName="Power" DataType="Float"><opc:DisplayName>Power</opc:DisplayName></opc:Variable>
</opc:Model>

         酷吧?关键是提示要写好。如何生成特定行业的DSL 语言,还需要进一步研究。例如生产线的工艺流程编排。这将极大提升系统设计和维护的工作效率,降低了工程成本。

生成结构化数据

  下面的例子演示如何利用chatGPT按照JSON 模板,构建结构化数据。

程序

import json
import os
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents.mrkl import prompt
os.environ['OPENAI_API_KEY'] ="sk-xxxxxxxx"
os.environ['OPENAI_BASE_URL'] ="https://api.chatanywhere.tech/v1"
def get_template(productClass):#print(productClass)answer = [{"type": "product type","brand": "product brand","manufacture":"product manufacture","color":"color of prodcts","size":"product size"}]return json.dumps(answer)
def device_control(device_id):print(device_id)status=Trueanswer = [{"状态": status}]return json.dumps(answer)
def lang_chain_agent(text):llm = ChatOpenAI(model_name="gpt-3.5-turbo",base_url="https://api.chatanywhere.tech/v1")tools = [Tool(name = "get_template",func=get_template,description="use this tool when you need to get product model tempplate ,To use the tool, you must provide  chinese product class",)]agent = initialize_agent(tools,llm,agent="zero-shot-react-description",agent_kwargs=dict(suffix='Answer should be  json. ' + prompt.SUFFIX), verbose=True,return_intermediate_steps=True)response = agent({"input": text})return response
lang_chain_agent("根据如下数据生成符合模型样板的json 产品数据,  类型 足球 品牌 小少年 制造商 鹰派运动用品公司 颜色 红色 尺寸 12 英寸")

结果

> Entering new AgentExecutor chain...
I need to use the get_template tool to generate the product model template for a football product.
Action: get_template
Action Input: 足球
Observation: [{"type": "product type", "brand": "product brand", "manufacture": "product manufacture", "color": "color of prodcts", "size": "product size"}]
Thought:Now I can fill in the template with the provided data.
Final Answer: {"type": "足球", "brand": "小少年", "manufacture": "鹰派运动用品公司", "color": "红色", "size": "12 英寸"}> Finished chain.

chatGPT 访问OPC UA 服务器

    OPC UA是自动化行业广泛应用的工业标准,我们设想可以在chatGPT Agent 中增加一个OPCUA Client ,用它来获取现场设备的状态,并且实现chatGPT对物理设备的控制。其架构如下:

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Git(8)之分支间同步特定提交
  • c++ Constraints 和 concepts介绍
  • 蓝桥杯算法题:卡片换位
  • WPS二次开发系列:WPS SDK初始化
  • Rustdesk二次编译,新集成AI功能开源Gpt小程序为远程协助助力,全网首发
  • 蓝桥杯刷题-13-子矩阵-二维滑动窗口 ಥ_ಥ
  • LC 226.翻转二叉树
  • 怀俄明探空站数据解算PWV和Tm
  • 什么是软件测试?5分钟带你快速了解!
  • JavaEE初阶-线程3
  • CentOS7:Python版本回退
  • Linux下Qt生成程序崩溃文件
  • 24双非考研哈尔滨工程大学计算机(@程程笔记)
  • hydra九头蛇
  • 海纳斯删除广告位
  • 「译」Node.js Streams 基础
  • 【跃迁之路】【519天】程序员高效学习方法论探索系列(实验阶段276-2018.07.09)...
  • Consul Config 使用Git做版本控制的实现
  • ES6--对象的扩展
  • JAVA并发编程--1.基础概念
  • JAVA多线程机制解析-volatilesynchronized
  • Just for fun——迅速写完快速排序
  • Redux 中间件分析
  • 码农张的Bug人生 - 初来乍到
  • 手写一个CommonJS打包工具(一)
  • 跳前端坑前,先看看这个!!
  • 网页视频流m3u8/ts视频下载
  • 组复制官方翻译九、Group Replication Technical Details
  • ​LeetCode解法汇总2182. 构造限制重复的字符串
  • #QT(TCP网络编程-服务端)
  • (~_~)
  • (2)nginx 安装、启停
  • (2/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (C++二叉树05) 合并二叉树 二叉搜索树中的搜索 验证二叉搜索树
  • (苍穹外卖)day03菜品管理
  • (附源码)springboot宠物管理系统 毕业设计 121654
  • (黑客游戏)HackTheGame1.21 过关攻略
  • (一)WLAN定义和基本架构转
  • (原創) 如何解决make kernel时『clock skew detected』的warning? (OS) (Linux)
  • (转) SpringBoot:使用spring-boot-devtools进行热部署以及不生效的问题解决
  • (转)memcache、redis缓存
  • (转)平衡树
  • *算法训练(leetcode)第四十五天 | 101. 孤岛的总面积、102. 沉没孤岛、103. 水流问题、104. 建造最大岛屿
  • .Net 基于MiniExcel的导入功能接口示例
  • .net 设置默认首页
  • .NET 指南:抽象化实现的基类
  • .NET的微型Web框架 Nancy
  • .NET之C#编程:懒汉模式的终结,单例模式的正确打开方式
  • /etc/apt/sources.list 和 /etc/apt/sources.list.d
  • @NoArgsConstructor和@AllArgsConstructor,@Builder
  • @Transactional 参数详解
  • [ 隧道技术 ] cpolar 工具详解之将内网端口映射到公网
  • []T 还是 []*T, 这是一个问题
  • [51nod1610]路径计数
  • [AI Embedchain] 开始使用 - 全栈