chatmodels

package
v0.0.0-...-84dd35e Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CF_LLAMA_2_7B_CHAT_INT8_MODEL = "@cf/meta/llama-2-7b-chat-int8"
	CF_SQL_MODEL                  = "@cf/defog/sqlcoder-7b-2"
	CF_AWQ_MODEL                  = "@hf/thebloke/llama-2-13b-chat-awq"
	CF_OPEN_CHAT_MODEL            = "@cf/openchat/openchat-3.5-0106"
	CF_STABLE_DIFFUSION           = "@cf/stabilityai/stable-diffusion-xl-base-1.0"
)

Variables

View Source
var AvaliableModels = []string{
	CHAT_MODEL_GPT.String(),
	CHAT_MODEL_GEMINI.String(),
	CHAT_MODEL_META.String(),
	CHAT_MODEL_SQL.String(),
	CHAT_MODEL_OPEN.String(),
	CHAT_MODEL_AWQ.String(),
	CHAT_MODEL_STABLE_DIFFUSION.String(),
}
View Source
var CHAT_MODEL_TO_CF_MODEL = map[ChatModel]string{
	CHAT_MODEL_SQL:              CF_SQL_MODEL,
	CHAT_MODEL_AWQ:              CF_AWQ_MODEL,
	CHAT_MODEL_META:             CF_LLAMA_2_7B_CHAT_INT8_MODEL,
	CHAT_MODEL_OPEN:             CF_OPEN_CHAT_MODEL,
	CHAT_MODEL_STABLE_DIFFUSION: CF_STABLE_DIFFUSION,
}

Functions

This section is empty.

Types

type ChatModel

type ChatModel string
const (
	CHAT_MODEL_GEMINI           ChatModel = "gemini"
	CHAT_MODEL_GPT              ChatModel = "gpt"
	CHAT_MODEL_META             ChatModel = "llama"
	CHAT_MODEL_AWQ              ChatModel = "awq"
	CHAT_MODEL_OPEN             ChatModel = "open chat"
	CHAT_MODEL_SQL              ChatModel = "sql"
	CHAT_MODEL_STABLE_DIFFUSION ChatModel = "stable diffusion"
)

func (ChatModel) String

func (c ChatModel) String() string

type Client

type Client struct {
	*Resources
}

func NewClient

func NewClient(r *Resources) *Client

func (*Client) AutoComplete

func (client *Client) AutoComplete(ctx context.Context, prompt string, model ChatModel) (string, error)

func (*Client) GenerateImage

func (client *Client) GenerateImage(ctx context.Context, prompt string, model ChatModel) ([]byte, error)

type CloudFlareAiWorkerAPI

type CloudFlareAiWorkerAPI interface {
	GenerateText(context.Context, string, string) (string, error)
	GenerateImage(ctx context.Context, prompt string, model string) ([]byte, error)
}

type CloudflareApiClient

type CloudflareApiClient struct {
	AccountID string
	APIKey    string
}

func NewCloudflareApiClient

func NewCloudflareApiClient(accountID, apiKey string) *CloudflareApiClient

func (*CloudflareApiClient) GenerateImage

func (api *CloudflareApiClient) GenerateImage(ctx context.Context, prompt string, model string) ([]byte, error)

func (*CloudflareApiClient) GenerateText

func (api *CloudflareApiClient) GenerateText(ctx context.Context, prompt string, model string) (string, error)

type GeminiAPI

type GeminiAPI interface {
	GeminiChat(context.Context, string) (*genai.GenerateContentResponse, error)
}

type GeminiApiClient

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

func NewGeminiApiClient

func NewGeminiApiClient(token string) *GeminiApiClient

func (*GeminiApiClient) GeminiChat

func (api *GeminiApiClient) GeminiChat(ctx context.Context, prompt string) (*genai.GenerateContentResponse, error)

type GptAPI

type GptAPI interface {
	AutoComplete(context.Context, string) (openai.ChatCompletionResponse, error)
}

type LastResponse

type LastResponse struct {
	Prompt         string    `json:"prompt"`
	Response       string    `json:"response"`
	TimeDiff       string    `json:"time_diff"`
	Model          ChatModel `json:"model"`
	ImagesResponse []string  `json:"images_responses"`
	Error          string    `json:"error_message"`
}

type MockClient

type MockClient struct {
	Service
	mock.Mock
}

func (*MockClient) AutoComplete

func (client *MockClient) AutoComplete(ctx context.Context, prompt string, model ChatModel) (string, error)

func (*MockClient) GenerateImage

func (client *MockClient) GenerateImage(ctx context.Context, prompt string, model ChatModel) (res []byte, err error)

type OpenAIApiClient

type OpenAIApiClient struct {
	Token        string
	OpenAIClient *openai.Client
}

func NewOpenAiApiClient

func NewOpenAiApiClient(token string) *OpenAIApiClient

func (*OpenAIApiClient) AutoComplete

func (api *OpenAIApiClient) AutoComplete(ctx context.Context, prompt string) (openai.ChatCompletionResponse, error)

type Request

type Request struct {
	Prompt string    `json:"prompt"`
	Model  ChatModel `json:"model"`
}

type Resources

type Resources struct {
	GPTApi              GptAPI
	GeminiAPI           GeminiAPI
	CloudflareApiClient CloudFlareAiWorkerAPI
}

type Response

type Response struct {
	Result struct {
		Response string `json:"response"`
	} `json:"result,omitempty"`
	Errors []struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"errors,omitempty"`
	Messages []string `json:"messages,omitempty"`
	Success  bool     `json:"success"`
}

type Service

type Service interface {
	AutoComplete(context.Context, string, ChatModel) (string, error)
	GenerateImage(context.Context, string, ChatModel) ([]byte, error)
}

Jump to

Keyboard shortcuts

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