Skip to content

Commit 8b8f93d

Browse files
committed
Updates
1 parent 37ac3c7 commit 8b8f93d

File tree

7 files changed

+70
-499
lines changed

7 files changed

+70
-499
lines changed

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func main() {
7272
}
7373
```
7474

75-
For Mistral models, you can use:
75+
For [Mistral](https://pkg.go.dev/github.com/mutablelogic/go-llm/pkg/mistral) models, you can use:
7676

7777
```go
7878
import (
@@ -89,6 +89,9 @@ func main() {
8989
}
9090
```
9191

92+
You can append options to the agent creation to set the client/server communication options,
93+
such as user agent strings, timeouts, debugging, rate limiting, adding custom headers, etc. See [here](https://pkg.go.dev/github.com/mutablelogic/go-client#readme-basic-usage) for more information.
94+
9295
### Chat Sessions
9396

9497
You create a **chat session** with a model as follows,
@@ -100,7 +103,7 @@ import (
100103

101104
func session(ctx context.Context, agent llm.Agent) error {
102105
// Create a new chat session
103-
session := agent.Model("claude-3-5-haiku-20241022").Context()
106+
session := agent.Model(context.TODO(), "claude-3-5-haiku-20241022").Context()
104107

105108
// Repeat forever
106109
for {
@@ -109,12 +112,28 @@ func session(ctx context.Context, agent llm.Agent) error {
109112
return err
110113
}
111114

112-
// Print the response
113-
fmt.Println(session.Text())
115+
// Print the response for the zero'th completion
116+
fmt.Println(session.Text(0))
114117
}
115118
}
116119
```
117120

121+
### Embedding Generation
122+
123+
TODO
124+
125+
### Attachments & Image Caption Generation
126+
127+
TODO
128+
129+
### Streaming
130+
131+
TODO
132+
133+
### Tool Support
134+
135+
TODO
136+
118137
## Options
119138

120139
You can add options to sessions, or to prompts. Different providers and models support

pkg/mistral/chat_completion.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ type Response struct {
2121
Metrics `json:"usage,omitempty"`
2222
}
2323

24-
// Response variation
25-
type Choice struct {
26-
Index uint64 `json:"index"`
27-
Message MessageMeta `json:"message"`
28-
Reason string `json:"finish_reason,omitempty"`
29-
}
30-
3124
// Metrics
3225
type Metrics struct {
3326
InputTokens uint64 `json:"prompt_tokens,omitempty"`

pkg/mistral/message.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@ package mistral
33
///////////////////////////////////////////////////////////////////////////////
44
// TYPES
55

6+
// Possible completions
7+
type Completions []Completion
8+
9+
// Completion Variation
10+
type Completion struct {
11+
Index uint64 `json:"index"`
12+
Message Message `json:"message"`
13+
Reason string `json:"finish_reason,omitempty"`
14+
}
15+
616
// Message with text or object content
7-
type MessageMeta struct {
17+
type Message struct {
818
Role string `json:"role"` // assistant, user, tool, system
919
Prefix bool `json:"prefix,omitempty"`
1020
Content any `json:"content,omitempty"`
@@ -30,7 +40,7 @@ type Image string
3040
///////////////////////////////////////////////////////////////////////////////
3141
// LIFECYCLE
3242

33-
// Return a Content object with text content
43+
// Return a Content object with text content (either in "text" or "prediction" field)
3444
func NewContent(t, v, p string) *Content {
3545
content := new(Content)
3646
content.Type = t
@@ -51,25 +61,29 @@ func NewTextContent(v string) *Content {
5161
///////////////////////////////////////////////////////////////////////////////
5262
// PUBLIC METHODS
5363

54-
// Return the text content
55-
func (m MessageMeta) Text() string {
56-
if text, ok := m.Content.(string); ok {
57-
return text
64+
// Return the number of completions
65+
func (c Completions) Num() int {
66+
return len(c)
67+
}
68+
69+
// Return the role of the completion
70+
func (c Completions) Role() string {
71+
// The role should be the same for all completions, let's use the first one
72+
if len(c) == 0 {
73+
return ""
5874
}
59-
return ""
75+
return c[0].Message.Role
6076
}
6177

62-
/*
63-
if arr, ok := m.Content.([]Content); ok {
64-
if len(m.Content) == 0 {
78+
// Return the text content for a specific completion
79+
func (c Completions) Text(index int) string {
80+
if index < 0 || index >= len(c) {
6581
return ""
6682
}
67-
var text []string
68-
for _, content := range m.Content {
69-
if content.Type == "text" && content.Text != nil {
70-
text = append(text, string(*content.Text))
71-
}
83+
completion := c[index].Message
84+
if text, ok := completion.Content.(string); ok {
85+
return text
7286
}
73-
return strings.Join(text, "\n")
87+
// Will the text be in other forms?
88+
return ""
7489
}
75-
*/

pkg/mistral/session.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package mistral
22

33
import (
4-
// Packages
54
"context"
65
"encoding/json"
76

7+
// Packages
88
llm "github.com/mutablelogic/go-llm"
99
)
1010

1111
//////////////////////////////////////////////////////////////////
1212
// TYPES
1313

1414
type session struct {
15-
model *model // The model used for the session
16-
opts []llm.Opt // Options to apply to the session
17-
seq []*MessageMeta // Sequence of messages
15+
model *model // The model used for the session
16+
opts []llm.Opt // Options to apply to the session
17+
seq []*Message // Sequence of messages
1818
}
1919

2020
var _ llm.Context = (*session)(nil)
@@ -67,6 +67,16 @@ func (session session) String() string {
6767
//////////////////////////////////////////////////////////////////
6868
// PUBLIC METHODS
6969

70+
// Return the number of completions
71+
func (session *session) Num() int {
72+
if len(session.seq) == 0 {
73+
return 0
74+
}
75+
message := session.seq[len(session.seq)-1]
76+
message.
77+
return session.seq[len(session.seq)-1].Role
78+
}
79+
7080
// Return the role of the last message
7181
func (session *session) Role() string {
7282
if len(session.seq) == 0 {
@@ -76,7 +86,7 @@ func (session *session) Role() string {
7686
}
7787

7888
// Return the text of the last message
79-
func (session *session) Text() string {
89+
func (session *session) Text(index int) string {
8090
if len(session.seq) == 0 {
8191
return ""
8292
}
@@ -85,7 +95,7 @@ func (session *session) Text() string {
8595
}
8696

8797
// Return the text of the last message
88-
func (session *session) ToolCalls() []llm.ToolCall {
98+
func (session *session) ToolCalls(index int) []llm.ToolCall {
8999
return nil
90100
}
91101

0 commit comments

Comments
 (0)