Skip to content

Commit d7cdd0c

Browse files
authored
Merge pull request #17 from mutablelogic/v1
Anthropic and Bitwarden Changes
2 parents 2c24ec0 + 1b492d1 commit d7cdd0c

36 files changed

+1985
-660
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ You can create a payload with form data:
189189

190190
The payload should be a `struct` where the fields are converted to form tuples. File uploads require a field of type `multipart.File`.
191191

192+
## Unmarshalling responses
193+
194+
You can implement your own unmarshalling of responses by implementing the `Unmarshaler` interface:
195+
196+
```go
197+
type Unmarshaler interface {
198+
Unmarshal(mimetype string, r io.Reader) error
199+
}
200+
```
201+
192202
## Streaming Responses
193203

194204
If the returned content is a stream of JSON responses, then you can use the `OptResponse(fn func() error)` option, which

client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type Client struct {
3434
sync.Mutex
3535
*http.Client
3636

37+
// Parent object for client options
38+
Parent any
39+
3740
endpoint *url.URL
3841
ua string
3942
rate float32 // number of requests allowed per second

clientopts.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,16 @@ func OptHeader(key, value string) ClientOpt {
113113
return nil
114114
}
115115
}
116+
117+
// OptParent sets the parent client for this client, which is
118+
// used for setting additional client options in the parent
119+
func OptParent(v any) ClientOpt {
120+
return func(client *Client) error {
121+
if v == nil {
122+
return ErrBadParameter.With("OptParent")
123+
} else {
124+
client.Parent = v
125+
}
126+
return nil
127+
}
128+
}

cmd/api/anthropic.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
5-
"strings"
66

7+
// Packages
78
"github.com/djthorpe/go-tablewriter"
89
"github.com/mutablelogic/go-client"
910
"github.com/mutablelogic/go-client/pkg/anthropic"
11+
"github.com/mutablelogic/go-client/pkg/openai/schema"
1012
)
1113

1214
///////////////////////////////////////////////////////////////////////////////
@@ -52,10 +54,17 @@ func anthropicParse(flags *Flags, opts ...client.ClientOpt) error {
5254
///////////////////////////////////////////////////////////////////////////////
5355
// METHODS
5456

55-
func anthropicChat(w *tablewriter.Writer, args []string) error {
57+
func anthropicChat(ctx context.Context, w *tablewriter.Writer, args []string) error {
5658
// Request -> Response
57-
message := anthropic.NewMessage("user", strings.Join(args, " "))
58-
responses, err := anthropicClient.Messages(message)
59+
message := schema.NewMessage("user")
60+
for _, arg := range args {
61+
message.Add(schema.Text(arg))
62+
}
63+
64+
// Request -> Response
65+
responses, err := anthropicClient.Messages(ctx, []*schema.Message{
66+
message,
67+
})
5968
if err != nil {
6069
return err
6170
}

0 commit comments

Comments
 (0)