-
Notifications
You must be signed in to change notification settings - Fork 1
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
765c44c
commit 594ad68
Showing
25 changed files
with
660 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.23.1 | ||
1.23.2 |
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
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 @@ | ||
# jigsawstack |
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,13 @@ | ||
package jigsawstack | ||
|
||
// https://api.jigsawstack.com/v1/ai/tts | ||
|
||
// https://docs.jigsawstack.com/api-reference/ai/text-to-speech | ||
|
||
// TODO: implement audio tts | ||
|
||
// https://api.jigsawstack.com/v1/ai/tts | ||
|
||
// https://docs.jigsawstack.com/api-reference/audio/speaker-voice-accents | ||
|
||
// TODO: implement get audio speaker voice accents |
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,6 @@ | ||
package jigsawstack | ||
|
||
// https://docs.jigsawstack.com/api-reference/store/file/add | ||
// https://docs.jigsawstack.com/api-reference/store/file/get | ||
// https://docs.jigsawstack.com/api-reference/store/file/delete | ||
// Upload Retrieve Delete |
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,13 @@ | ||
package jigsawstack | ||
|
||
// https://api.jigsawstack.com/v1/geo/search | ||
|
||
// https://docs.jigsawstack.com/api-reference/geo/search | ||
|
||
// TODO: Add geo search | ||
|
||
// https://api.jigsawstack.com/v1/geo/geocode | ||
|
||
// https://docs.jigsawstack.com/api-reference/geo/geocode | ||
|
||
// TODO: Add geocode |
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,62 @@ | ||
package jigsawstack | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/conneroisu/groq-go/pkg/builders" | ||
) | ||
|
||
const ( | ||
imageGenerationEndpoint = "v1/ai/image_generation" | ||
) | ||
|
||
// model | ||
// string | ||
// default: "sdxl" | ||
// | ||
// The model to use for the generation. Default is sdxl | ||
// | ||
// sd1.5 - Stable Diffusion v1.5 | ||
// sdxl - Stable Diffusion XL | ||
// ead1.0 - Anime Diffusion | ||
// rv1.3 - Realistic Vision v1.3 | ||
// rv3 - Realistic Vision v3 | ||
// rv5.1 - Realistic Vision v5.1 | ||
// ar1.8 - AbsoluteReality v1.8.1 | ||
type ( | ||
ImageGenerationRequest struct { | ||
Prompt string `json:"prompt"` | ||
Model string `json:"model,omitempty"` | ||
Size string `json:"size"` | ||
Width int `json:"width"` | ||
Height int `json:"height"` | ||
} | ||
ImageGenerationResponse struct { | ||
Success bool `json:"success"` | ||
Image string `json:"image"` | ||
} | ||
) | ||
|
||
// Default is sdxl | ||
func (j *JigsawStack) ImageGeneration( | ||
ctx context.Context, | ||
request ImageGenerationRequest, | ||
) (response ImageGenerationResponse, err error) { | ||
req, err := builders.NewRequest( | ||
ctx, | ||
j.header, | ||
http.MethodPost, | ||
j.baseURL+imageGenerationEndpoint, | ||
builders.WithBody(request), | ||
) | ||
if err != nil { | ||
return | ||
} | ||
var resp ImageGenerationResponse | ||
err = j.sendRequest(req, &resp) | ||
if err != nil { | ||
return | ||
} | ||
return resp, 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,98 @@ | ||
package jigsawstack | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
"net/http" | ||
|
||
"github.com/conneroisu/groq-go/pkg/builders" | ||
) | ||
|
||
const ( | ||
defaultBaseURL = "https://api.jigsawstack.com" | ||
) | ||
|
||
type ( | ||
// JigsawStack is a JigsawStack extension. | ||
JigsawStack struct { | ||
baseURL string | ||
client *http.Client | ||
logger *slog.Logger | ||
header builders.Header | ||
} | ||
// Option is an option for the JigsawStack client. | ||
Option func(*JigsawStack) | ||
// Endpoint is the endpoint for the JigsawStack api. | ||
Endpoint string | ||
) | ||
|
||
// NewJigsawStack creates a new JigsawStack extension. | ||
func NewJigsawStack(apiKey string, opts ...Option) (*JigsawStack, error) { | ||
j := &JigsawStack{ | ||
baseURL: defaultBaseURL, | ||
client: http.DefaultClient, | ||
logger: slog.Default(), | ||
} | ||
for _, opt := range opts { | ||
opt(j) | ||
} | ||
j.header.SetCommonHeaders = func(req *http.Request) { | ||
req.Header.Set("x-api-key", apiKey) | ||
req.Header.Set("Content-Type", "application/json") | ||
req.Header.Set("Accept", "application/json") | ||
} | ||
return j, nil | ||
} | ||
|
||
// WithBaseURL sets the base URL for the JigsawStack extension. | ||
func WithBaseURL(baseURL string) Option { | ||
return func(j *JigsawStack) { j.baseURL = baseURL } | ||
} | ||
|
||
// WithClient sets the client for the JigsawStack extension. | ||
func WithClient(client *http.Client) Option { | ||
return func(j *JigsawStack) { j.client = client } | ||
} | ||
|
||
// WithLogger sets the logger for the JigsawStack extension. | ||
func WithLogger(logger *slog.Logger) Option { | ||
return func(j *JigsawStack) { j.logger = logger } | ||
} | ||
|
||
func (j *JigsawStack) sendRequest(req *http.Request, v any) error { | ||
j.header.SetCommonHeaders(req) | ||
resp, err := j.client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode < http.StatusOK || | ||
resp.StatusCode >= http.StatusBadRequest { | ||
return nil | ||
} | ||
if v == nil { | ||
return nil | ||
} | ||
switch o := v.(type) { | ||
case *string: | ||
b, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
*o = string(b) | ||
return nil | ||
default: | ||
err = json.NewDecoder(resp.Body).Decode(v) | ||
if err != nil { | ||
read, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
j.logger.Debug("failed to decode response", "response", string(read)) | ||
return fmt.Errorf("failed to decode response: %w\nbody: %s", err, string(read)) | ||
} | ||
return 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 @@ | ||
package jigsawstack |
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,7 @@ | ||
package jigsawstack | ||
|
||
// https://docs.jigsawstack.com/api-reference/store/kv/get | ||
// https://docs.jigsawstack.com/api-reference/store/kv/add | ||
// https://docs.jigsawstack.com/api-reference/store/kv/delete | ||
|
||
// Add Get Delete |
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,55 @@ | ||
package jigsawstack | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/conneroisu/groq-go/pkg/builders" | ||
) | ||
|
||
const ( | ||
predictEndpoint Endpoint = "v1/ai/prediction" | ||
) | ||
|
||
type ( | ||
// DatasetEntry represents a dataset entry. | ||
DatasetEntry struct { | ||
Date time.Time `json:"date"` | ||
Value float64 `json:"value"` | ||
} | ||
// PredictRequest represents a request structure for prediction API. | ||
PredictRequest struct { | ||
Dataset []DatasetEntry `json:"dataset"` | ||
} | ||
// PredictResponse represents a response structure for prediction API. | ||
PredictResponse struct { | ||
Success bool `json:"success"` | ||
Answer []DatasetEntry `json:"answer"` | ||
} | ||
) | ||
|
||
// Predict predicts the text. | ||
// | ||
// Max text character is 5000. | ||
func (j *JigsawStack) Predict( | ||
ctx context.Context, | ||
request PredictRequest, | ||
) (response PredictResponse, err error) { | ||
req, err := builders.NewRequest( | ||
ctx, | ||
j.header, | ||
http.MethodPost, | ||
j.baseURL+string(predictEndpoint), | ||
builders.WithBody(request), | ||
) | ||
if err != nil { | ||
return | ||
} | ||
var resp PredictResponse | ||
err = j.sendRequest(req, &resp) | ||
if err != nil { | ||
return | ||
} | ||
return resp, 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,5 @@ | ||
package jigsawstack | ||
|
||
// https://docs.jigsawstack.com/api-reference/prompt-engine/create | ||
|
||
// TODO: implement prompt create |
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,7 @@ | ||
package jigsawstack | ||
|
||
// https://api.jigsawstack.com/v1/prompt_engine/{id} | ||
|
||
// https://docs.jigsawstack.com/api-reference/prompt-engine/delete | ||
|
||
// TODO: add support for deleting a prompt |
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,11 @@ | ||
package jigsawstack | ||
|
||
// https://api.jigsawstack.com/v1/prompt_engine/{id} | ||
|
||
// https://docs.jigsawstack.com/api-reference/prompt-engine/retrieve | ||
|
||
// TODO: add support for retrieving a specific prompt | ||
|
||
// https://docs.jigsawstack.com/api-reference/prompt-engine/list | ||
|
||
// TODO: add support for listing prompts |
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,11 @@ | ||
package jigsawstack | ||
|
||
// https://api.jigsawstack.com/v1/prompt_engine/{id} | ||
|
||
// https://docs.jigsawstack.com/api-reference/prompt-engine/run | ||
|
||
// TODO: implement prompt run | ||
|
||
// TODO: implement prompt run direct | ||
// https://docs.jigsawstack.com/api-reference/prompt-engine/run-direct | ||
// https://api.jigsawstack.com/v1/prompt_engine/run |
Oops, something went wrong.