openai

package
v0.6.0-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(logger *zap.Logger) base.IConnector

Types

type AudioTranscriptionInput

type AudioTranscriptionInput struct {
	Audio       string   `json:"audio"`
	Model       string   `json:"model"`
	Prompt      *string  `json:"prompt,omitempty"`
	Temperature *float64 `json:"temperature,omitempty"`
	Language    *string  `json:"language,omitempty"`
}

type AudioTranscriptionReq

type AudioTranscriptionReq struct {
	File        []byte   `json:"file"`
	Model       string   `json:"model"`
	Prompt      *string  `json:"prompt,omitempty"`
	Language    *string  `json:"language,omitempty"`
	Temperature *float64 `json:"temperature,omitempty"`
}

type AudioTranscriptionResp

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

type Choices

type Choices struct {
	Index        int     `json:"index"`
	FinishReason string  `json:"finish_reason"`
	Message      Message `json:"message"`
}

type Client

type Client struct {
	APIKey     string
	Org        string
	HTTPClient HTTPClient
}

Client represents a OpenAI client

func NewClient

func NewClient(apiKey, org string) Client

NewClient initializes a new OpenAI client

func (*Client) GenerateAudioTranscriptions

func (c *Client) GenerateAudioTranscriptions(req AudioTranscriptionReq) (result AudioTranscriptionResp, err error)

GenerateAudioTranscriptions makes a call to the audio transcriptions API from OpenAI. https://platform.openai.com/docs/api-reference/audio/create-transcription

func (*Client) GenerateTextCompletion

func (c *Client) GenerateTextCompletion(req TextCompletionReq) (result TextCompletionResp, err error)

GenerateTextCompletion makes a call to the completions API from OpenAI. https://platform.openai.com/docs/api-reference/completions

func (*Client) GenerateTextEmbeddings

func (c *Client) GenerateTextEmbeddings(req TextEmbeddingsReq) (result TextEmbeddingsResp, err error)

GenerateTextEmbeddings makes a call to the embeddings API from OpenAI. https://platform.openai.com/docs/api-reference/embeddings

func (*Client) ListModels

func (c *Client) ListModels() (resp ListModelsResponse, err error)

ListModels calls the list models endpoint and returns the available models. https://platform.openai.com/docs/api-reference/models/list

type Connector

type Connector struct {
	base.Connector
}

func (*Connector) CreateExecution

func (c *Connector) CreateExecution(defUID uuid.UUID, task string, config *structpb.Struct, logger *zap.Logger) (base.IExecution, error)

func (*Connector) Test

func (c *Connector) Test(defUid uuid.UUID, config *structpb.Struct, logger *zap.Logger) (connectorPB.ConnectorResource_State, error)

type Data

type Data struct {
	Object    string    `json:"object"`
	Embedding []float64 `json:"embedding"`
	Index     int       `json:"index"`
}

type Execution

type Execution struct {
	base.Execution
}

func (*Execution) Execute

func (e *Execution) Execute(inputs []*structpb.Struct) ([]*structpb.Struct, error)

type HTTPClient

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

HTTPClient interface

type ListModelsResponse

type ListModelsResponse struct {
	Object string  `json:"object"`
	Data   []Model `json:"data"`
}

type Message

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

type Model

type Model struct {
	ID         string            `json:"id"`
	Object     string            `json:"object"`
	Created    int               `json:"created"`
	OwnedBy    string            `json:"owned_by"`
	Permission []ModelPermission `json:"permission"`
	Root       string            `json:"root"`
}

Model represents a OpenAI Model

type ModelPermission

type ModelPermission struct {
	ID                 string `json:"id"`
	Object             string `json:"object"`
	Created            int    `json:"created"`
	AllowCreateEngine  bool   `json:"allow_create_engine"`
	AllowSampling      bool   `json:"allow_sampling"`
	AllowLogprobs      bool   `json:"allow_logprobs"`
	AllowSearchIndices bool   `json:"allow_search_indices"`
	AllowView          bool   `json:"allow_view"`
	AllowFineTuning    bool   `json:"allow_fine_tuning"`
	Organization       string `json:"organization"`
	IsBlocking         bool   `json:"is_blocking"`
}

type TextCompletionInput

type TextCompletionInput struct {
	Prompt        string   `json:"prompt"`
	Model         string   `json:"model"`
	SystemMessage *string  `json:"system_message,omitempty"`
	Temperature   *float32 `json:"temperature,omitempty"`
	N             *int     `json:"n,omitempty"`
	MaxTokens     *int     `json:"max_tokens,omitempty"`
}

type TextCompletionOutput

type TextCompletionOutput struct {
	Texts []string `json:"texts"`
}

type TextCompletionReq

type TextCompletionReq struct {
	Model            string    `json:"model"`
	Messages         []Message `json:"messages"`
	Temperature      *float32  `json:"temperature,omitempty"`
	TopP             *float32  `json:"top_p,omitempty"`
	N                *int      `json:"n,omitempty"`
	Stream           *bool     `json:"stream,omitempty"`
	Stop             *string   `json:"stop,omitempty"`
	MaxTokens        *int      `json:"max_tokens,omitempty"`
	PresencePenalty  *float32  `json:"presence_penalty,omitempty"`
	FrequencyPenalty *float32  `json:"frequency_penalty,omitempty"`
}

type TextCompletionResp

type TextCompletionResp struct {
	ID      string    `json:"id"`
	Object  string    `json:"object"`
	Created int       `json:"created"`
	Choices []Choices `json:"choices"`
	Usage   Usage     `json:"usage"`
}

type TextEmbeddingsInput

type TextEmbeddingsInput struct {
	Text  string `json:"text"`
	Model string `json:"model"`
}

type TextEmbeddingsOutput

type TextEmbeddingsOutput struct {
	Embedding []float64 `json:"embedding"`
}

type TextEmbeddingsReq

type TextEmbeddingsReq struct {
	Model string   `json:"model"`
	Input []string `json:"input"`
}

type TextEmbeddingsResp

type TextEmbeddingsResp struct {
	Object string `json:"object"`
	Data   []Data `json:"data"`
	Model  string `json:"model"`
	Usage  Usage  `json:"usage"`
}

type Usage

type Usage 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