groq

package module
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: MIT Imports: 7 Imported by: 4

README

go-groq

A Go implementation of the Groq API.

Groq API is a super fast way to query open source llms.

Installation

go get github.com/conneroisu/go-groq

Examples

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Messages  []Message `json:"messages"`
	Model     string    `json:"model"`
	TopP      float64   `json:"top_p"`
	MaxTokens int       `json:"max_tokens"`
	Stop      []string  `json:"stop,omitempty"`
	Seed      int       `json:"seed"`
	Stream    bool      `json:"stream"`
	Format    struct {
		Type Format `json:"type"`
	} `json:"response_format"`
}

ChatRequest is a request to the chat endpoint.

type ChatResponse

type ChatResponse struct {
	Id      string `json:"id"`
	Object  string `json:"object"`
	Created int    `json:"created"`
	Model   string `json:"model"`
	Choices []struct {
		Index   int `json:"index"`
		Message struct {
			Role    string `json:"role"`
			Content string `json:"content"`
		} `json:"message"`
		Logprobs     interface{} `json:"logprobs"`
		FinishReason string      `json:"finish_reason"`
	} `json:"choices"`
	Usage struct {
		PromptTokens     int     `json:"prompt_tokens"`
		PromptTime       float64 `json:"prompt_time"`
		CompletionTokens int     `json:"completion_tokens"`
		CompletionTime   float64 `json:"completion_time"`
		ToTalTokens      int     `json:"to tal_tokens"`
		TotalTime        float64 `json:"total_time"`
	} `json:"usage"`
	SystemFingerprint string `json:"system_fingerprint"`
	XGroq             struct {
		Id string `json:"id"`
	} `json:"x_groq"`
}

ChatResponse is a response from the chat endpoint.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Groq api client.

func NewClient

func NewClient(groqApiKey string, opts ...GroqOpts) (*Client, error)

NewClient creates a new Groq client.

func (*Client) Chat

func (c *Client) Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)

Chat sends a request to the chat endpoint of the Groq API.

func (*Client) GetModels

func (c *Client) GetModels() error

GetModels gets the list of models from the Groq API.

type Format

type Format string

Format is the format of a response. string

const (
	// FormatText is the text format. It is the default format of a
	// response.
	FormatText Format = "text"
	// FormatJSON is the JSON format. There is no support for streaming with
	// JSON format selected.
	FormatJSON Format = "json"
)

type GroqOpts

type GroqOpts func(*Client)

GroqOpts is a function that sets options for a Groq client.

func WithClient

func WithClient(client *http.Client) GroqOpts

WithClient sets the client for the Groq client.

type Helper

type Helper interface {
	error
	Advice() string
}

Helper is an interface for error helpers

type Message

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

Message is a message in a chat request.

type ModelResponse

type ModelResponse struct {
	Object string `json:"object"`
	Data   []struct {
		ID             string `json:"id"`
		Object         string `json:"object"`
		Created        int    `json:"created"`
		OwnedBy        string `json:"owned_by"`
		Active         bool   `json:"active"`
		ContextWindow  int    `json:"context_window,omitempty"`
		PublicApps     any    `json:"public_apps"`
		ContextWindow0 int    `json:"context_ window,omitempty"`
	} `json:"data"`
}

Directories

Path Synopsis
examples
terminal-chat module
extensions
toolhouse module
scripts
models module

Jump to

Keyboard shortcuts

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