SQLCoder部署和应用

news/2024/11/17 18:44:27/文章来源:https://www.cnblogs.com/informatics/p/18303862

主页

  • 个人微信公众号:密码应用技术实战
  • 个人博客园首页:https://www.cnblogs.com/informatics/

SQLCoder简介

SQLCoder是一个用于生成SQL语句的工具,可以通过输入自然语言描述的需求,生成对应的SQL语句。SQLCoder支持连接数据库,对生成的SQL语句可以直接自动执行,并以图表的形式展示结果。SQLCoder是一个开源项目,可以在GitHub上找到源代码和文档。

SQLCoder部署

SQLCoder可以使用pip安装,也可以从GitHub上下载源代码进行部署。下面以pip安装为例,介绍SQLCoder的部署方法。
注:SQLCoder部署依赖于硬件环境,本文以MacOS M3为例,其他环境可能有所不同。

SQLCoder安装&启动

  1. 安装SQLCoder
CMAKE_ARGS="-DLLAMA_METAL=on" pip install "sqlcoder[llama-cpp]"
  1. 下载模型&启动服务
➜  ~ sqlcoder launch
Downloading the SQLCoder-7b-2 GGUF file. This is a ~5GB file and may take a long time to download. But once it's downloaded, it will be saved on your machine and you won't have to download it again.
sqlcoder-7b-q5_k_m.gguf:  73%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████   
Starting SQLCoder server...
Serving static server...
Press Ctrl+C to exit.
Static folder is /usr/local/lib/python3.11/site-packages/sqlcoder/static
127.0.0.1 - - [15/Jul/2024 15:44:41] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:41] "GET /_next/static/css/321c398b2a784143.css HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:41] "GET /_next/static/chunks/webpack-1657be5a4830bbb9.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/chunks/framework-02223fe42ab9321b.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/chunks/main-d30d248d262e39c4.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/chunks/pages/_app-db0976def6406e5e.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/chunks/238-21e16f207d48d221.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/chunks/pages/index-a1b2fa2d87d27d8d.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/PhIFrR5mo2t2wIFmxfdiU/_buildManifest.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/PhIFrR5mo2t2wIFmxfdiU/_ssgManifest.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /favicon.ico HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/chunks/pages/extract-metadata-2dc614052128d5d3.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Jul/2024 15:44:42] "GET /_next/static/chunks/pages/query-data-0be55b0a48827890.js HTTP/1.1" 200 -
/bin/sh: lspci: command not found
llama_model_loader: loaded meta data with 22 key-value pairs and 291 tensors from /Users/hxy/.defog/sqlcoder-7b-q5_k_m.gguf (version GGUF V3 (latest))
llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
llama_model_loader: - kv   0:                       general.architecture str              = llama
llama_model_loader: - kv   1:                               general.name str              = .
llama_model_loader: - kv   2:                       llama.context_length u32              = 16384
llama_model_loader: - kv   3:                     llama.embedding_length u32              = 4096
llama_model_loader: - kv   4:                          llama.block_count u32              = 32
llama_model_loader: - kv   5:                  llama.feed_forward_length u32              = 11008
llama_model_loader: - kv   6:                 llama.rope.dimension_count u32              = 128
llama_model_loader: - kv   7:                 llama.attention.head_count u32              = 32
llama_model_loader: - kv   8:              llama.attention.head_count_kv u32              = 32
llama_model_loader: - kv   9:     llama.attention.layer_norm_rms_epsilon f32              = 0.000010
llama_model_loader: - kv  10:                       llama.rope.freq_base f32              = 1000000.000000
llama_model_loader: - kv  11:                          general.file_type u32              = 17
llama_model_loader: - kv  12:                       tokenizer.ggml.model str              = llama
llama_model_loader: - kv  13:                      tokenizer.ggml.tokens arr[str,32016]   = ["<unk>", "<s>", "</s>", "<0x00>", "<...
llama_model_loader: - kv  14:                      tokenizer.ggml.scores arr[f32,32016]   = [0.000000, 0.000000, 0.000000, 0.0000...
llama_model_loader: - kv  15:                  tokenizer.ggml.token_type arr[i32,32016]   = [2, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, ...
llama_model_loader: - kv  16:                tokenizer.ggml.bos_token_id u32              = 1
llama_model_loader: - kv  17:                tokenizer.ggml.eos_token_id u32              = 2
llama_model_loader: - kv  18:            tokenizer.ggml.unknown_token_id u32              = 0
llama_model_loader: - kv  19:               tokenizer.ggml.add_bos_token bool             = true
llama_model_loader: - kv  20:               tokenizer.ggml.add_eos_token bool             = false
llama_model_loader: - kv  21:               general.quantization_version u32              = 2
llama_model_loader: - type  f32:   65 tensors
llama_model_loader: - type q5_K:  193 tensors
llama_model_loader: - type q6_K:   33 tensors
llm_load_vocab: special tokens cache size = 259
llm_load_vocab: token to piece cache size = 0.1686 MB
llm_load_print_meta: format           = GGUF V3 (latest)
llm_load_print_meta: arch             = llama
llm_load_print_meta: vocab type       = SPM
llm_load_print_meta: n_vocab          = 32016
llm_load_print_meta: n_merges         = 0
llm_load_print_meta: vocab_only       = 0
llm_load_print_meta: n_ctx_train      = 16384
llm_load_print_meta: n_embd           = 4096
llm_load_print_meta: n_layer          = 32
llm_load_print_meta: n_head           = 32
llm_load_print_meta: n_head_kv        = 32
llm_load_print_meta: n_rot            = 128
llm_load_print_meta: n_swa            = 0
llm_load_print_meta: n_embd_head_k    = 128
llm_load_print_meta: n_embd_head_v    = 128
llm_load_print_meta: n_gqa            = 1
llm_load_print_meta: n_embd_k_gqa     = 4096
llm_load_print_meta: n_embd_v_gqa     = 4096
llm_load_print_meta: f_norm_eps       = 0.0e+00
llm_load_print_meta: f_norm_rms_eps   = 1.0e-05
llm_load_print_meta: f_clamp_kqv      = 0.0e+00
llm_load_print_meta: f_max_alibi_bias = 0.0e+00
llm_load_print_meta: f_logit_scale    = 0.0e+00
llm_load_print_meta: n_ff             = 11008
llm_load_print_meta: n_expert         = 0
llm_load_print_meta: n_expert_used    = 0
llm_load_print_meta: causal attn      = 1
llm_load_print_meta: pooling type     = 0
llm_load_print_meta: rope type        = 0
llm_load_print_meta: rope scaling     = linear
llm_load_print_meta: freq_base_train  = 1000000.0
llm_load_print_meta: freq_scale_train = 1
llm_load_print_meta: n_ctx_orig_yarn  = 16384
llm_load_print_meta: rope_finetuned   = unknown
llm_load_print_meta: ssm_d_conv       = 0
llm_load_print_meta: ssm_d_inner      = 0
llm_load_print_meta: ssm_d_state      = 0
llm_load_print_meta: ssm_dt_rank      = 0
llm_load_print_meta: model type       = 7B
llm_load_print_meta: model ftype      = Q5_K - Medium
llm_load_print_meta: model params     = 6.74 B
llm_load_print_meta: model size       = 4.45 GiB (5.68 BPW)
llm_load_print_meta: general.name     = .
llm_load_print_meta: BOS token        = 1 '<s>'
llm_load_print_meta: EOS token        = 2 '</s>'
llm_load_print_meta: UNK token        = 0 '<unk>'
llm_load_print_meta: LF token         = 13 '<0x0A>'
llm_load_print_meta: max token length = 48
llm_load_tensors: ggml ctx size =    0.14 MiB
llm_load_tensors: offloading 0 repeating layers to GPU
llm_load_tensors: offloaded 0/33 layers to GPU
llm_load_tensors:        CPU buffer size =  4560.96 MiB
..................................................................................................
llama_new_context_with_model: n_ctx      = 4096
llama_new_context_with_model: n_batch    = 512
llama_new_context_with_model: n_ubatch   = 512
llama_new_context_with_model: flash_attn = 0
llama_new_context_with_model: freq_base  = 1000000.0
llama_new_context_with_model: freq_scale = 1
llama_kv_cache_init:        CPU KV buffer size =  2048.00 MiB
llama_new_context_with_model: KV self size  = 2048.00 MiB, K (f16): 1024.00 MiB, V (f16): 1024.00 MiB
llama_new_context_with_model:        CPU  output buffer size =     0.12 MiB
llama_new_context_with_model:        CPU compute buffer size =   296.01 MiB
llama_new_context_with_model: graph nodes  = 1030
llama_new_context_with_model: graph splits = 514
AVX = 0 | AVX_VNNI = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | AVX512_BF16 = 0 | FMA = 0 | NEON = 0 | SVE = 0 | ARM_FMA = 0 | F16C = 0 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 0 |
Model metadata: {'general.quantization_version': '2', 'tokenizer.ggml.add_eos_token': 'false', 'tokenizer.ggml.add_bos_token': 'true', 'tokenizer.ggml.unknown_token_id': '0', 'tokenizer.ggml.eos_token_id': '2', 'tokenizer.ggml.bos_token_id': '1', 'tokenizer.ggml.model': 'llama', 'llama.attention.head_count_kv': '32', 'llama.context_length': '16384', 'llama.attention.head_count': '32', 'llama.rope.freq_base': '1000000.000000', 'llama.rope.dimension_count': '128', 'general.file_type': '17', 'llama.feed_forward_length': '11008', 'llama.embedding_length': '4096', 'llama.block_count': '32', 'general.architecture': 'llama', 'llama.attention.layer_norm_rms_epsilon': '0.000010', 'general.name': '.'}
Using fallback chat format: llama-2
INFO:     Started server process [51187]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://localhost:1235 (Press CTRL+C to quit)         

使用SQLCoder

SQLCoder支持多种数据库类型,下面以PostgreSQL为例,介绍SQLCoder的使用方法。
注:在使用SQLCoder之前,需确保已经安装了PostgreSQL数据库,并且数据库服务已经启动。

初始化PostgreSQL测试数据

安装PostgreSQL

以下是在MacOS上安装PostgreSQL的方法,其他系统可能有所不同。

  1. 安装PostgreSQL
 brew install postgresql@15
  1. 启动PostgreSQL服务
brew services start postgresql@15
  1. 安装PostgreSQL命令行客户端
brew install libpq
  1. 创建用户和数据库
# 创建用户
➜ createuser --interactive --pwprompt输入要增加的角色名称: root
为新角色输入的口令:
再输入一遍:
新的角色是否是超级用户? (y/n) y# 创建数据库
➜ createdb test# 连接数据库
➜  psql -U root -d test
psql (16.3, server 15.7 (Homebrew))
Type "help" for help.test=#

初始化测试数据

# 创建表
test=# CREATE TABLE myuser (
test(#     username VARCHAR(50),
test(#     password VARCHAR(50),
test(#     age INT,
test(#     email VARCHAR(100)
test(# );
test=# INSERT INTO myuser (username, password, age, email)
test-# VALUES ('JohnDoe', 'password123', 25, 'johndoe@example.com');
INSERT 0 1
test=#
test=# INSERT INTO myuser (username, password, age, email)
test-# VALUES ('JaneSmith', 'pass456', 30, 'janesmith@example.com');
INSERT 0 1test=# CREATE TABLE myphone (
test(#     username VARCHAR(50),
test(#     type VARCHAR(50),
test(#     price DECIMAL(10, 2)
test(# );
CREATE TABLE
test=#
test=# INSERT INTO myphone (username, type, price)
test-# VALUES ('JohnDoe', 'iPhone', 999.99),
test-#        ('JohnDoe', 'Samsung', 799.99),
test-#        ('JohnDoe', 'Google Pixel', 699.99),
test-#        ('JaneSmith', 'iPhone', 999.99),
test-#        ('JaneSmith', 'OnePlus', 699.99),
test-#        ('JaneSmith', 'Xiaomi', 499.99);
INSERT 0 6test=# \dtList of relationsSchema |  Name   | Type  | Owner
--------+---------+-------+-------public | myphone | table | rootpublic | myuser  | table | root
(2 rows)

打开SQLCoder前端页面

  1. 打开浏览器,输入URL:http://localhost:8002,如果SQLCoder部署成功的话,会显示如下页面:

image

  1. 录入数据库连接信息,并加载测试表Schema

image

  1. 输入需求,生成SQL语句,并查看结果(表格形式)
    image

  2. 查看结果(图表展示)
    image

总结

SQLCoder是一个用于生成SQL语句的工具,本文介绍了SQLCoder的部署方法和使用方法。希望本文对大家有所帮助。

参考文献

  • [1] SQLCoder: https://github.com/defog-ai/sqlcoder

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/744269.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

NOIP 十三连测 #2 补题

逆天输出文件 .ans reverse 水题,随便自己造两组数据都能看出规律: \[\begin{cases}a_n a_{n - 2} \dots a_1 + a_2 a_4 \dots a_{n - 1}(n \mod 2 = 1) \\ a_n a_{n - 2} \dots a_2 + a_1 a_3 \dots a_{n - 1 } (n \mod 2 = 0)\end{cases} \]logistics 先求出最小生成树的 \…

MySQL时间戳转成日期格式

将时间戳转换为日期格式:-- 如果时间戳为毫秒级长度为13位,需要先除以1000 SELECT id, `task_name` ,FROM_UNIXTIME(`task_register_begin_time`/1000,%Y-%m-%d %H:%i:%s) as task_register_begin_time,FROM_UNIXTIME(`task_register_end_time`/1000,%Y-%m-%d %H:%i:%s) as t…

使用GSAP制作动画视频

GSAP 3Blue1Brown给我留下了深刻印象。利用动画制作视频,内容简洁,演示清晰。前两天刚好碰到一件事,我就顺便学习了一下怎么用代码做动画。 以javascrip为例,有两个动画引擎,GSAP和Animajs。由于网速的原因,询问了GPT后,我选择了GSAP来制作我的第一个动画视频。 制作动画…

log4cpp的安装及使用

介绍开源库log4cpp的安装及使用目录前言安装使用示例代码配置文件编译链接输出 前言 本文的操作均在ubuntu20.04下进行 安装 本文仅介绍从源码编译安装log4cpp的过程。 ①在开始编译前,首先要确保系统中安装了g++,make,autoconf和libtool ②下载log4cpp源码 下载log4cpp的特…

Intellij springboot远程调试

服务器端配置: java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:5005 XXXX.jar 说明: address:IP:端口;*代表所有IP地址都可访问,5005需要可IDEA远程请求的端口一致 XXXX.jar:你的springboot程序 IDEA端配置:

采购订单列表根据多条件设置单元格背景色

bos配置: 如果值存在空字符串和空格,空格会标红,为空不会。因此单独针对空字符串标红。 测试效果:

面试准备【LLM】

目录其他注意力过拟合的表现有哪些?BN 训练和测试的区别在哪里?梯度下降的公式?反向传播优化器 & Adam均方误差损失交叉熵损失梯度消失问题梯度爆炸问题权重正则化过拟合分词器BERT掩码语言建模 (MLM)下一个句子预测 Next Sentence Prediction(NSP)BERT微调BERT模型创新…

帝国CMS网站为什么发布时间比实际时间相差8个小时?

你的php设置的时间有问题,是美国的时间。有以下两种方法可解决:1、修改php.ini,找到:date.timezone,把前面的分号去掉,并把值设为PRC2、修改e/class/config.php文件,把://@date_default_timezone_set("PRC");前面的//去掉即可本文来自博客园,作者:黄文Rex,…

易优CMS英文名称设置与调用标签

{$field.englist_name}本文来自博客园,作者:黄文Rex,转载请注明原文链接:https://www.cnblogs.com/hwrex/p/18303796

访问站点时出现:“/templets/default/index.htm Not Found!

错误记录: 访问站点时出现:“/templets/default/index.htm Not Found! 错误原因: 原因是程序调用的默认首页模板不存在, 解决方案: 请检查templets目录下是否存在报错中的default模板目录,或检查default目录下是否有index.htm文件,若有问题,请联系程序开发商核实并重新上传…

Apache服务器上的No input file specified错误

错误提示: Apache服务器上的No input file specified错误 解决方案: 在根目录下找到php5.ini文件(如果找不到就建立一个),在里面加上如下内容 cgi.fix_pathinfo = 1本文来自博客园,作者:黄文Rex,转载请注明原文链接:https://www.cnblogs.com/hwrex/p/18303797

帝国CMS网站如何单独制作投稿页面,不用系统默认的

做个HTML表单,表单含原信息投稿的字段变量(含classid/id/enews/字段等变量)即可,且表单的action指向/e/DoInfo/ecms.php就可以(action="/e/DoInfo/ecms.php")。本文来自博客园,作者:黄文Rex,转载请注明原文链接:https://www.cnblogs.com/hwrex/p/18303773