Skip to content

Commit 1e69fc6

Browse files
authored
Merge pull request #2 from Jesssullivan/feat/zai-provider-with-extra-fields
Feat/zai provider with extra fields
2 parents 17cbc17 + 41d471e commit 1e69fc6

40 files changed

+9687
-0
lines changed

providers/cerebras/cerebras.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Package cerebras provides a Fantasy provider for the Cerebras Inference API.
2+
package cerebras
3+
4+
import (
5+
"charm.land/fantasy"
6+
"charm.land/fantasy/providers/openaicompat"
7+
)
8+
9+
const (
10+
// Name is the provider identifier for Cerebras.
11+
Name = "cerebras"
12+
// BaseURL is the default Cerebras API base URL.
13+
BaseURL = "https://api.cerebras.ai/v1"
14+
)
15+
16+
// Option configures the Cerebras provider via OpenAI-compatible options.
17+
type Option = openaicompat.Option
18+
19+
var (
20+
// WithBaseURL is an alias for openaicompat.WithBaseURL.
21+
WithBaseURL = openaicompat.WithBaseURL
22+
// WithAPIKey is an alias for openaicompat.WithAPIKey.
23+
WithAPIKey = openaicompat.WithAPIKey
24+
// WithHeaders is an alias for openaicompat.WithHeaders.
25+
WithHeaders = openaicompat.WithHeaders
26+
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
27+
WithHTTPClient = openaicompat.WithHTTPClient
28+
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
29+
WithSDKOptions = openaicompat.WithSDKOptions
30+
)
31+
32+
// New creates a new Cerebras provider using OpenAI-compatible transport/options.
33+
func New(opts ...Option) (fantasy.Provider, error) {
34+
options := []Option{
35+
openaicompat.WithName(Name),
36+
WithBaseURL(BaseURL),
37+
}
38+
options = append(options, opts...)
39+
return openaicompat.New(options...)
40+
}

providers/groq/groq.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Package groq provides a Fantasy provider for the Groq API.
2+
package groq
3+
4+
import (
5+
"charm.land/fantasy"
6+
"charm.land/fantasy/providers/openaicompat"
7+
)
8+
9+
const (
10+
// Name is the provider identifier for Groq.
11+
Name = "groq"
12+
// BaseURL is the default Groq API base URL.
13+
BaseURL = "https://api.groq.com/openai/v1"
14+
)
15+
16+
// Option configures the Groq provider via OpenAI-compatible options.
17+
type Option = openaicompat.Option
18+
19+
var (
20+
// WithBaseURL is an alias for openaicompat.WithBaseURL.
21+
WithBaseURL = openaicompat.WithBaseURL
22+
// WithAPIKey is an alias for openaicompat.WithAPIKey.
23+
WithAPIKey = openaicompat.WithAPIKey
24+
// WithHeaders is an alias for openaicompat.WithHeaders.
25+
WithHeaders = openaicompat.WithHeaders
26+
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
27+
WithHTTPClient = openaicompat.WithHTTPClient
28+
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
29+
WithSDKOptions = openaicompat.WithSDKOptions
30+
)
31+
32+
// New creates a new Groq provider using OpenAI-compatible transport/options.
33+
func New(opts ...Option) (fantasy.Provider, error) {
34+
options := []Option{
35+
openaicompat.WithName(Name),
36+
WithBaseURL(BaseURL),
37+
}
38+
options = append(options, opts...)
39+
return openaicompat.New(options...)
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Package huggingface provides a Fantasy provider for the Hugging Face Inference API.
2+
package huggingface
3+
4+
import (
5+
"charm.land/fantasy"
6+
"charm.land/fantasy/providers/openaicompat"
7+
)
8+
9+
const (
10+
// Name is the provider identifier for Hugging Face.
11+
Name = "huggingface"
12+
// BaseURL is the default Hugging Face Inference API base URL.
13+
BaseURL = "https://router.huggingface.co/v1"
14+
)
15+
16+
// Option configures the Hugging Face provider via OpenAI-compatible options.
17+
type Option = openaicompat.Option
18+
19+
var (
20+
// WithBaseURL is an alias for openaicompat.WithBaseURL.
21+
WithBaseURL = openaicompat.WithBaseURL
22+
// WithAPIKey is an alias for openaicompat.WithAPIKey.
23+
WithAPIKey = openaicompat.WithAPIKey
24+
// WithHeaders is an alias for openaicompat.WithHeaders.
25+
WithHeaders = openaicompat.WithHeaders
26+
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
27+
WithHTTPClient = openaicompat.WithHTTPClient
28+
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
29+
WithSDKOptions = openaicompat.WithSDKOptions
30+
)
31+
32+
// New creates a new Hugging Face provider using OpenAI-compatible transport/options.
33+
func New(opts ...Option) (fantasy.Provider, error) {
34+
options := []Option{
35+
openaicompat.WithName(Name),
36+
WithBaseURL(BaseURL),
37+
}
38+
options = append(options, opts...)
39+
return openaicompat.New(options...)
40+
}

providers/xai/xai.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Package xai provides a Fantasy provider for the xAI API.
2+
package xai
3+
4+
import (
5+
"charm.land/fantasy"
6+
"charm.land/fantasy/providers/openaicompat"
7+
)
8+
9+
const (
10+
// Name is the provider identifier for xAI.
11+
Name = "xai"
12+
// BaseURL is the default xAI API base URL.
13+
BaseURL = "https://api.x.ai/v1"
14+
)
15+
16+
// Option configures the xAI provider via OpenAI-compatible options.
17+
type Option = openaicompat.Option
18+
19+
var (
20+
// WithBaseURL is an alias for openaicompat.WithBaseURL.
21+
WithBaseURL = openaicompat.WithBaseURL
22+
// WithAPIKey is an alias for openaicompat.WithAPIKey.
23+
WithAPIKey = openaicompat.WithAPIKey
24+
// WithHeaders is an alias for openaicompat.WithHeaders.
25+
WithHeaders = openaicompat.WithHeaders
26+
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
27+
WithHTTPClient = openaicompat.WithHTTPClient
28+
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
29+
WithSDKOptions = openaicompat.WithSDKOptions
30+
)
31+
32+
// New creates a new xAI provider using OpenAI-compatible transport/options.
33+
func New(opts ...Option) (fantasy.Provider, error) {
34+
options := []Option{
35+
openaicompat.WithName(Name),
36+
WithBaseURL(BaseURL),
37+
}
38+
options = append(options, opts...)
39+
return openaicompat.New(options...)
40+
}

providers/zai/zai.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Package zai provides a Fantasy provider for the Z.ai Coding PaaS API.
2+
package zai
3+
4+
import (
5+
"charm.land/fantasy"
6+
"charm.land/fantasy/providers/openaicompat"
7+
)
8+
9+
const (
10+
// Name is the provider identifier for Z.ai.
11+
Name = "zai"
12+
// BaseURL is the default Z.ai Coding PaaS API base URL.
13+
BaseURL = "https://api.z.ai/api/coding/paas/v4"
14+
)
15+
16+
// Option configures the Z.ai provider via OpenAI-compatible options.
17+
type Option = openaicompat.Option
18+
19+
var (
20+
// WithBaseURL is an alias for openaicompat.WithBaseURL.
21+
WithBaseURL = openaicompat.WithBaseURL
22+
// WithAPIKey is an alias for openaicompat.WithAPIKey.
23+
WithAPIKey = openaicompat.WithAPIKey
24+
// WithHeaders is an alias for openaicompat.WithHeaders.
25+
WithHeaders = openaicompat.WithHeaders
26+
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
27+
WithHTTPClient = openaicompat.WithHTTPClient
28+
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
29+
WithSDKOptions = openaicompat.WithSDKOptions
30+
)
31+
32+
// New creates a new Z.ai provider using OpenAI-compatible transport/options.
33+
func New(opts ...Option) (fantasy.Provider, error) {
34+
options := []Option{
35+
openaicompat.WithName(Name),
36+
WithBaseURL(BaseURL),
37+
}
38+
options = append(options, opts...)
39+
return openaicompat.New(options...)
40+
}

providertests/cerebras_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package providertests
2+
3+
import (
4+
"net/http"
5+
"os"
6+
"testing"
7+
8+
"charm.land/fantasy"
9+
"charm.land/fantasy/providers/cerebras"
10+
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
11+
)
12+
13+
func TestCerebrasCommon(t *testing.T) {
14+
testCommon(t, []builderPair{
15+
{"cerebras-qwen-3-coder-480b", builderCerebras, nil, nil},
16+
})
17+
}
18+
19+
func builderCerebras(t *testing.T, r *recorder.Recorder) (fantasy.LanguageModel, error) {
20+
provider, err := cerebras.New(
21+
cerebras.WithAPIKey(os.Getenv("FANTASY_CEREBRAS_API_KEY")),
22+
cerebras.WithHTTPClient(&http.Client{Transport: r}),
23+
)
24+
if err != nil {
25+
return nil, err
26+
}
27+
return provider.LanguageModel(t.Context(), "qwen-3-coder-480b")
28+
}

providertests/groq_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package providertests
2+
3+
import (
4+
"net/http"
5+
"os"
6+
"testing"
7+
8+
"charm.land/fantasy"
9+
"charm.land/fantasy/providers/groq"
10+
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
11+
)
12+
13+
func TestGroqCommon(t *testing.T) {
14+
testCommon(t, []builderPair{
15+
{"groq-kimi-k2-0905", builderGroqProvider, nil, nil},
16+
})
17+
}
18+
19+
func builderGroqProvider(t *testing.T, r *recorder.Recorder) (fantasy.LanguageModel, error) {
20+
provider, err := groq.New(
21+
groq.WithAPIKey(os.Getenv("FANTASY_GROQ_API_KEY")),
22+
groq.WithHTTPClient(&http.Client{Transport: r}),
23+
)
24+
if err != nil {
25+
return nil, err
26+
}
27+
return provider.LanguageModel(t.Context(), "moonshotai/kimi-k2-instruct-0905")
28+
}

providertests/huggingface_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package providertests
2+
3+
import (
4+
"net/http"
5+
"os"
6+
"testing"
7+
8+
"charm.land/fantasy"
9+
"charm.land/fantasy/providers/huggingface"
10+
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
11+
)
12+
13+
func TestHuggingFaceCommon(t *testing.T) {
14+
testCommon(t, []builderPair{
15+
{"huggingface-glm-4.6", builderHuggingFaceProvider, nil, nil},
16+
})
17+
}
18+
19+
func builderHuggingFaceProvider(t *testing.T, r *recorder.Recorder) (fantasy.LanguageModel, error) {
20+
provider, err := huggingface.New(
21+
huggingface.WithAPIKey(os.Getenv("FANTASY_HUGGINGFACE_API_KEY")),
22+
huggingface.WithHTTPClient(&http.Client{Transport: r}),
23+
)
24+
if err != nil {
25+
return nil, err
26+
}
27+
return provider.LanguageModel(t.Context(), "zai-org/GLM-4.6")
28+
}

providertests/testdata/TestCerebrasCommon/cerebras-qwen-3-coder-480b/multi_tool.yaml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)