Skip to content
Merged
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
19 changes: 1 addition & 18 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Client struct {

baseURL string
apiKey string
region Region
}

// Option defines a configuration option for the Client.
Expand All @@ -48,13 +47,6 @@ func WithAPIKey(key string) Option {
}
}

// WithRegion sets the region to use for the client.
func WithRegion(region Region) Option {
return func(c *Client) {
c.region = region
}
}

// WithHTTPClient sets the HTTP client to use for the client.
func WithHTTPClient(client *http.Client) Option {
return func(c *Client) {
Expand All @@ -66,22 +58,13 @@ func WithHTTPClient(client *http.Client) Option {
func NewClient(opts ...Option) *Client {
client := &Client{
httpClient: http.DefaultClient,
region: RegionEU,
baseURL: "https://api.eu.tensorlake.ai/documents/v2",
baseURL: EndpointEU,
apiKey: os.Getenv("TENSORLAKE_API_KEY"),
}

for _, opt := range opts {
opt(client)
}

// For non on-premise regions, use the default base URL.
switch client.region {
case RegionEU:
client.baseURL = "https://api.eu.tensorlake.ai/documents/v2"
case RegionUS:
client.baseURL = "https://api.tensorlake.ai/documents/v2"
}
return client
}

Expand Down
27 changes: 1 addition & 26 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,21 @@ func TestNewClient(t *testing.T) {
}
})

t.Run("with custom region", func(t *testing.T) {
client := NewClient(WithRegion(RegionUS))

if client == nil {
t.Fatal("NewClient returned nil")
}
})

t.Run("with custom API key", func(t *testing.T) {
client := NewClient(WithAPIKey("test-key"))

if client == nil {
t.Fatal("NewClient returned nil")
}
})

t.Run("with custom base URL and region", func(t *testing.T) {
client := NewClient(WithBaseURL("https://api.custom.com"), WithRegion(RegionUS))

if client == nil {
t.Fatal("NewClient returned nil")
}
})

t.Run("with on-premise region", func(t *testing.T) {
client := initializeTestClient(t)

if client == nil {
t.Fatal("NewClient returned nil")
}
})
}

func initializeTestClient(t *testing.T) *Client {
base := os.Getenv("TENSORLAKE_BASE_URL")
apiKey := os.Getenv("TENSORLAKE_API_KEY")
region := RegionUS
if base == "" || apiKey == "" {
t.Skip("TENSORLAKE_BASE_URL and TENSORLAKE_API_KEY must be set")
}

return NewClient(WithBaseURL(base), WithAPIKey(apiKey), WithRegion(region))
return NewClient(WithBaseURL(base), WithAPIKey(apiKey))
}
1 change: 0 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
// Create a client with your API key:
//
// c := tensorlake.NewClient(
// tensorlake.WithRegion(tensorlake.RegionOnPrem),
// tensorlake.WithBaseURL("https://api.your-domain.com"),
// tensorlake.WithAPIKey("your-api-key"),
// )
Expand Down
23 changes: 15 additions & 8 deletions enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@

package tensorlake

type Region string

const (
// RegionEU is the European region.
RegionEU Region = "eu"
// RegionUS is the United States region.
RegionUS Region = "us"
// RegionOnPrem is the on-premise setup.
RegionOnPrem Region = "onprem"
// EndpointEU is the European endpoint.
EndpointEU string = "https://api.eu.tensorlake.ai/documents/v2"
// EndpointUS is the United States endpoint.
EndpointUS string = "https://api.tensorlake.ai/documents/v2"
)

// ChunkingStrategy determines how the document is chunked into smaller pieces.
Expand Down Expand Up @@ -247,3 +243,14 @@ const (
DatasetStatusIdle DatasetStatus = "idle"
DatasetStatusProcessing DatasetStatus = "processing"
)

type JobType string

const (
JobTypeParse JobType = "parse"
JobTypeRead JobType = "read"
JobTypeExtract JobType = "extract"
JobTypeClassify JobType = "classify"
JobTypeLegacy JobType = "legacy"
JobTypeDataset JobType = "dataset"
)