Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions providers/cerebras/cerebras.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Package cerebras provides a Fantasy provider for the Cerebras Inference API.
package cerebras

import (
"charm.land/fantasy"
"charm.land/fantasy/providers/openaicompat"
)

const (
// Name is the provider identifier for Cerebras.
Name = "cerebras"
// BaseURL is the default Cerebras API base URL.
BaseURL = "https://api.cerebras.ai/v1"
)

// Option configures the Cerebras provider via OpenAI-compatible options.
type Option = openaicompat.Option

var (
// WithBaseURL is an alias for openaicompat.WithBaseURL.
WithBaseURL = openaicompat.WithBaseURL
// WithAPIKey is an alias for openaicompat.WithAPIKey.
WithAPIKey = openaicompat.WithAPIKey
// WithHeaders is an alias for openaicompat.WithHeaders.
WithHeaders = openaicompat.WithHeaders
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
WithHTTPClient = openaicompat.WithHTTPClient
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
WithSDKOptions = openaicompat.WithSDKOptions
)

// New creates a new Cerebras provider using OpenAI-compatible transport/options.
func New(opts ...Option) (fantasy.Provider, error) {
options := []Option{
openaicompat.WithName(Name),
WithBaseURL(BaseURL),
}
options = append(options, opts...)
return openaicompat.New(options...)
}
40 changes: 40 additions & 0 deletions providers/groq/groq.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Package groq provides a Fantasy provider for the Groq API.
package groq

import (
"charm.land/fantasy"
"charm.land/fantasy/providers/openaicompat"
)

const (
// Name is the provider identifier for Groq.
Name = "groq"
// BaseURL is the default Groq API base URL.
BaseURL = "https://api.groq.com/openai/v1"
)

// Option configures the Groq provider via OpenAI-compatible options.
type Option = openaicompat.Option

var (
// WithBaseURL is an alias for openaicompat.WithBaseURL.
WithBaseURL = openaicompat.WithBaseURL
// WithAPIKey is an alias for openaicompat.WithAPIKey.
WithAPIKey = openaicompat.WithAPIKey
// WithHeaders is an alias for openaicompat.WithHeaders.
WithHeaders = openaicompat.WithHeaders
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
WithHTTPClient = openaicompat.WithHTTPClient
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
WithSDKOptions = openaicompat.WithSDKOptions
)

// New creates a new Groq provider using OpenAI-compatible transport/options.
func New(opts ...Option) (fantasy.Provider, error) {
options := []Option{
openaicompat.WithName(Name),
WithBaseURL(BaseURL),
}
options = append(options, opts...)
return openaicompat.New(options...)
}
40 changes: 40 additions & 0 deletions providers/huggingface/huggingface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Package huggingface provides a Fantasy provider for the Hugging Face Inference API.
package huggingface

import (
"charm.land/fantasy"
"charm.land/fantasy/providers/openaicompat"
)

const (
// Name is the provider identifier for Hugging Face.
Name = "huggingface"
// BaseURL is the default Hugging Face Inference API base URL.
BaseURL = "https://router.huggingface.co/v1"
)

// Option configures the Hugging Face provider via OpenAI-compatible options.
type Option = openaicompat.Option

var (
// WithBaseURL is an alias for openaicompat.WithBaseURL.
WithBaseURL = openaicompat.WithBaseURL
// WithAPIKey is an alias for openaicompat.WithAPIKey.
WithAPIKey = openaicompat.WithAPIKey
// WithHeaders is an alias for openaicompat.WithHeaders.
WithHeaders = openaicompat.WithHeaders
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
WithHTTPClient = openaicompat.WithHTTPClient
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
WithSDKOptions = openaicompat.WithSDKOptions
)

// New creates a new Hugging Face provider using OpenAI-compatible transport/options.
func New(opts ...Option) (fantasy.Provider, error) {
options := []Option{
openaicompat.WithName(Name),
WithBaseURL(BaseURL),
}
options = append(options, opts...)
return openaicompat.New(options...)
}
40 changes: 40 additions & 0 deletions providers/xai/xai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Package xai provides a Fantasy provider for the xAI API.
package xai

import (
"charm.land/fantasy"
"charm.land/fantasy/providers/openaicompat"
)

const (
// Name is the provider identifier for xAI.
Name = "xai"
// BaseURL is the default xAI API base URL.
BaseURL = "https://api.x.ai/v1"
)

// Option configures the xAI provider via OpenAI-compatible options.
type Option = openaicompat.Option

var (
// WithBaseURL is an alias for openaicompat.WithBaseURL.
WithBaseURL = openaicompat.WithBaseURL
// WithAPIKey is an alias for openaicompat.WithAPIKey.
WithAPIKey = openaicompat.WithAPIKey
// WithHeaders is an alias for openaicompat.WithHeaders.
WithHeaders = openaicompat.WithHeaders
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
WithHTTPClient = openaicompat.WithHTTPClient
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
WithSDKOptions = openaicompat.WithSDKOptions
)

// New creates a new xAI provider using OpenAI-compatible transport/options.
func New(opts ...Option) (fantasy.Provider, error) {
options := []Option{
openaicompat.WithName(Name),
WithBaseURL(BaseURL),
}
options = append(options, opts...)
return openaicompat.New(options...)
}
40 changes: 40 additions & 0 deletions providers/zai/zai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Package zai provides a Fantasy provider for the Z.ai Coding PaaS API.
package zai

import (
"charm.land/fantasy"
"charm.land/fantasy/providers/openaicompat"
)

const (
// Name is the provider identifier for Z.ai.
Name = "zai"
// BaseURL is the default Z.ai Coding PaaS API base URL.
BaseURL = "https://api.z.ai/api/coding/paas/v4"
)

// Option configures the Z.ai provider via OpenAI-compatible options.
type Option = openaicompat.Option

var (
// WithBaseURL is an alias for openaicompat.WithBaseURL.
WithBaseURL = openaicompat.WithBaseURL
// WithAPIKey is an alias for openaicompat.WithAPIKey.
WithAPIKey = openaicompat.WithAPIKey
// WithHeaders is an alias for openaicompat.WithHeaders.
WithHeaders = openaicompat.WithHeaders
// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
WithHTTPClient = openaicompat.WithHTTPClient
// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
WithSDKOptions = openaicompat.WithSDKOptions
)

// New creates a new Z.ai provider using OpenAI-compatible transport/options.
func New(opts ...Option) (fantasy.Provider, error) {
options := []Option{
openaicompat.WithName(Name),
WithBaseURL(BaseURL),
}
options = append(options, opts...)
return openaicompat.New(options...)
}
28 changes: 28 additions & 0 deletions providertests/cerebras_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package providertests

import (
"net/http"
"os"
"testing"

"charm.land/fantasy"
"charm.land/fantasy/providers/cerebras"
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
)

func TestCerebrasCommon(t *testing.T) {
testCommon(t, []builderPair{
{"cerebras-qwen-3-coder-480b", builderCerebras, nil, nil},
})
}

func builderCerebras(t *testing.T, r *recorder.Recorder) (fantasy.LanguageModel, error) {
provider, err := cerebras.New(
cerebras.WithAPIKey(os.Getenv("FANTASY_CEREBRAS_API_KEY")),
cerebras.WithHTTPClient(&http.Client{Transport: r}),
)
if err != nil {
return nil, err
}
return provider.LanguageModel(t.Context(), "qwen-3-coder-480b")
}
28 changes: 28 additions & 0 deletions providertests/groq_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package providertests

import (
"net/http"
"os"
"testing"

"charm.land/fantasy"
"charm.land/fantasy/providers/groq"
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
)

func TestGroqCommon(t *testing.T) {
testCommon(t, []builderPair{
{"groq-kimi-k2-0905", builderGroqProvider, nil, nil},
})
}

func builderGroqProvider(t *testing.T, r *recorder.Recorder) (fantasy.LanguageModel, error) {
provider, err := groq.New(
groq.WithAPIKey(os.Getenv("FANTASY_GROQ_API_KEY")),
groq.WithHTTPClient(&http.Client{Transport: r}),
)
if err != nil {
return nil, err
}
return provider.LanguageModel(t.Context(), "moonshotai/kimi-k2-instruct-0905")
}
28 changes: 28 additions & 0 deletions providertests/huggingface_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package providertests

import (
"net/http"
"os"
"testing"

"charm.land/fantasy"
"charm.land/fantasy/providers/huggingface"
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
)

func TestHuggingFaceCommon(t *testing.T) {
testCommon(t, []builderPair{
{"huggingface-glm-4.6", builderHuggingFaceProvider, nil, nil},
})
}

func builderHuggingFaceProvider(t *testing.T, r *recorder.Recorder) (fantasy.LanguageModel, error) {
provider, err := huggingface.New(
huggingface.WithAPIKey(os.Getenv("FANTASY_HUGGINGFACE_API_KEY")),
huggingface.WithHTTPClient(&http.Client{Transport: r}),
)
if err != nil {
return nil, err
}
return provider.LanguageModel(t.Context(), "zai-org/GLM-4.6")
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading