Closed jishux2 closed 5 days ago
When using Claude-3.5-sonnet on the official website, it's possible to send messages containing 4k tokens at once. However, when using the API through third-party clients (such as NextChat) to send messages with context, even with only 2-4 historical messages, the content is frequently truncated. The final context presented in the conversation often contains less than 1k tokens.
Although the cause is unclear, my current workaround is to stop calling the __progressive_summarize_text
function in poe_api_wrapper/openai/api.py:
# rest_string = await helpers.__progressive_summarize_text(
# rest_string, min(len(rest_string), tokensLimit)
# )
However, this approach results in rest_string
repeatedly including main_request
at the end. To address this, I've also modified this line of code:
rest_string = await helpers.__stringify_messages(messages=messages[:-1])
This allows for larger context to be passed, but it doesn't handle token limits. If there's a better method, please let me know.
看样子问题在于__progressive_summarize_text
函数中的这一句:len(text) < max_length
It appears the issue lies in the __progressive_summarize_text
function, specifically with this line: len(text) < max_length
它把文本长度和最大token值比较,而实际上应该都是用token计数进行比较。
This line compares the text length with the maximum token value, whereas it should actually be comparing token counts on both sides.
len(rest_string): 7894
tokensLimit: 4000
current_tokens: 2894
在官网上使用Claude-3.5-sonnet,一次性应该可以发送最多4k tokens的信息。但是在第三方客户端(如NextChat)中使用api发送携带上下文的信息时,即使只有2~4条历史信息,也经常会被截断,最终在对话中呈现出来的上下文只有不到1k tokens。
虽然不知道是什么原因,但目前我使用的替代方案是,不再在poe_api_wrapper/openai/api.py中调用
__progressive_summarize_text
函数:不过这样会导致在
rest_string
的末尾重复包含main_request
,于是还要修改这行代码:这样可以传入更大的上下文,但是没法处理token限制。如果有更好的方法,请让我知道
Please check #188 for my changes. Hope it helps.