使用OpenAI ChatGPT 进行了编码尝试

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 笔记

12.pngChatGPT 是一种以类似聊天的方式进行交互的人工智能网络,从名字上看起来像是另一个“聊天机器人”,但实际上已经远超聊天的范畴了,当要求它编写一些代码时,结果相等震撼,它可以写出一些意想不到的连贯代码,而这些代码对于开发者很有启发。

开始要求它使用 JavaScript 编写一个散列(HASH)密码的函数。具体一点就是编写一个 JavaScript 函数,它接受密码的字符串输入并输出散列(HASH)密码。


function hashPassword(password) {
    return crypto.createHash("sha256").update(password).digest("hex");
}

然后逐步提高编码的难度,实现一些更加符合项目开发的需求,于是输入:

编写一个在请求正文中包含用户名和密码的 Express 路由处理程序,对密码进行哈希处理,在 MySQL 数据库中查找现有用户并检查哈希后的密码是否匹配。


const express = require("express");
const bcrypt = require("bcrypt");
const mysql = require("mysql");
// 创建 MySQL 数据库连接
const db = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "mydb",
});
// 连接数据库
db.connect((err) => {
    if (err) {
        throw err;
    }
    console.log("MySQL connected...");
});
// 创建 express app
const app = express();
// 路由 handler
app.post("/login", (req, res) => {
    // get username and password from request body
    const { username, password } = req.body;
    // HASH 密码
    const hashedPassword = bcrypt.hashSync(password, 10);
    // 在数据库中查找用户名称
    let sql = `SELECT * FROM users WHERE username = '${username}'`;
    let query = db.query(sql, (err, result) => {
        if (err) throw err;
        // 检查密码是否匹配
        if (bcrypt.compareSync(result[0].password, hashedPassword)) {
            res.send("Login successful!");
        } else {
            res.send("Incorrect username or password");
        }
    });
});

这段 JavaScript 代码基本是没什么问题的,可以直接复制到项目中进行调试。接下来使用别的语言来试一下:

用C语言编写一个链表结构的代码,具有根据“标识”属性在链表中添加、删除和查找节点的功能。


#include <stdio.h>
#include <stdlib.h>
// Structure for a node in the linked list
typedef struct Node {
    int identity; // Property of the node
    struct Node *next; // Pointer to the next node
} Node;
// Function to add a node to the linked list
void addNode(Node **head, int identity) {
    // Create a new node
    Node *newNode = (Node*)malloc(sizeof(Node));
    // Set the identity of the new node
    newNode->identity = identity;
    // Set the next pointer of the new node to point to the head
    newNode->next = *head;
    // Set the head to point to the new node
    *head = newNode;
}
// Function to delete a node from the linked list
void deleteNode(Node **head, int identity) {
    // Create a temporary node to traverse the linked list
    Node *temp = *head;
    // Check if the head is the node to be deleted
    if (temp != NULL && temp->identity == identity) {
        // Set the head to point to the next node
        *head = temp->next;
        // Free the memory allocated for the node
        free(temp);
        return;
    }
    // Traverse the linked list to find the node to be deleted
    while (temp != NULL && temp->identity != identity) {
        // Set the previous node to the current node
        Node *prev = temp;
        // Set the current node to the next node
        temp = temp->next;
    }
    // Check if the node was found
    if (temp == NULL) return;
    // Set the previous node to point to the next node
    prev->next = temp->next;
    // Free the memory allocated for the node
    free(temp);
}
// Function to find a node in the linked list
Node* findNode(Node *head, int identity) {
    // Create a temporary node to traverse the linked list
    Node *temp = head;
    // Traverse the linked list to find the node
    while (temp != NULL) {
        // Check if the current node has the given identity
        if (temp->identity == identity) {
            return temp;
        }
        // Set the current node to the next node
        temp = temp->next;
    }
    // Return NULL if the node was not found
    return NULL;
}
int main() {
    // Create a head node for the linked list
    Node *head = NULL;
    // Add some nodes to the linked list
    addNode(&head, 1);
    addNode(&head, 2);
    addNode(&head, 3);
    // Find a node in the linked list
    Node *node = findNode(head, 2);
    // Print the identity of the node
    printf("Node with identity 2: %d\n", node->identity);
    // Delete a node from the linked list
    deleteNode(&head, 2);
    // Find the deleted node in the linked list
    node = findNode(head, 2);
    // Check if the node was deleted
    if (node == NULL) {
        printf("Node with identity 2 was deleted\n");
    }
    return 0;
}

于是似乎开始担心未来的程序员,对于AI的机器学习能力,肯定是强于人类的。一个程序员宝贵的职业生涯就算 20 年,就假设这个程序员在职业生涯中相当勤奋好学,可AI应该可以通过学习收集全世界所有程序员的经验!人脑无法与在极其庞大的数据集上训练有素的 AI 模型的计算能力相提并论。未来是不是有可能程序员通过AI把自己这个职业淘汰掉!


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
4月前
|
人工智能 安全
OpenAI:纽约时报黑客攻击了ChatGPT,要求驳回版权诉讼
【2月更文挑战第9天】OpenAI:纽约时报黑客攻击了ChatGPT,要求驳回版权诉讼
58 2
OpenAI:纽约时报黑客攻击了ChatGPT,要求驳回版权诉讼
|
1月前
|
人工智能 测试技术 API
MatGPT - 访问 OpenAI™ ChatGPT API 的 MATLAB® 应用程序
MatGPT - 访问 OpenAI™ ChatGPT API 的 MATLAB® 应用程序
41 0
|
1月前
|
人工智能 搜索推荐 机器人
OpenAI 将向企业开放 GPT-4o 模型定制版,国内怎么使用ChatGPT?
OpenAI新推功能让企业客户能定制GPT-4o模型,通过微调技术满足特定需求和业务场景,以前所未有的方式优化AI投资回报。企业上传自有数据后,可在一到两小时内完成模型定制,如滑板公司打造专业客服聊天机器人解答详细问题,大幅提升服务针对性与客户体验。目前定制限于文本数据,但仍显著增强了企业应用AI的灵活性与效率。
63 2
OpenAI 将向企业开放 GPT-4o 模型定制版,国内怎么使用ChatGPT?
|
1月前
|
人工智能 监控 数据挖掘
普华永道和OpenAI达成合作协议,成为首个ChatGPT Enterprise的转售商
普华永道和OpenAI达成合作协议,成为首个ChatGPT Enterprise的转售商
普华永道和OpenAI达成合作协议,成为首个ChatGPT Enterprise的转售商
|
1月前
|
人工智能 自然语言处理 程序员
使用 go-openai 轻松调用 chatGPT:释放无限创造力!
使用 go-openai 轻松调用 chatGPT:释放无限创造力!
|
2月前
|
人工智能 程序员
ChatGPT无法取代人类程序员! IEEE 35页论文测出困难编码正确率仅为0.66%
【7月更文挑战第20天】IEEE 35页论文揭示ChatGPT在复杂编码任务上的正确率仅0.66%,表明大型语言模型虽能生成语法正确代码,但在逻辑和可读性上不及人类程序员。研究强调AI在深度领域知识与推理上的局限性,提示AI辅助而非替代的角色。[链接:https://ieeexplore.ieee.org/document/10507163]
36 2
|
3月前
|
人工智能 机器人 API
OpenAI发布新AI模型GPT-4o和桌面版ChatGPT
OpenAI发布新AI模型GPT-4o和桌面版ChatGPT
|
3月前
|
人工智能 机器人 API
OpenAI CEO奥特曼向大公司推销ChatGPT企业版,包括一些微软的客户
OpenAI CEO奥特曼向大公司推销ChatGPT企业版,包括一些微软的客户
|
3月前
|
机器学习/深度学习 人工智能
可解释性研究新突破:OpenAI成功训练1600万个特征的自动编码器
【6月更文挑战第13天】OpenAI团队在可解释性研究上取得进展,训练出拥有1600万特征的自动编码器来解析GPT-4。此模型旨在揭示语言模型的工作原理,提高AI透明度。自动编码器从低维度特征空间重建输入数据,研究通过稀疏特征增强可解释性。虽然规模扩大带来解释性提升,但计算资源需求大,且评估指标的全面性仍受质疑。[论文链接](https://cdn.openai.com/papers/sparse-autoencoders.pdf)
57 1
|
4月前
|
JSON Java API
在 Spring Boot 中使用 OpenAI ChatGPT API
在 Spring Boot 中使用 OpenAI ChatGPT API
176 1