shuttle

package module
v0.0.0-...-287c6fe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 8 Imported by: 0

README

⚗️ go-shuttleai

Build Status Go Reference

The ShuttleAI Client in Golang is a modul designed to interact with the openai model repository for free and perform inference tasks using state-of-the-art natural language processing models. Developed in Golang, it provides a seamless and efficient way to integrate openai models into your Golang application.

Installation

go get github.com/charlesozo/go-shuttleai

Shuttle AI documentation

Visit Discord server to get the $SHUTTLE_API_KEY and Run /getkey command in the Discord server.

shuttle api docs

How to use

package main

import (
	"context"
	"fmt"
    "os"
	shuttleai "github.com/charlesozo/go-shuttleai"
)

func main(){
    client := shuttleai.NewClient(os.getenv("SHUTTLE_API_TOKEN"))
	response, err := client.ChatCompletion(context.Background(), &shuttleai.ChatRequest{
		Messages: []shuttleai.ChatMessage{
		  {
			Role: "user",
			Content: "write an essay on global warming",
		  },
		},
	})

	if err != nil{
		fmt.Println(err)
		return
	}
	fmt.Println(response.Choices[0].Message.Content)
}

Output:

response goes here

For more example usage, see _examples.

License

MIT

Documentation

Index

Constants

View Source
const APIBaseURL = "https://api.shuttleai.app"

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioGenRequest

type AudioGenRequest struct {
	//required
	Input string `json:"input"`

	//required
	Model string `json:"model"`

	//The voice to use for the generation > Voices can be found https://api.shuttleai.app/v1/models
	Voice *string `json:"voice,omitempty"`
}

type AudioGenResponse

type AudioGenResponse struct {
	Data struct {
		URL string `json:"url"`
	} `json:"data"`
	ExpiresIn int    `json:"expiresIn"`
	Model     string `json:"model"`
	Chars     int    `json:"chars"`
}

type AudioTranscribeRequest

type AudioTranscribeRequest struct {
	File []byte `json:"file"`
}

type AudioTranscribeResponse

type AudioTranscribeResponse struct {
	Text string `json:"text"`
}

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ChatRequest

type ChatRequest struct {
	//Required
	Messages []ChatMessage `json:"messages"`

	//The id of the model to use for the generation
	Model string `json:"model"`

	//Whether to include citations in the generation > For use in owned_by: bing/openai models only, defaults to true.
	Citations *bool `json:"citations,omitempty"`

	Image *string `json:"image,omitempty"`

	//Whether to use the internet for the generation > Model limitations apply, defaults to true for bing models.
	Internet *bool `json:"internet,omitempty"`

	//The maximum number of tokens to generate
	MaxToken *int `json:"max_token,omitempty"`

	//Whether to return the raw response > For use in owned_by: bing/openai models only! Returns Bing AI Suggestions and Search Results, defaults to false.
	Raw *bool `json:"raw,omitempty"`

	//The temperature of the sampling distribution
	Temperature *int `json:"temperature,omitempty"`

	//The tone of the generation > For use in owned_by: bing/openai models only, defaults to precise.
	Tone *string `json:"tone,omitempty"`

	//The cumulative probability of the top tokens to keep in the nucleus of the distribution
	TopP *int `json:"top_p,omitempty"`
}

type ChatResponse

type ChatResponse struct {
	Choices []struct {
		FinishReason string `json:"finish_reason"`
		Index        int    `json:"index"`
		Logprobs     struct {
		} `json:"logprobs"`
		Message struct {
			Content string `json:"content"`
			Role    string `json:"role"`
		} `json:"message"`
	} `json:"choices"`
	Created           int    `json:"created"`
	ID                string `json:"id"`
	Model             string `json:"model"`
	Object            string `json:"object"`
	SystemFingerprint string `json:"system_fingerprint"`
	Usage             struct {
		CompletionTokens int `json:"completion_tokens"`
		PromptTokens     int `json:"prompt_tokens"`
		TotalTokens      int `json:"total_tokens"`
	} `json:"usage"`
}

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type ImageRequest

type ImageRequest struct {
	Model  string `json:"model"`
	Prompt string `json:"prompt"`
}

type ImageResponse

type ImageResponse struct {
	Created int `json:"created"`
	Data    []struct {
		URL string `json:"url"`
	} `json:"data"`
}

type ModelResponse

type ModelResponse []struct {
	Data []struct {
		Cost    int    `json:"cost"`
		Created int    `json:"created"`
		ID      string `json:"id"`
		Object  string `json:"object"`
		OwnedBy string `json:"owned_by"`
		Premium bool   `json:"premium"`
		Tokens  int    `json:"tokens"`
	} `json:"data"`
	Object string `json:"object"`
}

example of endpoint: /v1/images/generations

type ShuttleClient

type ShuttleClient struct {
	Httpclient HTTPClient
	ApiKey     string
	Baseurl    string
}

func NewClient

func NewClient(apikey string) *ShuttleClient

func (*ShuttleClient) AudioGeneration

func (sh *ShuttleClient) AudioGeneration(ctx context.Context, req *AudioGenRequest) (*AudioGenResponse, error)

func (*ShuttleClient) ChatCompletion

func (sh *ShuttleClient) ChatCompletion(ctx context.Context, req *ChatRequest) (*ChatResponse, error)

func (*ShuttleClient) GetModelByEndpoint

func (sh *ShuttleClient) GetModelByEndpoint(endpoint string) (*ModelResponse, error)

func (*ShuttleClient) GetModels

func (sh *ShuttleClient) GetModels() (*ModelResponse, error)

func (*ShuttleClient) ImageGeneration

func (sh *ShuttleClient) ImageGeneration(ctx context.Context, req *ImageRequest) (*ImageResponse, error)

func (*ShuttleClient) TranscribeAudio

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL