opencat_api

package module
v0.0.0-...-d23b74e Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 11 Imported by: 0

README

A reverse engineered Golang API wrapper for Baye's OpenCat, which provides access to GPT3.5, GPT4, Claude, Gemini, Dall-E, StableDiffusion etc.

OpenCat Cloud subscription is required to use the API. You can capture the request sent by the OpenCat app to get the token.

OpenCat's API is not public, and it may be against the TOS to use this wrapper. Use at your own risk. This project is not affiliated with OpenCat.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	HTTPStatusCode int
	Body           string
}

func NewAPIError

func NewAPIError(resp *http.Response) *APIError

func (*APIError) Error

func (e *APIError) Error() string

type ChatModel

type ChatModel string
var (
	// OpenAI
	ChatModelGPT3Dot5Turbo     ChatModel = "gpt-3.5-turbo"
	ChatModelGPT3Dot5Turbo16K  ChatModel = "gpt-3.5-turbo-16k"
	ChatModelGPT4              ChatModel = "gpt-4"
	ChatModelGPT432K           ChatModel = "gpt-4-32k"
	ChatModelGPT4Turbo         ChatModel = "gpt-4-1106-preview"
	ChatModelGPT4VisionPreview ChatModel = "gpt-4-vision-preview"
	// Anthropic Claude
	ChatModelClaudeInstant1 ChatModel = "claude-instant-v1"
	ChatModelClaude2        ChatModel = "claude-2.1"
	// Google GEMINI
	ChatModelGEMINIPro       ChatModel = "gemini-pro"
	ChatModelGEMINIProVision ChatModel = "gemini-pro-vision"
	// 百度文心一言
	ChatModelERNIEBot      ChatModel = "ERNIE-Bot"
	ChatModelERNIEBotTurbo ChatModel = "ERNIE-Bot-Turbo"
	ChatModelERNIEBot4     ChatModel = "ERNIE-Bot-4"
	// 阿里通义千问
	ChatModelQWENTurbo ChatModel = "qwen-turbo"
	ChatModelQWENPlus  ChatModel = "qwen-plus"
	// 讯飞星火大模型
	ChatModelSparkDeskV1 ChatModel = "SparkDesk-V1.5"
	ChatModelSparkDeskV2 ChatModel = "SparkDesk-V2.0"
	ChatModelSparkDeskV3 ChatModel = "SparkDesk-V3.0"
)

type ChatRequest

type ChatRequest struct {
	Temperature float64   `json:"temperature,omitempty"`
	MaxTokens   int       `json:"maxTokens,omitempty"`
	Model       ChatModel `json:"model"`
	Stream      bool      `json:"stream,omitempty"`
	Messages    []Message `json:"messages"`
}

type ChatResponse

type ChatResponse struct {
	ID      string               `json:"id"`
	Object  string               `json:"object"`
	Created int64                `json:"created"`
	Model   string               `json:"model"`
	Choices []ChatResponseChoice `json:"choices"`
	Usage   Usage                `json:"usage"`
}

type ChatResponseChoice

type ChatResponseChoice struct {
	Index   int `json:"index"`
	Message struct {
		Content string `json:"content"`
		Role    Role   `json:"role"`
	} `json:"message"`
	FinishReason string `json:"finish_reason"`
}

type Client

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

func NewClient

func NewClient(token string) *Client

func (*Client) Chat

func (c *Client) Chat(ctx context.Context, chat ChatRequest) (_ ChatResponse, err error)

Chat generates a response from a list of messages.

func (*Client) Image

func (c *Client) Image(ctx context.Context, image ImageRequest) ([][]byte, error)

Image generates an image from a text prompt.

func (*Client) Speech

func (c *Client) Speech(ctx context.Context, speech SpeechRequest) (io.ReadCloser, error)

Speech generates speech from a text input. The returned io.ReadCloser is an MP3 audio stream. Caller must close it.

func (*Client) StreamChat

func (c *Client) StreamChat(ctx context.Context, chat ChatRequest, fn func(delta string, done bool)) error

StreamChat generates a response from a list of messages, and streams the response.

func (*Client) Usage

func (c *Client) Usage(ctx context.Context) ([]Usage, error)

Usage returns the current usage of the API.

type DallEParams

type DallEParams struct {
	Quality string `json:"quality"`
	Style   string `json:"style"`
}

type Image

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

func NewImage

func NewImage(r io.Reader) Image

func (*Image) MarshalJSON

func (img *Image) MarshalJSON() ([]byte, error)

type ImageModel

type ImageModel string
var (
	ImageModelDallE2            ImageModel = "dall-e-2"
	ImageModelDallE3            ImageModel = "dall-e-3"
	ImageModelStableDiffusionXL ImageModel = "stable_diffusion_xl"
)

type ImageRequest

type ImageRequest struct {
	Width             int                     `json:"width"`
	Height            int                     `json:"height"`
	Num               int                     `json:"num"`
	Model             ImageModel              `json:"model"`
	Prompt            string                  `json:"prompt"`
	NegativePrompt    string                  `json:"negativePrompt"`
	DallE             DallEParams             `json:"dallE,omitempty"`
	StableDiffusionXL StableDiffusionXLParams `json:"stable_diffusion_xl,omitempty"`
}

type Message

type Message struct {
	Role    Role    `json:"role"`
	Content string  `json:"content"`
	Images  []Image `json:"images,omitempty"`
}

type Role

type Role string
var (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
)

type SpeechModel

type SpeechModel string
var (
	SpeechModelTTS1   SpeechModel = "tts-1"
	SpeechModelTTS1HD SpeechModel = "tts-1-hd"
	SpeechModelAzure  SpeechModel = "__azure"
)

type SpeechRequest

type SpeechRequest struct {
	Input string      `json:"input"`
	Voice string      `json:"voice"`
	Model SpeechModel `json:"model"`
}

type StableDiffusionXLParams

type StableDiffusionXLParams struct {
	Steps       int    `json:"steps"`
	Sampler     string `json:"sampler"`
	StylePreset string `json:"style_preset"`
	Scale       int    `json:"scale"`
}

type Usage

type Usage struct {
	ID      string             `json:"id"`
	Limit   int                `json:"limit"`
	Product string             `json:"product"`
	Usage   map[string]float32 `json:"usage"`
}

Jump to

Keyboard shortcuts

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