togetherai

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 3 Imported by: 0

README

together-ai-go

Unofficial API library for together.ai

Quickstart

Create a new client
client := togetherai.NewClient(os.Getenv("TOGETHERAI_API_KEY"))
Infer with a model
resp, err := client.NewInference(InferenceConfig{
    Model:     "togethercomputer/RedPajama-INCITE-7B-Instruct",
    Prompt:    "The capital of France is",
    MaxTokens: 128,
    Stop:      &stopStrings,
})
if err != nil {
    panic(err)
}

fmt.Println(resp.Output.Choices)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	APIKey string
}

func NewClient

func NewClient(apiKey string) *Client

NewClient creates a new instance of Client.

It takes an apiKey string as a parameter and returns a pointer to a Client.

func (*Client) NewInference

func (c *Client) NewInference(config InferenceConfig) (respBody *InferenceResponseBody, err error)

NewInference creates a new inference using the provided configuration.

config: The configuration for the inference. respBody: The response body containing the inference result. err: An error if the inference creation fails.

type InferenceConfig

type InferenceConfig struct {
	Model             string    `json:"model"`
	Prompt            string    `json:"prompt"`
	MaxTokens         int32     `json:"max_tokens"`
	Stop              *[]string `json:"stop"`
	Temperature       *float32  `json:"temperature"`
	TopP              *float32  `json:"top_p"`
	TopK              *int32    `json:"top_k"`
	RepetitionPenalty *float32  `json:"repetition_penalty"`
	LogProbs          *int32    `json:"logprobs"`
}

type InferenceResponseBody

type InferenceResponseBody struct {
	Status     string   `json:"status"`
	Prompt     []string `json:"prompt"`
	Model      string   `json:"model"`
	ModelOwner string   `json:"model_owner"`
	Tags       struct {
	} `json:"tags"`
	NumReturns int `json:"num_returns"`
	Args       struct {
		Model             string   `json:"model"`
		Prompt            string   `json:"prompt"`
		MaxTokens         int      `json:"max_tokens"`
		Stop              []string `json:"stop"`
		Temperature       float64  `json:"temperature"`
		TopP              float64  `json:"top_p"`
		TopK              int      `json:"top_k"`
		RepetitionPenalty int      `json:"repetition_penalty"`
	} `json:"args"`
	Subjobs []interface{} `json:"subjobs"`
	Output  struct {
		Choices []struct {
			FinishReason string `json:"finish_reason"`
			Index        int    `json:"index"`
			Text         string `json:"text"`
		} `json:"choices"`
		RawComputeTime float64 `json:"raw_compute_time"`
		ResultType     string  `json:"result_type"`
	} `json:"output"`
}

Jump to

Keyboard shortcuts

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