chatmodels

package
v0.0.0-...-60c34f3 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 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_LLAMA_3_8B_INSTRUCT_MODEL  = "@cf/meta/llama-3-8b-instruct"
	CF_LLAMA_3_1_INSTRUCT_MODEL   = "@cf/meta/llama-3.1-8b-instruct"
	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"
	CF_META_TRANSLATION_MODEL     = "@cf/meta/m2m100-1.2b"
	CF_QWEN_MODEL                 = "@cf/qwen/qwen1.5-1.8b-chat"
)

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(),
	CHAT_MODEL_QWEN.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_3_1_INSTRUCT_MODEL,
	CHAT_MODEL_OPEN:             CF_OPEN_CHAT_MODEL,
	CHAT_MODEL_STABLE_DIFFUSION: CF_STABLE_DIFFUSION,
	CHAT_MODEL_TRANSLATIONS:     CF_META_TRANSLATION_MODEL,
	CHAT_MODEL_QWEN:             CF_QWEN_MODEL,
}

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_TRANSLATIONS     ChatModel = "translate"
	CHAT_MODEL_OPEN             ChatModel = "open chat"
	CHAT_MODEL_SQL              ChatModel = "sql"
	CHAT_MODEL_STABLE_DIFFUSION ChatModel = "stable"
	CHAT_MODEL_QWEN             ChatModel = "qwen"
)

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)

func (*Client) Translate

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

type CloudFlareAiWorkerAPI

type CloudFlareAiWorkerAPI interface {
	GenerateText(context.Context, string, string) (string, error)
	GenerateImage(ctx context.Context, prompt string, model string) ([]byte, error)
	GenerateTranslation(ctx context.Context, req *GenerateTranslationRequest) (string, 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)

func (*CloudflareApiClient) GenerateTranslation

func (api *CloudflareApiClient) GenerateTranslation(ctx context.Context, req *GenerateTranslationRequest) (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 GenerateTranslationRequest

type GenerateTranslationRequest struct {
	SourceLanguage string
	TargetLanguage string
	Prompt         string
	Model          string
}

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"`
	TargetLanguage string    `json:"target_language,omitempty"`
	SourceLanguage string    `json:"source_language,omitempty"`
	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)
	Translate(
		ctx context.Context,
		prompt string,
		sourceLang string,
		targetLang string,
		model ChatModel,
	) (string, error)
}

type TranslateResponse

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

Jump to

Keyboard shortcuts

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