当前位置: 首页 > news >正文

问题解决:Problem exceeding maximum token in azure openai (with java)

问题背景:

I'm doing a chat that returns queries based on the question you ask it in reference to a specific database. For this I use azure openai and Java in Spring Boot.

我正在开发一个聊天功能,该功能根据您针对特定数据库的提问返回查询结果。为此,我使用了Azure OpenAI和Spring Boot中的Java。

My problem comes here:

How can I make the AI remember the previous questions without passing the context back to it (what I want to do is greatly reduce the consumption of tokens, since depending on what it asks, if the question contains a keyword, for example 'users', what I do is pass in the context the information in this table that is huge (name of the fields, type of data and description) so when you have several questions the use of tokens rises to more than 10,000))

我如何能让AI记住之前的问题,而不需要将上下文再次传递给它(我想做的是大大减少令牌的消耗,因为根据AI提出的问题,如果问题中包含一个关键字,例如“用户”,我会在上下文中传递这个巨大表格的信息(字段名、数据类型和描述),所以当你有多个问题时,令牌的使用量会上升到超过10,000个))

I can't show all the code since it's a project for my company.

由于这是我们公司的一个项目,我不能展示所有的代码。

What im currently doing is adding to the context the referenced table and the principal context(you are a based SQL chat...). And for the chat to remember, I have tried to save the history in java and pass the context history again(but this exceed the tokens pretty fast)

我目前所做的是向上下文中添加引用的表格和主要上下文(例如“您是一个基于SQL的聊天...”)。为了让聊天能够记住之前的对话,我试图在Java中保存历史记录并再次传递上下文历史(但这很快就会超过令牌限制)。

This is what I'm currently doing (no remembering from the AI):

这是我现在的做法(AI不会记住之前的对话)

chatMessages.add(new ChatMessage(ChatRole.SYSTEM, context));chatMessages.add(new ChatMessage(ChatRole.USER, question));ChatCompletions chatCompletions = client.getChatCompletions(deploymentOrModelId, new ChatCompletionsOptions(chatMessages));

问题解决:

As far as I know, there is no way to make the LLM (Azure OpenAI in this case) remember your context cheaply, as you said, sending context (and a huge chunk of it) on each call gets pricy really fast. That been said, you could change the approach and try other techniques to mimic that the AI has memory like summarizing the previous questions and send that as content (instead of a long string with 20 questions/answers, you send a short summary of what the user has been asking for. it will keep your prompt short and kind of "aware" of the conversation.

据我所知,确实没有便宜的方法让大型语言模型(在这种情况下是Azure OpenAI)记住上下文,正如您所说,每次调用时发送上下文(特别是大量的上下文)会很快变得昂贵。话虽如此,您可以改变方法并尝试其他技术来模拟AI具有记忆的功能,比如总结之前的问题并将其作为内容发送(而不是发送包含20个问答的长字符串,您发送一个用户一直在询问的内容的简短摘要)。这将使您的提示保持简短,并使AI对对话保持“意识”。

There are also conversation buffers (keeping the chat history in memory and send it to de llm each time as you did) but it gets long pretty fast, for that you could configure a buffer window (limiting the memory of the conversation to the last 3 questions for example, that should help keep the token count manageable).

还有对话缓冲区(将聊天历史保存在内存中,并在每次调用时像您之前所做的那样发送给LLM),但对话历史很快就会变得很长。为此,您可以配置一个缓冲区窗口(例如,将对话的内存限制为最后3个问题),这有助于将令牌数量控制在可管理的范围内。

There are several ways to manage this but there is no "perfect memory" as far as I know, not one the is worth paying. If you could tell us a bit more on how good the bot memory needs to be or the specific use case, maybe we can be more precise. Good luck!

管理这种情况有几种方法,但据我所知,没有“完美的记忆”,至少没有一种值得为此付费的。如果您能告诉我们机器人需要多好的记忆能力,或者具体的使用场景,我们可能能给出更精确的建议。祝您好运!

相关文章:

  • 分布式光纤测温DTS使用的单模光纤与多模光纤有何区别?
  • Leetcode - 周赛401
  • 八大经典排序算法
  • kali中安装docker
  • SARscape——Lee滤波
  • celery使用 Zookeeper 或 kafka 作为broker,使用 mysql 作为 backend
  • POSTMAN接口详解
  • CentOS Linux 7系统中离线安装MySQL5.7步骤
  • Zabbix 7.0 LTS新特征
  • xss-lab靶场level1-level10
  • Centos7升级K8S集群
  • YOLOv10改进 | Neck | 添加双向特征金字塔BiFPN【含二次独家创新】
  • RK3568技术笔记十四 Ubuntu创建共享文件夹
  • 掌握心理学知识成为产品经理一门必修课?
  • 第一百一十六节 Java 面向对象设计 - Java 终止块
  • 2018一半小结一波
  • css属性的继承、初识值、计算值、当前值、应用值
  • Fabric架构演变之路
  • Java IO学习笔记一
  • Javascripit类型转换比较那点事儿,双等号(==)
  • SQLServer插入数据
  • zookeeper系列(七)实战分布式命名服务
  • 包装类对象
  • 回顾2016
  • 开源中国专访:Chameleon原理首发,其它跨多端统一框架都是假的?
  • 日剧·日综资源集合(建议收藏)
  • 它承受着该等级不该有的简单, leetcode 564 寻找最近的回文数
  • 小而合理的前端理论:rscss和rsjs
  • 小试R空间处理新库sf
  • 最简单的无缝轮播
  • (STM32笔记)九、RCC时钟树与时钟 第一部分
  • (备份) esp32 GPIO
  • (第二周)效能测试
  • (十六)、把镜像推送到私有化 Docker 仓库
  • (四)js前端开发中设计模式之工厂方法模式
  • (淘宝无限适配)手机端rem布局详解(转载非原创)
  • (图)IntelliTrace Tools 跟踪云端程序
  • (一)面试需要掌握的技巧
  • (原創) 物件導向與老子思想 (OO)
  • (转)Sql Server 保留几位小数的两种做法
  • ****** 二十三 ******、软设笔记【数据库】-数据操作-常用关系操作、关系运算
  • **python多态
  • ..回顾17,展望18
  • .bat批处理(九):替换带有等号=的字符串的子串
  • .bat批处理出现中文乱码的情况
  • .Net CoreRabbitMQ消息存储可靠机制
  • .NET/C# 利用 Walterlv.WeakEvents 高性能地中转一个自定义的弱事件(可让任意 CLR 事件成为弱事件)
  • .NETCORE 开发登录接口MFA谷歌多因子身份验证
  • .NET导入Excel数据
  • .NET使用HttpClient以multipart/form-data形式post上传文件及其相关参数
  • @transactional 方法执行完再commit_当@Transactional遇到@CacheEvict,你的代码是不是有bug!...
  • @Valid和@NotNull字段校验使用
  • [ MSF使用实例 ] 利用永恒之蓝(MS17-010)漏洞导致windows靶机蓝屏并获取靶机权限
  • [ vulhub漏洞复现篇 ] Apache APISIX 默认密钥漏洞 CVE-2020-13945
  • [12] 使用 CUDA 加速排序算法