together package - github.com/maxnystrom/together-go - Go Packages

together

package module
v0.0.0-...-3a34121 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: BSD-3-Clause Imports: 14 Imported by: 0

README

together-go

Go Test codecov

Note: This library is a proof-of-concept and is not yet feature-complete nor should be considered production ready.

A Go library for interacting with

Together AI's API. This library allows you to:

  • Interact with chat and moderation models
  • Interact with language, code, and image models
  • Embed models
  • Fine-tune models

Installation

You need a working Go environment. Only Go versions according to Go project's release policy are currently supported.

go get github.com/maxnystrom/together-go

Getting Started

package main

import (
   "context"
   "encoding/json"
   "fmt"
   "log"
   "os"
  
   "go get github.com/maxnystrom/together-go"
)

func main() {
  // Construct a new API object using a global API key
  api, err := together.New(os.Getenv("TOGETHER_API_KEY"))
  if err != nil {
    log.Fatal(err)
  }

  // Most API calls require a Context
  ctx := context.Background()
  
  // List running instances
  r, err := api.ListRunningInstances(ctx)
  if err != nil {
    log.Fatal(err)
  }
  
  // Print instance details
  prettyPrint, _ := json.Marshal(r)
  fmt.Println(string(prettyPrint))
}

Contributing

Pull Requests are welcome, but please open an issue (or comment in an existing issue) to discuss any non-trivial changes before submitting code.

License

BSD licensed. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version string = "v1" // This corresponds to the version of the API and is used in the URL path
)

Functions

This section is empty.

Types

type API

type API struct {
	APIKey    string
	BaseURL   string
	UserAgent string

	Client *retryablehttp.Client
	Debug  bool
	// contains filtered or unexported fields
}

func New

func New(key string) (*API, error)

func (*API) ChatCompletions

func (api *API) ChatCompletions(ctx context.Context, model string, messages []Message, request ChatCompletionsRequest) (ChatCompletionsResponse, error)

Chat Completions is the endpoint for chat and moderation models on Together AI.

API Reference: https://docs.together.ai/reference/chat-completions

func (*API) Completions

func (api *API) Completions(ctx context.Context, model string, prompt string, maxTokens int32, request CompletionsRequest) (CompletionsResponse, error)

Completions is the endpoint for language, code, and image models on Together AI.

API Reference: https://docs.together.ai/reference/completions

func (*API) Embeddings

func (api *API) Embeddings(ctx context.Context, model string, input string, request EmbeddingsRequest) (EmbeddingsResponse, error)

Embeddings is the endpoint for embedding models on Together AI.

API Reference: https://docs.together.ai/reference/embeddings

func (*API) ListRunningInstances

func (api *API) ListRunningInstances(ctx context.Context) (FineTuningResponse, error)

List Running Instances is the endpoint for listing running fine-tuning instances.

API Reference: https://docs.together.ai/reference/instances

func (*API) StartFineTunedInstance

func (api *API) StartFineTunedInstance(ctx context.Context, name string) (FineTuningResponse, error)

Start Fine-tuned Instance is the endpoint for starting a fine-tuned model.

API Reference: https://docs.together.ai/reference/instances-start

func (*API) StopFineTunedInstance

func (api *API) StopFineTunedInstance(ctx context.Context, name string) (FineTuningResponse, error)

Stop Fine-tuned Instance is the endpoint for stopping a fine-tuned model.

API Reference: https://docs.together.ai/reference/instances-stop

type Args

type Args struct {
	Model       string  `json:"model"`
	Prompt      string  `json:"prompt"`
	Temperature float64 `json:"temperature"`
	TopP        float64 `json:"top_p"`
	TopK        int     `json:"top_k"`
	MaxTokens   int     `json:"max_tokens"`
}

type ChatCompletionsRequest

type ChatCompletionsRequest struct {
	Model             string               `json:"model"`
	Messages          []Message            `json:"messages"`
	Stream            bool                 `json:"stream"`
	MaxTokens         int32                `json:"max_tokens"`
	Stop              []string             `json:"stop"`
	Temperature       float64              `json:"temperature"`
	TopP              float64              `json:"top_p"`
	TopK              int32                `json:"top_k"`
	RepetitionPenalty float64              `json:"repetition_penalty"`
	Logprobs          int32                `json:"logprobs"`
	Echo              bool                 `json:"echo"`
	N                 int32                `json:"n"`
	SafetyModel       string               `json:"safety_model"`
	ResponseFormat    ResponseFormatObject `json:"response_format"`
	Tools             []Tool               `json:"tools"`
	ToolChoice        []ToolChoiceObject   `json:"tool_choice"`
	FrequencyPenalty  float64              `json:"frequency_penalty"`
	PresencePenalty   float64              `json:"presence_penalty"`
	MinP              float64              `json:"min_p"`
}

type ChatCompletionsResponse

type ChatCompletionsResponse struct {
	Id      string      `json:"id"`
	Choices []Message   `json:"choices"`
	Usage   UsageObject `json:"usage"`
	Created int         `json:"created"`
	Model   string      `json:"model"`
	Object  string      `json:"object"`
}

type Choice

type Choice struct {
	FinishReason string `json:"finish_reason"`
	Index        int    `json:"index"`
	Text         string `json:"text"`
}

type ChoiceObject

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

type CompletionsRequest

type CompletionsRequest struct {
	Model             string   `json:"model"`
	Prompt            string   `json:"prompt"`
	MaxTokens         int32    `json:"max_tokens"`
	Stream            bool     `json:"stream"`
	Stop              []string `json:"stop"`
	Temperature       float64  `json:"temperature"`
	TopP              float64  `json:"top_p"`
	TopK              int32    `json:"top_k"`
	RepetitionPenalty float64  `json:"repetition_penalty"`
	Logprobs          int32    `json:"logprobs"`
	Echo              bool     `json:"echo"`
	N                 int32    `json:"n"`
	SafetyModel       string   `json:"safety_model"`
}

type CompletionsResponse

type CompletionsResponse struct {
	Id      string         `json:"id"`
	Choices []ChoiceObject `json:"choices"`
	Usage   UsageObject    `json:"usage"`
	Created int            `json:"created"`
	Model   string         `json:"model"`
	Object  string         `json:"object"`
}

type EmbeddingsRequest

type EmbeddingsRequest struct {
	Model string `json:"model"`
	Input string `json:"input"`
}

type EmbeddingsResponse

type EmbeddingsResponse struct {
	Status     string   `json:"status"`
	Prompt     []string `json:"prompt"`
	Model      string   `json:"model"`
	ModelOwner string   `json:"model_owner"`
	Tags       Tags     `json:"tags"`
	NumReturns int      `json:"num_returns"`
	Args       Args     `json:"args"`
	Subjobs    []Subjob `json:"subjobs"`
	Output     Output   `json:"output"`
}

type FineTuningResponse

type FineTuningResponse struct {
	Status     string   `json:"status"`
	Prompt     []string `json:"prompt"`
	Model      string   `json:"model"`
	ModelOwner string   `json:"model_owner"`
	Tags       Tags     `json:"tags"` // API Documentation states this is an object, but does not define it or provide an example.
	NumReturns int      `json:"num_returns"`
	Args       Args     `json:"args"`
	Subjobs    []Subjob `json:"subjobs"` // API Documentation states this is an array, but does not define it or provide an example.
	Output     Output   `json:"output"`
}

type FunctionObject

type FunctionObject struct {
	Description string          `json:"description"`
	Name        string          `json:"name"`
	Parameters  json.RawMessage `json:"parameters"` // maybe should be *json.RawMessage ?
}

type Message

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

type Output

type Output struct {
	Choices        []Choice `json:"choices"`
	RawComputeTime float64  `json:"raw_compute_time"`
	ResultType     string   `json:"result_type"`
}

type ResponseFormatObject

type ResponseFormatObject struct {
	Type   string          `json:"type"`
	Schema json.RawMessage `json:"schema"` // maybe should be *json.RawMessage ?
}

type Subjob

type Subjob struct{} // TODO: define Subjob.

type Tags

type Tags struct{} // TODO: define Tags.

type Tool

type Tool struct {
	Type     string         `json:"type"`
	Function FunctionObject `json:"function"`
}

type ToolChoiceObject

type ToolChoiceObject struct {
	Type     string         `json:"type"`
	Function FunctionObject `json:"function"`
}

type UsageObject

type UsageObject struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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