fix: resolve merge conflicts with main, adapt transcriber to interface
This commit is contained in:
parent
9118879d59
commit
dfe65da016
2 changed files with 28 additions and 34 deletions
|
|
@ -624,50 +624,41 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
|
||||||
|
|
||||||
// Transcribe any audio media refs before passing to the agent.
|
// Transcribe any audio media refs before passing to the agent.
|
||||||
userMessage := msg.Content
|
userMessage := msg.Content
|
||||||
|
|
||||||
if al.transcriber != nil && len(msg.Media) > 0 && al.mediaStore != nil {
|
if al.transcriber != nil && len(msg.Media) > 0 && al.mediaStore != nil {
|
||||||
logger.DebugCF("agent", "Checking media for transcription", map[string]any{
|
|
||||||
"media_count": len(msg.Media),
|
|
||||||
})
|
|
||||||
for _, ref := range msg.Media {
|
for _, ref := range msg.Media {
|
||||||
localPath, meta, err := al.mediaStore.ResolveWithMeta(ref)
|
localPath, meta, err := al.mediaStore.ResolveWithMeta(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WarnCF("agent", "Failed to resolve media ref for transcription", map[string]any{
|
|
||||||
"ref": ref, "error": err.Error(),
|
|
||||||
})
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if inferMediaType(meta.Filename, meta.ContentType) != "audio" {
|
|
||||||
logger.DebugCF("agent", "Skipping non-audio media", map[string]any{
|
mediaType := inferMediaType(meta.Filename, meta.ContentType)
|
||||||
"ref": ref, "filename": meta.Filename,
|
|
||||||
|
// Handle audio transcription
|
||||||
|
if mediaType == "audio" {
|
||||||
|
logger.InfoCF("agent", "Transcribing audio", map[string]any{
|
||||||
|
"ref": ref, "path": localPath, "filename": meta.Filename,
|
||||||
})
|
})
|
||||||
continue
|
result, err := al.transcriber.Transcribe(ctx, localPath)
|
||||||
}
|
if err != nil {
|
||||||
logger.InfoCF("agent", "Transcribing audio", map[string]any{
|
logger.WarnCF("agent", "Audio transcription failed", map[string]any{
|
||||||
"ref": ref, "path": localPath, "filename": meta.Filename,
|
"ref": ref, "error": err.Error(),
|
||||||
})
|
})
|
||||||
result, err := al.transcriber.Transcribe(ctx, localPath)
|
continue
|
||||||
if err != nil {
|
}
|
||||||
logger.WarnCF("agent", "Audio transcription failed", map[string]any{
|
logger.InfoCF("agent", "Transcribed audio", map[string]any{
|
||||||
"ref": ref, "error": err.Error(),
|
"ref": ref, "length": len(result.Text),
|
||||||
})
|
})
|
||||||
continue
|
// Replace the [voice]/[audio] placeholder with the actual transcript
|
||||||
}
|
userMessage = strings.NewReplacer("[voice]", "", "[audio]", "").Replace(userMessage)
|
||||||
logger.InfoCF("agent", "Transcribed audio", map[string]any{
|
userMessage = strings.TrimSpace(userMessage)
|
||||||
"ref": ref, "length": len(result.Text),
|
if userMessage != "" {
|
||||||
})
|
userMessage = userMessage + "\n\n[Voice transcript]: " + result.Text
|
||||||
// Replace the [voice]/[audio] placeholder with the actual transcript
|
} else {
|
||||||
userMessage = strings.NewReplacer("[voice]", "", "[audio]", "").Replace(userMessage)
|
userMessage = result.Text
|
||||||
userMessage = strings.TrimSpace(userMessage)
|
}
|
||||||
if userMessage != "" {
|
|
||||||
userMessage = userMessage + "\n\n[Voice transcript]: " + result.Text
|
|
||||||
} else {
|
|
||||||
userMessage = result.Text
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if al.transcriber == nil && len(msg.Media) > 0 {
|
|
||||||
logger.WarnCF("agent", "Transcriber not configured, skipping media", map[string]any{
|
|
||||||
"media_count": len(msg.Media),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return al.runAgentLoop(ctx, agent, processOptions{
|
return al.runAgentLoop(ctx, agent, processOptions{
|
||||||
|
|
@ -1759,3 +1750,5 @@ func extractParentPeer(msg bus.InboundMessage) *routing.RoutePeer {
|
||||||
}
|
}
|
||||||
return &routing.RoutePeer{Kind: parentKind, ID: parentID}
|
return &routing.RoutePeer{Kind: parentKind, ID: parentID}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -364,6 +364,7 @@ func parseResponse(body io.Reader) (*LLMResponse, error) {
|
||||||
// openaiMessage is the wire-format message for OpenAI-compatible APIs.
|
// openaiMessage is the wire-format message for OpenAI-compatible APIs.
|
||||||
// It mirrors protocoltypes.Message but omits SystemParts, which is an
|
// It mirrors protocoltypes.Message but omits SystemParts, which is an
|
||||||
// internal field that would be unknown to third-party endpoints.
|
// internal field that would be unknown to third-party endpoints.
|
||||||
|
// Content can be either a string or an array of content blocks for multimodal messages.
|
||||||
type openaiMessage struct {
|
type openaiMessage struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue