• 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

95.45
/provider/bedrock/foundation/llama/encoder.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 llama
10

11
import (
12
        "strings"
13

14
        "github.com/kshard/chatter"
15
        "github.com/kshard/chatter/aio/provider"
16
)
17

18
func factory() (provider.Encoder[*input], error) {
1✔
19
        codec := &encoder{
1✔
20
                w:   strings.Builder{},
1✔
21
                req: input{},
1✔
22
        }
1✔
23
        codec.w.WriteString(begin_of_text)
1✔
24
        return codec, nil
1✔
25
}
1✔
26

27
func (codec *encoder) writeHeader(actor string) error {
1✔
28
        codec.w.WriteString(start_header_id)
1✔
29
        codec.w.WriteString(actor)
1✔
30
        codec.w.WriteString(end_header_id)
1✔
31
        return nil
1✔
32
}
1✔
33

34
func (codec *encoder) WithInferrer(inferrer provider.Inferrer) {
1✔
35
        codec.req.Temperature = inferrer.Temperature
1✔
36
        codec.req.TopP = inferrer.TopP
1✔
37
        codec.req.MaxTokens = inferrer.MaxTokens
1✔
38
}
1✔
39

NEW
40
func (codec *encoder) WithCommand(cmd chatter.Cmd) {
×
NEW
41
        // Llama3 doesn't support tools in this bedrock implementation
×
NEW
42
}
×
43

44
// AsStratum processes a Stratum message (system role)
45
func (codec *encoder) AsStratum(stratum chatter.Stratum) error {
1✔
46
        codec.writeHeader(system)
1✔
47
        codec.w.WriteString(string(stratum))
1✔
48
        codec.w.WriteString(end_of_turn)
1✔
49
        return nil
1✔
50
}
1✔
51

52
// AsText processes a Text message as user input
53
func (codec *encoder) AsText(text chatter.Text) error {
1✔
54
        codec.writeHeader(human)
1✔
55
        codec.w.WriteString(string(text))
1✔
56
        codec.w.WriteString(end_of_turn)
1✔
57
        // Note: required as part of Llama3 protocol
1✔
58
        codec.writeHeader(assistant)
1✔
59
        return nil
1✔
60
}
1✔
61

62
// AsPrompt processes a Prompt message by converting it to string
63
func (codec *encoder) AsPrompt(prompt *chatter.Prompt) error {
1✔
64
        codec.writeHeader(human)
1✔
65
        codec.w.WriteString(prompt.String())
1✔
66
        codec.w.WriteString(end_of_turn)
1✔
67
        // Note: required as part of Llama3 protocol
1✔
68
        codec.writeHeader(assistant)
1✔
69
        return nil
1✔
70
}
1✔
71

72
// AsAnswer processes an Answer message (tool results)
73
func (codec *encoder) AsAnswer(answer *chatter.Answer) error {
1✔
74
        if len(answer.Yield) == 0 {
2✔
75
                return nil
1✔
76
        }
1✔
77

78
        codec.writeHeader(human)
1✔
79
        for _, content := range answer.Yield {
2✔
80
                codec.w.Write(content.Value)
1✔
81
        }
1✔
82
        codec.w.WriteString(end_of_turn)
1✔
83
        // Note: required as part of Llama3 protocol
1✔
84
        codec.writeHeader(assistant)
1✔
85

1✔
86
        return nil
1✔
87
}
88

89
// AsReply processes a Reply message (assistant response)
90
func (codec *encoder) AsReply(reply *chatter.Reply) error {
1✔
91
        codec.w.WriteString(reply.String())
1✔
92
        codec.w.WriteString(end_of_turn)
1✔
93
        return nil
1✔
94
}
1✔
95

96
func (codec *encoder) Build() *input {
1✔
97
        codec.req.Prompt = codec.w.String()
1✔
98
        return &codec.req
1✔
99
}
1✔
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