fix(history): prevent duplicate prepend with seen-set and fetch guard; reset seen on channel switch
This commit is contained in:
parent
e9d764817f
commit
95e1f77956
2 changed files with 35 additions and 15 deletions
|
|
@ -194,16 +194,20 @@ func (o *OpenAI) SummarizeLink(ctx context.Context, rawURL string) (string, erro
|
|||
oembed := "https://www.youtube.com/oembed?format=json&url=" + url.QueryEscape(watchURL)
|
||||
req, _ := http.NewRequestWithContext(ctx2, http.MethodGet, oembed, nil)
|
||||
if resp, err := http.DefaultClient.Do(req); err == nil {
|
||||
func(){
|
||||
func() {
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
var oem struct{
|
||||
var oem struct {
|
||||
Title string `json:"title"`
|
||||
Thumb string `json:"thumbnail_url"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&oem); err == nil {
|
||||
if oem.Title != "" { title = oem.Title }
|
||||
if oem.Thumb != "" { img = oem.Thumb }
|
||||
if oem.Title != "" {
|
||||
title = oem.Title
|
||||
}
|
||||
if oem.Thumb != "" {
|
||||
img = oem.Thumb
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
@ -226,13 +230,17 @@ func (o *OpenAI) SummarizeLink(ctx context.Context, rawURL string) (string, erro
|
|||
if art, err := readability.FromReader(strings.NewReader(text), base); err == nil {
|
||||
if at := strings.TrimSpace(art.TextContent); at != "" {
|
||||
text = at
|
||||
if title == "" && strings.TrimSpace(art.Title) != "" { title = strings.TrimSpace(art.Title) }
|
||||
if title == "" && strings.TrimSpace(art.Title) != "" {
|
||||
title = strings.TrimSpace(art.Title)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
text = strings.ReplaceAll(text, "\r", "")
|
||||
text = strings.TrimSpace(text)
|
||||
if len(text) > 6000 { text = text[:6000] }
|
||||
if len(text) > 6000 {
|
||||
text = text[:6000]
|
||||
}
|
||||
content = text
|
||||
}
|
||||
}()
|
||||
|
|
@ -247,7 +255,11 @@ func (o *OpenAI) SummarizeLink(ctx context.Context, rawURL string) (string, erro
|
|||
b.WriteString("URL: ")
|
||||
b.WriteString(rawURL)
|
||||
b.WriteString("\n")
|
||||
if title != "" { b.WriteString("Title: "); b.WriteString(title); b.WriteString("\n") }
|
||||
if title != "" {
|
||||
b.WriteString("Title: ")
|
||||
b.WriteString(title)
|
||||
b.WriteString("\n")
|
||||
}
|
||||
b.WriteString("\n")
|
||||
if content != "" {
|
||||
b.WriteString("Extracted content (may be truncated):\n")
|
||||
|
|
@ -274,11 +286,17 @@ func (o *OpenAI) SummarizeLink(ctx context.Context, rawURL string) (string, erro
|
|||
},
|
||||
MaxCompletionTokens: o.maxTokens,
|
||||
}
|
||||
if !reasoningLike { req.Temperature = 0.2 }
|
||||
if !reasoningLike {
|
||||
req.Temperature = 0.2
|
||||
}
|
||||
|
||||
resp, err := client.CreateChatCompletion(ctx, req)
|
||||
if err != nil { return "", err }
|
||||
if len(resp.Choices) == 0 { return "", nil }
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(resp.Choices) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
return strings.TrimSpace(resp.Choices[0].Message.Content), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue