rag系列文章目录
文章目录
- rag系列文章目录
- 前言
- 一、openwebui介绍
- 二、配置prompt模板
- 三、测试输出
- 总结
前言
大模型时代,人人都在使用大模型进行提效,对程序员而言,尤其如此,不提高自己的开发效率,就会有被取代失业的危险。本文介绍基于openwebui如何进行开发提效,解放自己繁琐的开发任务。
一、openwebui介绍
Open WebUI 是一个功能强大、可扩展的开源 Web 界面,专为本地和云端的大型语言模型(LLM)设计,提供类似 ChatGPT 的用户体验。以下是它的核心功能:
- 直观的用户界面
仿照 ChatGPT 设计,提供流畅的交互体验。
响应式设计,适配桌面和移动设备。
代码高亮,支持 Markdown 和 LaTeX 渲染,便于技术文档和数学公式展示。 - 多模型支持
兼容 Ollama、OpenAI API 及其他兼容 API(如 LM Studio、Mistral 等)。
支持 多模型并行对话,可同时与多个 LLM 交互并比较结果。
提供 模型竞技场(Model Arena),让用户对不同模型的表现进行评分。 - 检索增强生成(RAG)
支持 本地 RAG 集成,可上传文档(PDF、Word、TXT 等)作为知识库,AI 回答时会参考这些内容。
支持 网页浏览,通过 #URL 命令直接抓取网页内容进行分析。
二、配置prompt模板
配置prompt模板,主要是为了重复高效使用优秀的prompt示例,这些prompt示例是用户长时间调试好的,主要有特点是,能够针对客户特定问题输出结构化的容易理解的结果。
大家可以根据自己的场景进行调整修改,以满足自己的需要为准。这里以让大模型数据springboot工程里面mybatis的增删改查为例,写的prompt如下:
你是一个springboot工程代码专家,基于建表语句生成操作数据库的相关工程文件。你需要根据一个建表语句生成3个文件,分别是Po类文件,Mapper文件,Mapper xml文件。输出格式如下:
==============Po文件===================
主要基于建表语句生成,Po类里面的字段需要参考建表语句的字段,类型需要对应正确。
==============Mapper文件===============
主要基于建表语句生成增删改查接口,查询字段如果含有id,需要含有根据id查询的接口,如果含有name,需要根据name进行模糊查询。插入接口包含两个,单条插入和批量插入。
==============Mapper xml文件============
这里主要基于上面的Mapper接口文件,生成mapper xml文件,实现上面的接口,sql语句使用postgres sql。样例输入如下:
CREATE TABLE IF NOT EXISTS pg_conversation(id BIGSERIAL PRIMARY KEY,agent_id bigint,user_id bigint NOT NULL,conversation_name text,create_time timestamp,update_time timestamp);COMMENT ON TABLE "pg_conversation" IS '会话信息表';COMMENT ON COLUMN "pg_conversation".id IS '主键';COMMENT ON COLUMN "pg_conversation".agent_id IS 'agent ID';COMMENT ON COLUMN "pg_conversation".user_id IS '用户ID';COMMENT ON COLUMN "pg_conversation".conversation_name IS '会话名称';COMMENT ON COLUMN "pg_conversation".create_time IS '创建时间';COMMENT ON COLUMN "pg_conversation".update_time IS '更新时间';
样例输出如下:
==============Po文件===================
@Data
@Table(name = "pg_conversation")
public class PgConversationPo {@Idprivate Long id;private Long agentId;private Long userId;private String conversationName;private Date createTime;private Date updateTime;
}
==============Mapper文件===============
public interface PgConversationMapper {List<PgConversationPo> queryPos(@Param("conversationName") String conversationName);int insertPo(PgConversationPo po);int deletePo(@Param("id") Long id);int updatePo(PgConversationPo po);
}
==============Mapper xml文件============
<mapper namespace="com.test.dao.mapper.PgConversationMapper"><resultMap id="PgConversationPoResultMap" type="com.test.po.PgConversationPo"><id property="id" column="id"/><result property="agentId" column="agent_id"/><result property="userId" column="user_id"/><result property="conversationName" column="conversation_name"/><result property="createTime" column="create_time"/><result property="updateTime" column="update_time"/></resultMap><select id="queryPos" resultMap="PgConversationPoResultMap">select *from pg_conversationwhere <if test=" conversationName != null and conversationName != '' ">and conversation_name like concat('%',#{conversationName},'%')</if>order bycreate_time desc</select><insert id="insertPo">INSERT INTO pg_conversation (agent_id, user_id, conversation_name, create_time, update_time)VALUES (#{agentId}, #{userId}, #{conversationName}, #{createTime}, #{updateTime})</insert><update id="updatePo">UPDATE pg_conversationSET conversation_name = #{conversationName}WHERE id = #{id}</update><delete id="deletePo">DELETE FROM pg_conversationWHERE id = #{id}</delete>
</mapper>postgres sql建表语句如下:{{CLIPBOARD}}
请开始生成
三、测试输出
Openwebui具有操作简单的特性,复制你需要生成的sql语句,然后在问答会话窗口,输入/mapper(自己配置的模板名称),然后输入tab健,就会把你的复制内容放到变量{{CLIPBOARD}}里面,然后点击问答即可,看到大模型输出效果。
输出结果如下:
@Data
@Table(name = "pg_user")
public class PgUserPo {@Idprivate Long id;private String userId;private String userName;private Date createTime;private Date updateTime;
}
public interface PgUserMapper {List<PgUserPo> queryByUserName(@Param("userName") String userName);PgUserPo queryById(@Param("id") Long id);PgUserPo queryByUserId(@Param("userId") String userId);int insertPo(PgUserPo po);int batchInsertPos(@Param("pos") List<PgUserPo> pos);int deletePo(@Param("id") Long id);int updatePo(PgUserPo po);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.example.mapper.PgUserMapper"><resultMap id="PgUserPoResultMap" type="com.example.po.PgUserPo"><id property="id" column="id" /><result property="userId" column="user_id" /><result property="userName" column="user_name" /><result property="createTime" column="create_time" /><result property="updateTime" column="update_time" /></resultMap><select id="queryByUserName" resultMap="PgUserPoResultMap">SELECT *FROM pg_userWHERE <if test="userName != null and userName != ''">user_name LIKE concat('%',#{userName},'%')</if>ORDER BY create_time DESC</select><select id="queryById" resultMap="PgUserPoResultMap">SELECT *FROM pg_userWHERE id = #{id}</select><select id="queryByUserId" resultMap="PgUserPoResultMap">SELECT *FROM pg_userWHERE user_id = #{userId}</select><insert id="insertPo">INSERT INTO pg_user (user_id, user_name, create_time, update_time)VALUES (#{userId}, #{userName}, #{createTime}, #{updateTime})</insert><insert id="batchInsertPos">INSERT INTO pg_user (user_id, user_name, create_time, update_time)VALUES <foreach collection="pos" item="po" separator=",">(#{po.userId}, #{po.userName}, #{po.createTime}, #{po.updateTime})</foreach></insert><update id="updatePo">UPDATE pg_userSET user_id = #{userId},user_name = #{userName},create_time = #{createTime},update_time = #{updateTime}WHERE id = #{id}</update><delete id="deletePo">DELETE FROM pg_userWHERE id = #{id}</delete></mapper>
总结
本文介绍了使用openwebui来帮助程序员减少重复冗余的开发任务,除了开发工程中CURD任务之外,只要细心发现,还有很多可以来帮助程序员节省时间的功能,比如格式化输出接口文档,mysql sql语句转换为postgres sql语句等等,这些都可以写prompt模板做成一个agent,在需要的时候,帮助自己提升开发效率。