• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kshard / chatter / 16538940978

26 Jul 2025 10:35AM UTC coverage: 67.584% (+44.9%) from 22.674%
16538940978

Pull #53

github

fogfish
update license
Pull Request #53: Enable multi-content I/O within prompts & responses

596 of 837 new or added lines in 27 files covered. (71.21%)

2 existing lines in 2 files now uncovered.

884 of 1308 relevant lines covered (67.58%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.94
/provider/bedrock/foundation/converse/decoder.go
1
//
2
// Copyright (C) 2024 - 2025 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/kshard/chatter
7
//
8

9
package converse
10

11
import (
12
        "fmt"
13
        "log/slog"
14

15
        "github.com/aws/aws-sdk-go-v2/aws"
16
        "github.com/aws/aws-sdk-go-v2/service/bedrockruntime"
17
        "github.com/aws/aws-sdk-go-v2/service/bedrockruntime/types"
18
        "github.com/kshard/chatter"
19
)
20

21
func (decoder decoder) Decode(result *bedrockruntime.ConverseOutput) (*chatter.Reply, error) {
1✔
22
        reply := new(chatter.Reply)
1✔
23
        reply.Stage = decodeStage(result.StopReason)
1✔
24

1✔
25
        content, err := decodeOutput(result.Output)
1✔
26
        if err != nil {
2✔
27
                return nil, err
1✔
28
        }
1✔
29
        reply.Content = content
1✔
30

1✔
31
        if result.Usage != nil {
2✔
32
                reply.Usage.InputTokens += int(aws.ToInt32(result.Usage.InputTokens))
1✔
33
                reply.Usage.ReplyTokens += int(aws.ToInt32(result.Usage.OutputTokens))
1✔
34
        }
1✔
35

36
        return reply, nil
1✔
37
}
38

39
func decodeStage(reason types.StopReason) chatter.Stage {
1✔
40
        switch reason {
1✔
41
        case types.StopReasonEndTurn:
1✔
42
                return chatter.LLM_RETURN
1✔
43
        case types.StopReasonMaxTokens:
1✔
44
                return chatter.LLM_INCOMPLETE
1✔
45
        case types.StopReasonStopSequence:
1✔
46
                return chatter.LLM_INCOMPLETE
1✔
47
        case types.StopReasonToolUse:
1✔
48
                return chatter.LLM_INVOKE
1✔
49
        default:
1✔
50
                return chatter.LLM_ERROR
1✔
51
        }
52
}
53

54
func decodeOutput(out types.ConverseOutput) ([]chatter.Content, error) {
1✔
55
        switch v := out.(type) {
1✔
56
        case *types.ConverseOutputMemberMessage:
1✔
57
                seq := make([]chatter.Content, 0)
1✔
58
                for _, block := range v.Value.Content {
2✔
59
                        c, err := decodeContent(block)
1✔
60
                        if err != nil {
1✔
NEW
61
                                return nil, err
×
NEW
62
                        }
×
63
                        if c != nil {
2✔
64
                                seq = append(seq, c)
1✔
65
                        }
1✔
66
                }
67
                return seq, nil
1✔
68
        default:
1✔
69
                return nil, fmt.Errorf("unknown bedrock api response %T", out)
1✔
70
        }
71
}
72

73
func decodeContent(block types.ContentBlock) (chatter.Content, error) {
1✔
74
        switch v := block.(type) {
1✔
75
        case *types.ContentBlockMemberText:
1✔
76
                return chatter.Text(v.Value), nil
1✔
77

78
        case *types.ContentBlockMemberToolUse:
1✔
79
                in, err := v.Value.Input.MarshalSmithyDocument()
1✔
80
                if err != nil {
1✔
NEW
81
                        return nil, err
×
NEW
82
                }
×
83
                return chatter.Invoke{
1✔
84
                        Cmd: aws.ToString(v.Value.Name),
1✔
85
                        Args: chatter.Json{
1✔
86
                                ID:    aws.ToString(v.Value.ToolUseId),
1✔
87
                                Value: in,
1✔
88
                        },
1✔
89
                        Message: v,
1✔
90
                }, nil
1✔
NEW
91
        default:
×
NEW
92
                slog.Warn("chatter does not support aws bedrock content type",
×
NEW
93
                        slog.String("type", fmt.Sprintf("%T", block)),
×
NEW
94
                )
×
NEW
95
                return nil, nil
×
96
        }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc