Skip to content

Commit

Permalink
feat: added shazam, youtube summarization, image2text, docGPT features.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingmariano committed Jul 20, 2024
1 parent f734c1c commit c6449cd
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 17 deletions.
4 changes: 2 additions & 2 deletions _examples/g4f/g4f.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion _examples/imageGeneration/highImageGenration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions docGPT.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 0 additions & 2 deletions downloadMusic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
4 changes: 2 additions & 2 deletions g4f.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -26,4 +26,4 @@ func (c *Client) GPT4Free(ctx context.Context, req *G4FRequest) (*GabsContainer,
return nil, err
}
return g4fResponse, nil
}
}
25 changes: 25 additions & 0 deletions imageTotext.go
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 6 additions & 4 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 7 additions & 6 deletions searchMusic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
25 changes: 25 additions & 0 deletions shazam.go
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 23 additions & 0 deletions youtubeSummarization.go
Original file line number Diff line number Diff line change
@@ -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

}

0 comments on commit c6449cd

Please sign in to comment.