-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1260ecf
commit 6e63e84
Showing
5 changed files
with
178 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package mlx | ||
|
||
type Client struct { | ||
*Completer | ||
} | ||
|
||
func New(url string, options ...Option) (*Client, error) { | ||
c, err := NewCompleter(url, options...) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Client{ | ||
Completer: c, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package mlx | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/adrianliechti/llama/pkg/provider/openai" | ||
) | ||
|
||
type Completer = openai.Completer | ||
|
||
func NewCompleter(url string, options ...Option) (*Completer, error) { | ||
if url == "" { | ||
return nil, errors.New("url is required") | ||
} | ||
|
||
url = strings.TrimRight(url, "/") | ||
url = strings.TrimSuffix(url, "/v1") | ||
|
||
c := &Config{ | ||
options: []openai.Option{ | ||
openai.WithURL(url + "/v1"), | ||
}, | ||
} | ||
|
||
for _, option := range options { | ||
option(c) | ||
} | ||
|
||
return openai.NewCompleter(c.options...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mlx | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/adrianliechti/llama/pkg/provider/openai" | ||
) | ||
|
||
type Config struct { | ||
options []openai.Option | ||
} | ||
|
||
type Option func(*Config) | ||
|
||
func WithClient(client *http.Client) Option { | ||
return func(c *Config) { | ||
c.options = append(c.options, openai.WithClient(client)) | ||
} | ||
} | ||
|
||
func WithModel(model string) Option { | ||
return func(c *Config) { | ||
c.options = append(c.options, openai.WithModel(model)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters