|
1 | 1 | package anthropic |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "encoding/json" |
5 | 6 |
|
| 7 | + // Packages |
6 | 8 | llm "github.com/mutablelogic/go-llm" |
7 | 9 | ) |
8 | 10 |
|
9 | 11 | ////////////////////////////////////////////////////////////////// |
10 | 12 | // TYPES |
11 | 13 |
|
12 | 14 | type session struct { |
13 | | - seq []*MessageMeta |
| 15 | + model *model |
| 16 | + opts []llm.Opt |
| 17 | + seq []*MessageMeta |
14 | 18 | } |
15 | 19 |
|
16 | 20 | var _ llm.Context = (*session)(nil) |
17 | 21 |
|
18 | 22 | /////////////////////////////////////////////////////////////////////////////// |
19 | 23 | // LIFECYCLE |
20 | 24 |
|
21 | | -func (*model) Context(...llm.Opt) (llm.Context, error) { |
22 | | - // TODO: Currently ignoring options |
23 | | - return &session{}, nil |
| 25 | +// Return am empty session context object for the model, |
| 26 | +// setting session options |
| 27 | +func (model *model) Context(opts ...llm.Opt) llm.Context { |
| 28 | + return &session{ |
| 29 | + model: model, |
| 30 | + opts: opts, |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +// Convenience method to create a session context object |
| 35 | +// with a user prompt, which panics on error |
| 36 | +func (model *model) UserPrompt(prompt string, opts ...llm.Opt) llm.Context { |
| 37 | + // Apply attachments |
| 38 | + opt, err := apply(opts...) |
| 39 | + if err != nil { |
| 40 | + panic(err) |
| 41 | + } |
| 42 | + |
| 43 | + meta := MessageMeta{ |
| 44 | + Role: "user", |
| 45 | + Content: make([]*Content, 1, len(opt.data)+1), |
| 46 | + } |
| 47 | + |
| 48 | + // Append the text |
| 49 | + meta.Content[0] = NewTextContent(prompt) |
| 50 | + |
| 51 | + // Append any additional data |
| 52 | + for _, data := range opt.data { |
| 53 | + meta.Content = append(meta.Content, data) |
| 54 | + } |
| 55 | + |
| 56 | + // Return success |
| 57 | + return nil |
24 | 58 | } |
25 | 59 |
|
26 | 60 | /////////////////////////////////////////////////////////////////////////////// |
@@ -64,32 +98,14 @@ func (session *session) Text() string { |
64 | 98 | return string(data) |
65 | 99 | } |
66 | 100 |
|
67 | | -// Append user prompt (and attachments) to a context |
68 | | -func (session *session) AppendUserPrompt(text string, opts ...llm.Opt) error { |
69 | | - // Apply attachments |
70 | | - opt, err := apply(opts...) |
71 | | - if err != nil { |
72 | | - return err |
73 | | - } |
74 | | - |
75 | | - meta := MessageMeta{ |
76 | | - Role: "user", |
77 | | - Content: make([]*Content, 1, len(opt.data)+1), |
78 | | - } |
79 | | - |
80 | | - // Append the text |
81 | | - meta.Content[0] = NewTextContent(text) |
82 | | - |
83 | | - // Append any additional data |
84 | | - for _, data := range opt.data { |
85 | | - meta.Content = append(meta.Content, data) |
86 | | - } |
87 | | - |
88 | | - // Return success |
89 | | - return nil |
| 101 | +// Generate a response from a user prompt (with attachments and |
| 102 | +// other empheral options |
| 103 | +func (session *session) FromUser(context.Context, string, ...llm.Opt) (llm.Context, error) { |
| 104 | + return nil, llm.ErrNotImplemented |
90 | 105 | } |
91 | 106 |
|
92 | | -// Append the result of calling a tool to a context |
93 | | -func (session *session) AppendToolResult(string, ...llm.Opt) error { |
94 | | - return llm.ErrNotImplemented |
| 107 | +// Generate a response from a tool, passing the call identifier or |
| 108 | +// function name, and the result |
| 109 | +func (session *session) FromTool(context.Context, string, any, ...llm.Opt) (llm.Context, error) { |
| 110 | + return nil, llm.ErrNotImplemented |
95 | 111 | } |
0 commit comments