ChatGPT 3.5 注册已经不需要手机了,直接邮箱认证就可以,这可真算是好消息,坏消息是 ChatGPT 4 还是要收费。 那么 GPT-3.5 与 GPT-4 区别有多大呢,下面简单测试一下。
以从 TDengine 订阅数据为例,TDengine 算是不太小众的数据库,如果连这个都能搞定,说明GPT 还是蛮厉害的。
GPT-3.5 给出的代码
这个我是直接从OpenAI 获取的答案
from taospy import Client
# 连接到 TDengine 服务器
conn = Client(host='your_tdengine_server_ip', user='your_username', password='your_password', database='your_database')
# 订阅数据回调函数
def callback(data):
print(f'Received data: {data}')
# 订阅数据
with conn.subscribe('your_table_name', callback):
# 在此处可以执行其他任务,让订阅保持活跃
input('Press Enter to stop the subscription...\n')
# 关闭连接
conn.close()
GPT-4 给出的代码
这是从DevChat 简介获取的答案
import taos
import time
# 创建订阅对象
def create_subscribe(conn):
sql = 'select * from test.meters interval(1s)'
print("sql: ", sql)
sub = conn.subscribe(sql, restart=False)
print("sub name:", sub.name())
print("create sub res:", sub.result())
return sub
# 获取订阅对象的值
def get_subscribe_value(sub):
while True:
print("blocked get result.")
sub.consume()
print("result: ", sub.result.current)
time.sleep(1)
# 删除订阅对象
def unsub(sub):
print("unsub")
sub.unsubscribe()
try:
conn = taos.connect(host="TDengine的地址", user="root", password="taosdata", database="test", charset="UTF8")
sub = create_subscribe(conn)
time.sleep(2)
get_subscribe_value(sub)
time.sleep(2)
unsub(sub)
print("End of program!")
except Exception as e:
print(e)
官方示例代码
地址如下: python/#数据订阅文章来源:https://www.toymoban.com/news/detail-771203.html
from taos.tmq import Consumer
import taos
def init_tmq_env(db, topic):
conn = taos.connect()
conn.execute("drop topic if exists {}".format(topic))
conn.execute("drop database if exists {}".format(db))
conn.execute("create database if not exists {} wal_retention_period 3600".format(db))
conn.select_db(db)
conn.execute(
"create stable if not exists stb1 (ts timestamp, c1 int, c2 float, c3 varchar(16)) tags(t1 int, t3 varchar(16))")
conn.execute("create table if not exists tb1 using stb1 tags(1, 't1')")
conn.execute("create table if not exists tb2 using stb1 tags(2, 't2')")
conn.execute("create table if not exists tb3 using stb1 tags(3, 't3')")
conn.execute("create topic if not exists {} as select ts, c1, c2, c3 from stb1".format(topic))
conn.execute("insert into tb1 values (now, 1, 1.0, 'tmq test')")
conn.execute("insert into tb2 values (now, 2, 2.0, 'tmq test')")
conn.execute("insert into tb3 values (now, 3, 3.0, 'tmq test')")
def cleanup(db, topic):
conn = taos.connect()
conn.execute("drop topic if exists {}".format(topic))
conn.execute("drop database if exists {}".format(db))
if __name__ == '__main__':
init_tmq_env("tmq_test", "tmq_test_topic") # init env
consumer = Consumer(
{
"group.id": "tg2",
"td.connect.user": "root",
"td.connect.pass": "taosdata",
"enable.auto.commit": "true",
}
)
consumer.subscribe(["tmq_test_topic"])
try:
while True:
res = consumer.poll(1)
if not res:
break
err = res.error()
if err is not None:
raise err
val = res.value()
for block in val:
print(block.fetchall())
finally:
consumer.unsubscribe()
consumer.close()
cleanup("tmq_test", "tmq_test_topic")
区别有多大呢? 用图片说话
文章来源地址https://www.toymoban.com/news/detail-771203.html
到了这里,关于[AI]ChatGPT4 与 ChatGPT3.5 区别有多大的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!