From c6449cd257f5fba987fc1c0b24beead08ad30112 Mon Sep 17 00:00:00 2001 From: kingmariano Date: Sat, 20 Jul 2024 17:13:46 +0100 Subject: [PATCH] feat: added shazam, youtube summarization, image2text, docGPT features. --- _examples/g4f/g4f.go | 4 +-- .../imageGeneration/highImageGenration.go | 2 +- docGPT.go | 30 +++++++++++++++++++ downloadMusic.go | 2 -- g4f.go | 4 +-- imageTotext.go | 25 ++++++++++++++++ response.go | 10 ++++--- searchMusic.go | 13 ++++---- shazam.go | 25 ++++++++++++++++ youtubeSummarization.go | 23 ++++++++++++++ 10 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 docGPT.go create mode 100644 imageTotext.go create mode 100644 shazam.go create mode 100644 youtubeSummarization.go diff --git a/_examples/g4f/g4f.go b/_examples/g4f/g4f.go index e1a6744..3c4056f 100644 --- a/_examples/g4f/g4f.go +++ b/_examples/g4f/g4f.go @@ -17,13 +17,13 @@ func main() { Messages: []omnicron.Message{ { Content: "What is the weather like in New York City?", - Role: "user", + Role: "user", }, }, }) if err != nil { fmt.Printf("Error: %v\n", err) - return + return } jsonData, err := json.MarshalIndent(g4fResponse, "", " ") if err != nil { diff --git a/_examples/imageGeneration/highImageGenration.go b/_examples/imageGeneration/highImageGenration.go index 0f9c860..e5c520e 100644 --- a/_examples/imageGeneration/highImageGenration.go +++ b/_examples/imageGeneration/highImageGenration.go @@ -57,7 +57,7 @@ func main() { return } - fmt.Println("JSON data written to file.json successfully" + fmt.Println("JSON data written to file.json successfully") // dynamically handle the response with the Gabs library: https://github.com/Jeffail/gabs/ outputText := res.Path("response.output").Data().(map[string]interface{}) fmt.Println(outputText) diff --git a/docGPT.go b/docGPT.go new file mode 100644 index 0000000..f54c1a9 --- /dev/null +++ b/docGPT.go @@ -0,0 +1,30 @@ +package omnicron + +import ( + "context" + "os" +) + +type DocGPTParams struct { + File *os.File `form:"file"` + Prompt string `form:"prompt"` +} + +func (c *Client) DocGPT(ctx context.Context, req DocGPTParams) (*GabsContainer, error) { + if req.File == nil { + return nil, ErrNoFileProvided + } + if req.Prompt == "" { + return nil, ErrPromptMissing + } + + body, err := c.newFormWithFilePostRequest(ctx, "/docgpt", "", req) + if err != nil { + return nil, err + } + docGPTResponse, err := unmarshalJSONResponse(body) + if err != nil { + return nil, err + } + return docGPTResponse, nil +} diff --git a/downloadMusic.go b/downloadMusic.go index 669e7a6..39b2d9d 100644 --- a/downloadMusic.go +++ b/downloadMusic.go @@ -8,8 +8,6 @@ type MusicRequest struct { Song string `json:"song"` } - - // the downloadMusic function takes a song as input, downloads the song and return the direct cloudinary url. something to note: use the search music function to get the song before using it as input. Do not use any song name directly to avoid inaccuracy. func (c *Client) DownloadMusic(ctx context.Context, req *MusicRequest) (*GabsContainer, error) { if req.Song == "" { diff --git a/g4f.go b/g4f.go index aaafed4..bddb0b3 100644 --- a/g4f.go +++ b/g4f.go @@ -13,7 +13,7 @@ type G4FRequest struct { } // this uses the g4f library by xtekky: https://github.com/xtekky/gpt4free -func (c *Client) GPT4Free(ctx context.Context, req *G4FRequest) (*GabsContainer, error){ +func (c *Client) GPT4Free(ctx context.Context, req *G4FRequest) (*GabsContainer, error) { if len(req.Messages) == 0 { return nil, ErrGroqChatCompletionNoMessage } @@ -26,4 +26,4 @@ func (c *Client) GPT4Free(ctx context.Context, req *G4FRequest) (*GabsContainer, return nil, err } return g4fResponse, nil -} \ No newline at end of file +} diff --git a/imageTotext.go b/imageTotext.go new file mode 100644 index 0000000..d4f17c4 --- /dev/null +++ b/imageTotext.go @@ -0,0 +1,25 @@ +package omnicron + +import ( + "context" + "os" +) + +type ImageToTextParams struct { + File *os.File `form:"file"` +} + +func (c *Client) ImageToText(ctx context.Context, params ImageToTextParams) (*GabsContainer, error) { + if params.File == nil { + return nil, ErrNoFileProvided + } + body, err := c.newFormWithFilePostRequest(ctx, "/image2text", "", params) + if err != nil { + return nil, err + } + imageToTextResponse, err := unmarshalJSONResponse(body) + if err != nil { + return nil, err + } + return imageToTextResponse, nil +} diff --git a/response.go b/response.go index 99e551c..56ada9f 100644 --- a/response.go +++ b/response.go @@ -3,12 +3,14 @@ package omnicron import ( "github.com/Jeffail/gabs/v2" ) -//using the gabs library for dynamic JSON handling + +// using the gabs library for dynamic JSON handling type GabsContainer = gabs.Container + func unmarshalJSONResponse(body []byte) (*GabsContainer, error) { container, err := gabs.ParseJSON(body) - if err!= nil { - return nil, err - } + if err != nil { + return nil, err + } return container, nil } diff --git a/searchMusic.go b/searchMusic.go index 521f8b4..ea9e170 100644 --- a/searchMusic.go +++ b/searchMusic.go @@ -7,18 +7,19 @@ type MusicSearchRequest struct { Limit int `json:"limit,omitempty"` Proxy string `json:"proxy,omitempty"` } + // this function takes a song as input and returns a list of matching songs. Use the DownloadMusic function to download the song. -func (c *Client) MusicSearch(ctx context.Context, req *MusicSearchRequest)(*GabsContainer, error){ - if req.Song == ""{ +func (c *Client) MusicSearch(ctx context.Context, req *MusicSearchRequest) (*GabsContainer, error) { + if req.Song == "" { return nil, ErrSongNotProvided } body, err := c.newJSONPostRequest(ctx, "/musicsearch", "", req) - if err!= nil{ - return nil, err - } + if err != nil { + return nil, err + } musicSearchResponse, err := unmarshalJSONResponse(body) if err != nil { return nil, err } return musicSearchResponse, nil -} \ No newline at end of file +} diff --git a/shazam.go b/shazam.go new file mode 100644 index 0000000..a10f95d --- /dev/null +++ b/shazam.go @@ -0,0 +1,25 @@ +package omnicron + +import ( + "context" + "os" +) + +type ShazamParams struct { + File *os.File `form:"file"` +} + +func (c *Client) Shazam(ctx context.Context, params ShazamParams) (*GabsContainer, error) { + if params.File == nil { + return nil, ErrNoFileProvided + } + body, err := c.newFormWithFilePostRequest(ctx, "/shazam", "", params) + if err != nil { + return nil, err + } + shazamResponse, err := unmarshalJSONResponse(body) + if err != nil { + return nil, err + } + return shazamResponse, nil +} diff --git a/youtubeSummarization.go b/youtubeSummarization.go new file mode 100644 index 0000000..4f9109d --- /dev/null +++ b/youtubeSummarization.go @@ -0,0 +1,23 @@ +package omnicron + +import "context" + +type YoutubeSummarizationParams struct { + URL string `json:"url"` +} + +func (c *Client) YoutubeSummarization(ctx context.Context, params *YoutubeSummarizationParams) (*GabsContainer, error) { + if params.URL == "" { + return nil, ErrVideoDownloadNoURLProvided + } + body, err := c.newJSONPostRequest(ctx, "/youtubesummarization", "", params) + if err != nil { + return nil, err + } + youtubeSummarizationResponse, err := unmarshalJSONResponse(body) + if err != nil { + return nil, err + } + return youtubeSummarizationResponse, nil + +}