sdk

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const ACCESS_TOKEN_KEY = "sdk:baidu:access_token:%s"
View Source
const RoleAssistant = "assistant"
View Source
const RoleUser = "user"

Variables

This section is empty.

Functions

func ChatCompletion

func ChatCompletion(ctx context.Context, request openai.ChatCompletionRequest, retry ...int) (openai.ChatCompletionResponse, error)

func ChatCompletionStream

func ChatCompletionStream(ctx context.Context, request openai.ChatCompletionRequest, retry ...int) (responseChan chan openai.ChatCompletionStreamResponse, err error)

func GenImage

func GenImage(ctx context.Context, model, prompt string) (url string, err error)

func GenImageBase64

func GenImageBase64(ctx context.Context, model, prompt string, retry ...int) (string, error)

func Init

func Init(ctx context.Context, model string)

func MidjourneyProxy

func MidjourneyProxy(ctx context.Context, prompt string) (*model.Image, error)

func MidjourneyProxyBlend

func MidjourneyProxyBlend(ctx context.Context, midjourneyProxyBlendReq *model.MidjourneyProxyBlendReq) (*model.MidjourneyProxyBlendRes, error)

func MidjourneyProxyChange

func MidjourneyProxyChange(ctx context.Context, midjourneyProxyChangeReq *model.MidjourneyProxyChangeReq) (*model.MidjourneyProxyChangeRes, error)

func MidjourneyProxyChanges

func MidjourneyProxyChanges(ctx context.Context, prompt string) (*model.Image, error)

func MidjourneyProxyDescribe

func MidjourneyProxyDescribe(ctx context.Context, midjourneyProxyDescribeReq *model.MidjourneyProxyDescribeReq) (*model.MidjourneyProxyDescribeRes, error)

func MidjourneyProxyFetch

func MidjourneyProxyFetch(ctx context.Context, taskId string) (imageInfo *model.Image, midjourneyProxyFetchRes *model.MidjourneyProxyFetchRes, err error)

func MidjourneyProxyImagine

func MidjourneyProxyImagine(ctx context.Context, midjourneyProxyImagineReq *model.MidjourneyProxyImagineReq) (*model.MidjourneyProxyImagineRes, error)

func NumTokensFromMessages

func NumTokensFromMessages(messages []openai.ChatCompletionMessage, model string) (numTokens int, err error)

func NumTokensFromString

func NumTokensFromString(text, model string) (int, error)

func SparkStream

func SparkStream(ctx context.Context, model, uid string, text []Text, responseContent chan Payload, retry ...int)

Types

type Chat

type Chat struct {
	// req
	Domain          string `json:"domain"`
	RandomThreshold int    `json:"random_threshold"`
	MaxTokens       int    `json:"max_tokens"`
}

type Choices

type Choices struct {
	// res
	Status int    `json:"status,omitempty"`
	Seq    int    `json:"seq,omitempty"`
	Text   []Text `json:"text,omitempty"`
}

type ErnieBotMessage

type ErnieBotMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ErnieBotReq

type ErnieBotReq struct {
	Messages []ErnieBotMessage `json:"messages"`
}

type ErnieBotRes

type ErnieBotRes struct {
	Id               string `json:"id"`
	Object           string `json:"object"`
	Created          int    `json:"created"`
	Result           string `json:"result"`
	IsTruncated      bool   `json:"is_truncated"`
	NeedClearHistory bool   `json:"need_clear_history"`
	Usage            struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
		TotalTokens      int `json:"total_tokens"`
	} `json:"usage"`
	ErrorCode int    `json:"error_code"`
	ErrorMsg  string `json:"error_msg"`
}

func ErnieBot

func ErnieBot(ctx context.Context, model string, messages []ErnieBotMessage, retry ...int) (res *ErnieBotRes, err error)

type GetAccessTokenRes

type GetAccessTokenRes struct {
	RefreshToken     string `json:"refresh_token"`
	ExpiresIn        int64  `json:"expires_in"`
	SessionKey       string `json:"session_key"`
	AccessToken      string `json:"access_token"`
	Scope            string `json:"scope"`
	SessionSecret    string `json:"session_secret"`
	ErrorDescription string `json:"error_description"`
	Error            string `json:"error"`
}
type Header struct {
	// req
	AppId string `json:"app_id"`
	Uid   string `json:"uid"`
	// res
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
	Sid     string `json:"sid,omitempty"`
	Status  int    `json:"status,omitempty"`
}

type Input

type Input struct {
	Prompt  string                      `json:"prompt"`
	History []QwenChatCompletionMessage `json:"history"`
}

type Message

type Message struct {
	// req
	Text []Text `json:"text"`
}

type Parameter

type Parameter struct {
	// req
	Chat *Chat `json:"chat"`
}

type Payload

type Payload struct {
	// req
	Message *Message `json:"message"`
	// res
	Choices *Choices `json:"choices,omitempty"`
	Usage   *Usage   `json:"usage,omitempty"`
}

type QwenChatCompletionMessage

type QwenChatCompletionMessage struct {
	User string `json:"user"`
	Bot  string `json:"bot"`
}

type QwenChatCompletionReq

type QwenChatCompletionReq struct {
	Model      string `json:"model"`
	Input      Input  `json:"input"`
	Parameters struct {
	} `json:"parameters"`
}

type QwenChatCompletionRes

type QwenChatCompletionRes struct {
	Output struct {
		FinishReason string `json:"finish_reason"`
		Text         string `json:"text"`
	} `json:"output"`
	Usage struct {
		OutputTokens int `json:"output_tokens"`
		InputTokens  int `json:"input_tokens"`
	} `json:"usage"`
	RequestId string `json:"request_id"`
	Code      string `json:"code"`
	Message   string `json:"message"`
}

func QwenChatCompletion

func QwenChatCompletion(ctx context.Context, model string, messages []QwenChatCompletionMessage, retry ...int) (res *QwenChatCompletionRes, err error)

type SparkReq

type SparkReq struct {
	Header    Header    `json:"header"`
	Parameter Parameter `json:"parameter"`
	Payload   Payload   `json:"payload"`
}

type SparkRes

type SparkRes struct {
	Content string  `json:"content"`
	Header  Header  `json:"header"`
	Payload Payload `json:"payload"`
}

func Spark

func Spark(ctx context.Context, model, uid string, text []Text, retry ...int) (res *SparkRes, err error)

type Text

type Text struct {
	// req res
	Role    string `json:"role"`
	Content string `json:"content"`

	// Choices
	Index int `json:"index,omitempty"`

	// Usage
	QuestionTokens   int `json:"question_tokens,omitempty"`
	PromptTokens     int `json:"prompt_tokens,omitempty"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens,omitempty"`
}

type Usage

type Usage struct {
	// res
	Text *Text `json:"text,omitempty"`
}

Jump to

Keyboard shortcuts

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