alibaba / higress

Cloud Native API Gateway | 云原生API网关
https://higress.io
Apache License 2.0
2.5k stars 407 forks source link

ai-statistics 统计获取模型失败[bug & 求助] #1057

Open pepesi opened 5 days ago

pepesi commented 5 days ago

我配置了三个ai上游服务,分别是qwen/baichuan/zhipuai,同时开启了ai统计模块,部分配置如下

image

我期望的是能从/stat/prometheus中采集到每个上游模型的token使用情况,但是日志显示,获取模型失败,似乎是上游调用onHttpStreamingBody 的时候,就直接跳过了最后的那个chunk, 图中sssss部分是将data和endOfStream debug出来的。

image

qwen是可以的,zhipuai/baichuan 不行。

我对proxy-wasm-go-sdk和流程生命周期还不太熟悉,求助!

johnlanni commented 5 days ago

开启 ai-proxy 插件了吗

pepesi commented 5 days ago

开启 ai-proxy 插件了吗

开了的,

image
pepesi commented 5 days ago

我发现它总是在识别最后一个chunk的时候出现问题,我在debug过程中,尝试过打印一些信息,在https://github.com/alibaba/higress/blob/0ce52de59b2416193fdb62854210142aceef98f5/plugins/wasm-go/pkg/wrapper/plugin_wrapper.go#L406 这儿传进来的bodySize都是0,但是我对上游调用一无所知

johnlanni commented 5 days ago

cc @rinfx

pepesi commented 5 days ago

我知道为啥了,不是上游的问题,是ai-statistics 在获取lastChunk的时候有问题,明天我来提pr吧; getLastChunk的函数默认是拿最后一个区段,实际上最后一个段可能不是带有usage的,这儿需要单独处理;