client

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClients

func NewClients(cfg *config.Config, logger *zap.SugaredLogger) (map[string]ChatClient, error)

func NewOpenAIChatCompletionService

func NewOpenAIChatCompletionService(config *config.OpenAI) *openai.ChatCompletionService

Types

type ChatClient

type ChatClient interface {
	Chat(ctx context.Context, request *ChatRequest) (*ChatResponse, error)
	ImageGen(ctx context.Context, request *ChatRequest) (*ImageGenResponse, error)
}

type ChatClientMock added in v0.1.7

type ChatClientMock struct {
	// ChatFunc mocks the Chat method.
	ChatFunc func(ctx context.Context, request *ChatRequest) (*ChatResponse, error)

	// ImageGenFunc mocks the ImageGen method.
	ImageGenFunc func(ctx context.Context, request *ChatRequest) (*ImageGenResponse, error)
	// contains filtered or unexported fields
}

ChatClientMock is a mock implementation of ChatClient.

func TestSomethingThatUsesChatClient(t *testing.T) {

	// make and configure a mocked ChatClient
	mockedChatClient := &ChatClientMock{
		ChatFunc: func(ctx context.Context, request *ChatRequest) (*ChatResponse, error) {
			panic("mock out the Chat method")
		},
		ImageGenFunc: func(ctx context.Context, request *ChatRequest) (*ImageGenResponse, error) {
			panic("mock out the ImageGen method")
		},
	}

	// use mockedChatClient in code that requires ChatClient
	// and then make assertions.

}

func (*ChatClientMock) Chat added in v0.1.7

func (mock *ChatClientMock) Chat(ctx context.Context, request *ChatRequest) (*ChatResponse, error)

Chat calls ChatFunc.

func (*ChatClientMock) ChatCalls added in v0.1.7

func (mock *ChatClientMock) ChatCalls() []struct {
	Ctx     context.Context
	Request *ChatRequest
}

ChatCalls gets all the calls that were made to Chat. Check the length with:

len(mockedChatClient.ChatCalls())

func (*ChatClientMock) ImageGen added in v0.1.7

func (mock *ChatClientMock) ImageGen(ctx context.Context, request *ChatRequest) (*ImageGenResponse, error)

ImageGen calls ImageGenFunc.

func (*ChatClientMock) ImageGenCalls added in v0.1.7

func (mock *ChatClientMock) ImageGenCalls() []struct {
	Ctx     context.Context
	Request *ChatRequest
}

ImageGenCalls gets all the calls that were made to ImageGen. Check the length with:

len(mockedChatClient.ImageGenCalls())

type ChatRequest

type ChatRequest struct {
	Messages        []*Message
	Temperature     float64
	Schema          *jsonschema.Schema
	Model           string
	ImageModel      string
	MaxOutputTokens int64
	PresencePenalty float64
}

type ChatResponse

type ChatResponse struct {
	Content string `json:"content"`
	Tokens  int64  `json:"tokens"`
}

type Content added in v0.1.5

type Content struct {
	Type ContentType
	Data string
}

type ContentType added in v0.1.5

type ContentType string
const (
	ContentTypeText  ContentType = "text"
	ContentTypeImage ContentType = "image"
)

type GeminiClient added in v0.1.7

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

func NewGeminiClient added in v0.1.7

func NewGeminiClient(config *config.Gemini, logger *zap.SugaredLogger) (*GeminiClient, error)

func (*GeminiClient) Chat added in v0.1.7

func (c *GeminiClient) Chat(ctx context.Context, request *ChatRequest) (*ChatResponse, error)

func (*GeminiClient) ImageGen added in v0.1.7

func (c *GeminiClient) ImageGen(ctx context.Context, request *ChatRequest) (*ImageGenResponse, error)

type GenaiModelService added in v0.1.7

type GenaiModelService interface {
	GenerateContent(ctx context.Context, model string, contents []*genai.Content, config *genai.GenerateContentConfig) (*genai.GenerateContentResponse, error)
}

type GenaiModelServiceMock added in v0.1.7

type GenaiModelServiceMock struct {
	// GenerateContentFunc mocks the GenerateContent method.
	GenerateContentFunc func(ctx context.Context, model string, contents []*genai.Content, config *genai.GenerateContentConfig) (*genai.GenerateContentResponse, error)
	// contains filtered or unexported fields
}

GenaiModelServiceMock is a mock implementation of GenaiModelService.

func TestSomethingThatUsesGenaiModelService(t *testing.T) {

	// make and configure a mocked GenaiModelService
	mockedGenaiModelService := &GenaiModelServiceMock{
		GenerateContentFunc: func(ctx context.Context, model string, contents []*genai.Content, config *genai.GenerateContentConfig) (*genai.GenerateContentResponse, error) {
			panic("mock out the GenerateContent method")
		},
	}

	// use mockedGenaiModelService in code that requires GenaiModelService
	// and then make assertions.

}

func (*GenaiModelServiceMock) GenerateContent added in v0.1.7

func (mock *GenaiModelServiceMock) GenerateContent(ctx context.Context, model string, contents []*genai.Content, config *genai.GenerateContentConfig) (*genai.GenerateContentResponse, error)

GenerateContent calls GenerateContentFunc.

func (*GenaiModelServiceMock) GenerateContentCalls added in v0.1.7

func (mock *GenaiModelServiceMock) GenerateContentCalls() []struct {
	Ctx      context.Context
	Model    string
	Contents []*genai.Content
	Config   *genai.GenerateContentConfig
}

GenerateContentCalls gets all the calls that were made to GenerateContent. Check the length with:

len(mockedGenaiModelService.GenerateContentCalls())

type ImageGenResponse added in v0.1.7

type ImageGenResponse struct {
	Images map[string][]byte `json:"images"` // map[image id]image b64 data
	Tokens int64             `json:"tokens"`
}

type ImageGenerateRequest

type ImageGenerateRequest struct {
	Prompt string
	Model  string
}

type ImageResponse

type ImageResponse struct {
	URL     string `json:"url"`
	Content string `json:"content"`
	Tokens  int    `json:"tokens"`
}

type Message

type Message struct {
	Role    string
	Content []Content
}

func AssistantMessage

func AssistantMessage(content string) *Message

func SystemMessage

func SystemMessage(content string) *Message

func UserMessage

func UserMessage(content string) *Message

func UserMessageWithImages added in v0.1.5

func UserMessageWithImages(content string, images map[string]string) *Message

type OpenAIClient

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

func NewOpenAIClient

func NewOpenAIClient(completionService oaiChatCompletionService, logger *zap.SugaredLogger) *OpenAIClient

func (*OpenAIClient) Chat

func (c *OpenAIClient) Chat(ctx context.Context, request *ChatRequest) (*ChatResponse, error)

func (*OpenAIClient) ImageGen added in v0.1.7

func (c *OpenAIClient) ImageGen(ctx context.Context, request *ChatRequest) (*ImageGenResponse, error)

Jump to

Keyboard shortcuts

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