openai

package
v0.0.0-...-1a4fc59 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Endpoints for mocking OpenAI API calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartHTTPTestServer

func StartHTTPTestServer(response OpenAIResponse) *httptest.Server

Types

type AIMessage

type AIMessage struct {
	Type    string `json:"type"`
	Content string `json:"content"`
}

func (*AIMessage) GetContent

func (msg *AIMessage) GetContent() string

func (*AIMessage) GetType

func (msg *AIMessage) GetType() string

func (*AIMessage) IsMessage

func (msg *AIMessage) IsMessage() bool

func (*AIMessage) IsQuery

func (msg *AIMessage) IsQuery() bool

type ChatClient

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

func NewChatClient

func NewChatClient(apiKey string) *ChatClient

func (*ChatClient) AddMessage

func (c *ChatClient) AddMessage(role string, content string)

func (*ChatClient) ClearMessages

func (c *ChatClient) ClearMessages()

func (*ChatClient) CreateChatCompletion

func (c *ChatClient) CreateChatCompletion(messages []ChatMessage, model string) ([]ChatMessage, error)

func (*ChatClient) GetLastMessage

func (c *ChatClient) GetLastMessage() ChatMessage

func (*ChatClient) GetMessages

func (c *ChatClient) GetMessages() []ChatMessage

func (*ChatClient) LoadMessages

func (c *ChatClient) LoadMessages(filename string) error

func (*ChatClient) SaveMessages

func (c *ChatClient) SaveMessages(filename string) error

func (*ChatClient) SendAssistantMessage

func (c *ChatClient) SendAssistantMessage(msg string) error

func (*ChatClient) SendMessage

func (c *ChatClient) SendMessage(content string, role string) error

func (*ChatClient) SendSystemMessage

func (c *ChatClient) SendSystemMessage(msg string) error

func (*ChatClient) SendUserMessage

func (c *ChatClient) SendUserMessage(msg string) error

func (*ChatClient) SetBaseURL

func (c *ChatClient) SetBaseURL(baseURL string)

func (*ChatClient) SetMessages

func (c *ChatClient) SetMessages(messages []ChatMessage)

type ChatMessage

type ChatMessage struct {
	Content string
	Role    string
}

func (ChatMessage) GetContent

func (msg ChatMessage) GetContent() string

func (ChatMessage) GetRole

func (msg ChatMessage) GetRole() string

func (*ChatMessage) ToAIMessage

func (msg *ChatMessage) ToAIMessage() (AIMessage, error)

type OpenAI

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

func NewOpenAI

func NewOpenAI(apiKey string) *OpenAI

func NewOpenAIWithBaseURL

func NewOpenAIWithBaseURL(apiKey string, baseURL string) *OpenAI

func (*OpenAI) GetCompletion

func (o *OpenAI) GetCompletion(prompt string, model string) (string, error)

func (*OpenAI) GetEmbeddings

func (o *OpenAI) GetEmbeddings(texts []string) ([][]float32, error)

type OpenAIResponse

type OpenAIResponse string
const (
	SampleChatCompletion     OpenAIResponse = `` /* 299-byte string literal not displayed */
	SampleChatJSONCompletion OpenAIResponse = `` /* 333-byte string literal not displayed */
	SampleChatYAMLCompletion OpenAIResponse = `` /* 354-byte string literal not displayed */
	SampleChatFileCompletion OpenAIResponse = `` /* 384-byte string literal not displayed */
)

Jump to

Keyboard shortcuts

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