chatmodels

package
v0.0.0-...-b072a08 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 15 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_LLAMA_3_2_3B_INSTRUCT_MODEL = "@cf/meta/llama-3.2-3b-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"
)
View Source
const MODEL string = "gemini-1.0-pro"

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_QWEN.String(),
	CHAT_MODEL_GPT_V4.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_2_3B_INSTRUCT_MODEL,
	CHAT_MODEL_OPEN:         CF_OPEN_CHAT_MODEL,
	CHAT_MODEL_TRANSLATIONS: CF_META_TRANSLATION_MODEL,
	CHAT_MODEL_QWEN:         CF_QWEN_MODEL,
}
View Source
var CHAT_MODEL_TO_OPENAI_MODEL = map[ChatModel]string{
	CHAT_MODEL_GPT:    openai.O1Mini,
	CHAT_MODEL_GPT_V4: openai.GPT4o,
}
View Source
var IMAGE_MODEL_TO_CF_MODEL = map[ImageModel]string{
	IMAGE_MODEL_STABLE_DIFFUSION: CF_STABLE_DIFFUSION,
}
View Source
var IMAGE_MODEL_TO_OPENAI_MODEL = map[ImageModel]string{
	IMAGE_MODEL_DALL_E_3: openai.CreateImageModelDallE3,
	IMAGE_MODEL_DALL_E_2: openai.CreateImageModelDallE2,
}
View Source
var ImageModels = []string{
	IMAGE_MODEL_STABLE_DIFFUSION.String(),
	IMAGE_MODEL_DALL_E_3.String(),
	IMAGE_MODEL_DALL_E_2.String(),
}
View Source
var MissingContentError = errors.New("Missing content")

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_QWEN         ChatModel = "qwen"
	CHAT_MODEL_GPT_V4       ChatModel = "g. p. t. version number four"
)

func (ChatModel) String

func (c ChatModel) String() string

type Client

type Client struct {
	*Resources
}

func NewClient

func NewClient(r *Resources) *Client

func (*Client) GenerateImage

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

func (*Client) TextGeneration

func (client *Client) TextGeneration(ctx context.Context, prompt string, model ChatModel) (string, 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 {
	GenerateTextWithModel(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) GenerateTextWithModel

func (api *CloudflareApiClient) GenerateTextWithModel(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 {
	GenerateText(context.Context, string) (string, error)
}

type GeminiApiClient

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

func NewGeminiApiClient

func NewGeminiApiClient(token string) *GeminiApiClient

func (*GeminiApiClient) GenerateText

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

type GenerateTranslationRequest

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

type GptAPI

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

type ImageModel

type ImageModel string
const (
	IMAGE_MODEL_STABLE_DIFFUSION ImageModel = "stable"
	IMAGE_MODEL_DALL_E_2         ImageModel = "dallas v2"
	IMAGE_MODEL_DALL_E_3         ImageModel = "dallas"
)

func (ImageModel) String

func (c ImageModel) String() string

type LastResponse

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

type MockClient

type MockClient struct {
	Service
	mock.Mock
}

func (*MockClient) GenerateImage

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

func (*MockClient) TextGeneration

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

type OpenAIApiClient

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

func NewOpenAiApiClient

func NewOpenAiApiClient(token string) *OpenAIApiClient

func (*OpenAIApiClient) GenerateImage

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

func (*OpenAIApiClient) GenerateTextWithModel

func (api *OpenAIApiClient) GenerateTextWithModel(ctx context.Context, prompt string, model string) (string, 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"`
	ImageModel     *ImageModel `json:"image_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 {
	TextGeneration(context.Context, string, ChatModel) (string, error)
	GenerateImage(context.Context, string, ImageModel) ([]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