mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-17 10:44:52 +08:00
streaming p0 fix: preserve upstream 400 body and cap stream edit length
This commit is contained in:
@@ -303,11 +303,15 @@ func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pID, ok := c.placeholders.Load(msg.ChatID); ok {
|
if pID, ok := c.placeholders.Load(msg.ChatID); ok {
|
||||||
|
htmlForEdit := htmlContent
|
||||||
|
if len([]rune(htmlForEdit)) > 3500 {
|
||||||
|
htmlForEdit = sanitizeTelegramHTML(markdownToTelegramHTML(splitTelegramText(plainTextFromTelegramHTML(htmlForEdit), 3500)[0]))
|
||||||
|
}
|
||||||
editCtx, cancelEdit := withTelegramAPITimeout(ctx)
|
editCtx, cancelEdit := withTelegramAPITimeout(ctx)
|
||||||
params := &telego.EditMessageTextParams{
|
params := &telego.EditMessageTextParams{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
MessageID: pID.(int),
|
MessageID: pID.(int),
|
||||||
Text: htmlContent,
|
Text: htmlForEdit,
|
||||||
ParseMode: telego.ModeHTML,
|
ParseMode: telego.ModeHTML,
|
||||||
ReplyMarkup: markup,
|
ReplyMarkup: markup,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ func (p *HTTPProvider) callChatCompletionsStream(ctx context.Context, messages [
|
|||||||
requestBody["temperature"] = temperature
|
requestBody["temperature"] = temperature
|
||||||
}
|
}
|
||||||
var fullText strings.Builder
|
var fullText strings.Builder
|
||||||
_, status, ctype, err := p.postJSONStream(ctx, endpointFor(p.apiBase, "/chat/completions"), requestBody, func(event string) {
|
rawBody, status, ctype, err := p.postJSONStream(ctx, endpointFor(p.apiBase, "/chat/completions"), requestBody, func(event string) {
|
||||||
var chunk struct {
|
var chunk struct {
|
||||||
Choices []struct {
|
Choices []struct {
|
||||||
Delta struct {
|
Delta struct {
|
||||||
@@ -416,6 +416,9 @@ func (p *HTTPProvider) callChatCompletionsStream(ctx context.Context, messages [
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status, ctype, err
|
return nil, status, ctype, err
|
||||||
}
|
}
|
||||||
|
if status != http.StatusOK || !strings.Contains(strings.ToLower(ctype), "text/event-stream") {
|
||||||
|
return rawBody, status, ctype, nil
|
||||||
|
}
|
||||||
body, _ := json.Marshal(map[string]interface{}{
|
body, _ := json.Marshal(map[string]interface{}{
|
||||||
"choices": []map[string]interface{}{{
|
"choices": []map[string]interface{}{{
|
||||||
"message": map[string]interface{}{"content": fullText.String()},
|
"message": map[string]interface{}{"content": fullText.String()},
|
||||||
|
|||||||
Reference in New Issue
Block a user