基于Langchain的SQL交互Agent
Github链接
代码已开源,点点❤家人们,顶着一堆作业写的QAQ
https://github.com/SYuan03/llm4db
参考链接
官网
- https://python.langchain.com/v0.1/docs/use_cases/sql/
- https://python.langchain.com/v0.1/docs/use_cases/sql/quickstart/
DashScope(阿里云)API
https://dashscope.console.aliyun.com/dashboard
好多地方都用了gpt-3.5-turbo的模型,4o又太贵,所以体验下Qwen的模型,体验额度还挺大的
Process
以下记录几个问题点
处理密码特殊字符
这步有点气人咳咳
了解到密码中含有@等特殊词汇需要使用
1 | from urllib.parse import quote_plus |
然后用了发现还是连不上,OK排查了一番后发现填成服务器密码了QAQ
改了之后终于连好了
StrOutputParser
OutputParser that parses LLMResult into the top likely string.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
demo
1 | db = SQLDatabase.from_uri(uri) |
1 | There are 703 repositories. |
Cool,验证下
想看下用了多少token的,结果好像数据没刷新
NextSteps
只试了下few shot
Prompting strategies
https://python.langchain.com/v0.1/docs/use_cases/sql/prompting/
看了下可以把表结构也一起传下,增强一下,加点描述之类的
Few-shot examples
https://python.langchain.com/v0.1/docs/use_cases/sql/prompting/#few-shot-examples
还可以搞点few shot
补充:StreamForHttps
部署接口在服务器上的时候发现
http://ip:8000/dbchat/stream能正常流式响应
但是经过nginx反向代理的https的https://ip:8001/dbchat/stream没法正常流式响应,直接~~依大托~~出来
之前的nginx配置如下
1 | server { |
关闭缓存后修改如下
1 | server { |
发现解决了问题
致谢
Paying tribute to the legendary software engineering warrior ——SEBugMaker!
And SYuan03 as well. (Ahem, paying tribute to oneself might seem a bit odd)
- 标题: 基于Langchain的SQL交互Agent
- 作者: SYuan03
- 创建于 : 2024-06-09 21:18:29
- 更新于 : 2024-09-30 20:51:50
- 链接: https://bblog.031105.xyz/posts/实践记录/2024-Spring-软工三/基于langchain的sql交互agent.html
- 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。