go_ernie

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 14 Imported by: 5

README

文心千帆 GO SDK

Go Reference

本库为文心千帆GO语言SDK,非官方库,目前官方还没有GO语言的SDK 文心千帆

已支持自动刷新 accessToken, 需要通过 ernie.NewDefaultClient("API Key", "Secret Key") 方式初始化客户端

目前支持的模型:

  • ERNIE-Bot-4
  • ERNIE-Bot
  • ERNIE-Bot-turbo
  • ERNIE-Bot-8k
  • ERNIE-Bot-turbo-AI
  • BLOOMZ-7B
  • Llama-2
  • Embeddings
  • 百度云所有模型
安装
go get github.com/anhao/go-ernie

需要 go 版本为 1.18+

使用示例
package main

import (
	"context"
	"fmt"
	ernie "github.com/anhao/go-ernie"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	completion, err := client.CreateErnieBotChatCompletion(context.Background(), ernie.ErnieBotRequest{
		Messages: []ernie.ChatCompletionMessage{
			{
				Role:    ernie.MessageRoleUser,
				Content: "你好呀",
			},
		},
	})
	if err != nil {
		fmt.Printf("ernie bot error: %v\n", err)
		return
	}
	fmt.Println(completion)
}
获取文心千帆 APIKEY
  1. 在百度云官网进行申请:https://cloud.baidu.com/product/wenxinworkshop
  2. 申请通过后创建应用:https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application
  3. 获取 apikey 和 api secret
其他示例
ERNIE-Bot 4.0 对话
import (
	"context"
	"errors"
	"fmt"
	ernie "github.com/anhao/go-ernie"
	"io"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.ErnieBot4Request{
		Messages: []ChatCompletionMessage{
			{
				Role:    "user",
				Content: "Hello",
			},
		},
		Stream: true,
	}

	stream, err := client.CreateErnieBot4ChatCompletionStream(context.Background(), request)
	if err != nil {
		fmt.Printf("ernie bot stream error: %v\n", err)
		return
	}
	defer stream.Close()
	for {
		response, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			fmt.Println("ernie bot 4 Stream finished")
			return
		}
		if err != nil {
			fmt.Printf("ernie bot 4 stream error: %v\n", err)
			return
		}
		fmt.Println(response.Result)
	}
}
ERNIE-Bot stream流 对话
import (
	"context"
	"errors"
	"fmt"
	ernie "github.com/anhao/go-ernie"
	"io"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.ErnieBotRequest{
		Messages: []ChatCompletionMessage{
			{
				Role:    "user",
				Content: "Hello",
			},
		},
		Stream: true,
	}

	stream, err := client.CreateErnieBotChatCompletionStream(context.Background(), request)
	if err != nil {
		fmt.Printf("ernie bot stream error: %v\n", err)
		return
	}
	defer stream.Close()
	for {
		response, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			fmt.Println("ernie bot Stream finished")
			return
		}
		if err != nil {
			fmt.Printf("ernie bot stream error: %v\n", err)
			return
		}
		fmt.Println(response.Result)
	}
}
ERNIE-Bot-Turbo 对话
package main

import (
	"context"
	"fmt"
	ernie "github.com/anhao/go-ernie"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	completion, err := client.CreateErnieBotTurboChatCompletion(context.Background(), ernie.ErnieBotTurboRequest{
		Messages: []ernie.ChatCompletionMessage{
			{
				Role:    ernie.MessageRoleUser,
				Content: "你好呀",
			},
		},
	})
	if err != nil {
		fmt.Printf("ernie bot turbo error: %v\n", err)
		return
	}
	fmt.Println(completion)
}
ERNIE-Bot Turbo stream流 对话
import (
	"context"
	"errors"
	"fmt"
	ernie "github.com/anhao/go-ernie"
	"io"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.ErnieBotTurboRequest{
		Messages: []ChatCompletionMessage{
			{
				Role:    "user",
				Content: "Hello",
			},
		},
		Stream: true,
	}

	stream, err := client.CreateErnieBotTurboChatCompletionStream(context.Background(), request)
	if err != nil {
		fmt.Printf("ernie bot stream error: %v\n", err)
		return
	}
	defer stream.Close()
	for {
		response, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			fmt.Println("ernie bot turbo Stream finished")
			return
		}
		if err != nil {
			fmt.Printf("ernie bot turbo stream error: %v\n", err)
			return
		}
		fmt.Println(response.Result)
	}
}
BLOOMZ-7B 对话
package main

import (
	"context"
	"fmt"
	ernie "github.com/anhao/go-ernie"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	completion, err := client.CreateBloomz7b1ChatCompletion(context.Background(), ernie.Bloomz7b1Request{
		Messages: []ernie.ChatCompletionMessage{
			{
				Role:    ernie.MessageRoleUser,
				Content: "你好呀",
			},
		},
	})
	if err != nil {
		fmt.Printf("BLOOMZ-7B error: %v\n", err)
		return
	}
	fmt.Println(completion)
}
BLOOMZ-7B stream流 对话
import (
	"context"
	"errors"
	"fmt"
	ernie "github.com/anhao/go-ernie"
	"io"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.Bloomz7b1Request{
		Messages: []ChatCompletionMessage{
			{
				Role:    "user",
				Content: "Hello",
			},
		},
		Stream: true,
	}

	stream, err := client.CreateBloomz7b1ChatCompletionStream(context.Background(), request)
	if err != nil {
		fmt.Printf("BLOOMZ-7B error: %v\n", err)
		return
	}
	defer stream.Close()
	for {
		response, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			fmt.Println("BLOOMZ-7B  Stream finished")
			return
		}
		if err != nil {
			fmt.Printf("BLOOMZ-7B stream error: %v\n", err)
			return
		}
		fmt.Println(response.Result)
	}
}
Llama2 对话
package main

import (
	"context"
	"fmt"
	ernie "github.com/anhao/go-ernie"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	completion, err := client.CreateLlamaChatCompletion(context.Background(), ernie.LlamaChatRequest{
		Messages: []ernie.ChatCompletionMessage{
			{
				Role:    ernie.MessageRoleUser,
				Content: "你好呀",
			},
		},
		Model: "", //申请发布时填写的API名称
	})
	if err != nil {
		fmt.Printf("llama2 error: %v\n", err)
		return
	}
	fmt.Println(completion)
}
Llama2 stream流 对话
import (
	"context"
	"errors"
	"fmt"
	ernie "github.com/anhao/go-ernie"
	"io"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.LlamaChatRequest{
		Messages: []ChatCompletionMessage{
			{
				Role:    "user",
				Content: "Hello",
			},
		},
		Stream: true,
		Model: "", //申请发布时填写的API名称
	}

	stream, err := client.CreateLlamaChatCompletionStream(context.Background(), request)
	if err != nil {
		fmt.Printf("llama2 error: %v\n", err)
		return
	}
	defer stream.Close()
	for {
		response, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			fmt.Println("llama2  Stream finished")
			return
		}
		if err != nil {
			fmt.Printf("llama2 stream error: %v\n", err)
			return
		}
		fmt.Println(response.Result)
	}
}
Embedding向量
package main

import (
	"context"
	"fmt"
	ernie "github.com/anhao/go-ernie"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.EmbeddingRequest{
		Input: []string{
			"Hello",
		},
	}
	embeddings, err := client.CreateEmbeddings(context.Background(), request)
	if err != nil {
		fmt.Sprintf("embeddings err: %v", err)
		return
	}
	fmt.Println(embeddings)
}

自定义 accessToken
client :=ernie.NewClient("accessToken")
百度云其他Chat模型 百度云的其他模型需要自己部署,部署需要填写一个API地址
import (
	"context"
	"errors"
	"fmt"
	ernie "github.com/anhao/go-ernie"
	"io"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.BaiduChatRequest{
		Messages: []ChatCompletionMessage{
			{
				Role:    "user",
				Content: "Hello",
			},
		},
		Stream: true,
		Model: "", //申请发布时填写的API名称
	}

	stream, err := client.CreateBaiduChatCompletionStream(context.Background(), request)
	if err != nil {
		fmt.Printf("baidu chat error: %v\n", err)
		return
	}
	defer stream.Close()
	for {
		response, err := stream.Recv()
		if errors.Is(err, io.EOF) {
			fmt.Println("baidu chat  Stream finished")
			return
		}
		if err != nil {
			fmt.Printf("baidu chat stream error: %v\n", err)
			return
		}
		fmt.Println(response.Result)
	}
}
文本生成图片 百度云的其他模型需要自己部署,部署需要填写一个API地址
import (
	"context"
	"errors"
	"fmt"
	ernie "github.com/anhao/go-ernie"
	"io"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.BaiduTxt2ImgRequest{
		Model: "", //申请发布时填写的API名称
		Prompt: "",//提示词
	}

    response, err := client.CreateBaiduTxt2Img(context.Background(), request)
	if err != nil {
		fmt.Printf("baidu txt2img error: %v\n", err)
		return
	}
	fmt.Println(response)
}
插件应用
import (
	"context"
	"errors"
	"fmt"
	ernie "github.com/anhao/go-ernie"
	"io"
)

func main() {

	client := ernie.NewDefaultClient("API Key", "Secret Key")
	request := ernie.ErnieCustomPluginRequest{
		PluginName: "xxx", // 插件名称
		Query:      "你好",// 查询信息
		Stream:     false,
	}

    response, err := client.CreateErnieCustomPluginChatCompletion(context.Background(), request)
	if err != nil {
		fmt.Printf("ernie custom plugins error: %v\n", err)
		return
	}
	fmt.Println(response)
}

Documentation

Index

Constants

View Source
const (
	MessageRoleUser      = "user"
	MessageRoleAssistant = "assistant"
	MessageRoleFunction  = "function"
)

Variables

View Source
var (
	ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateChatCompletionStream") //nolint:lll
)
View Source
var (
	ErrTooManyEmptyStreamMessages = errors.New("stream has sent too many empty messages")
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	ErrorCode int    `json:"error_code"`
	ErrorMsg  string `json:"error_msg"`
	ID        string `json:"id"`
}

func (*APIError) Error

func (e *APIError) Error() string

type AccessTokenResponse

type AccessTokenResponse struct {
	RefreshToken     string `json:"refresh_token"`
	ExpiresIn        int    `json:"expires_in"`
	SessionKey       string `json:"session_key"`
	AccessToken      string `json:"access_token"`
	Scope            string `json:"scope"`
	SessionSecret    string `json:"session_secret"`
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

type BaiduChatCompletionStream added in v1.0.4

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

func (BaiduChatCompletionStream) Close added in v1.0.4

func (stream BaiduChatCompletionStream) Close()

func (BaiduChatCompletionStream) Recv added in v1.0.4

func (stream BaiduChatCompletionStream) Recv() (response T, err error)

type BaiduChatRequest added in v1.0.4

type BaiduChatRequest struct {
	Messages []ChatCompletionMessage `json:"messages"`
	Stream   bool                    `json:"stream"`
	UserId   string                  `json:"user_id"`
	Model    string                  `json:"-"`
}

type BaiduChatResponse added in v1.0.4

type BaiduChatResponse struct {
	ErnieBotResponse
}

type BaiduTxt2ImgRequest added in v1.0.4

type BaiduTxt2ImgRequest struct {
	Prompt string `json:"prompt"`
	Width  string `json:"width"`
	Height string `json:"height"`
	Model  string `json:"-"`
}

type BaiduTxt2ImgResponse added in v1.0.4

type BaiduTxt2ImgResponse struct {
	Images []string `json:"images"`
	APIError
}

type Bloomz7b1ChatCompletionStream

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

func (Bloomz7b1ChatCompletionStream) Close

func (stream Bloomz7b1ChatCompletionStream) Close()

func (Bloomz7b1ChatCompletionStream) Recv

func (stream Bloomz7b1ChatCompletionStream) Recv() (response T, err error)

type Bloomz7b1Request

type Bloomz7b1Request struct {
	Messages []ChatCompletionMessage `json:"messages"`
	Stream   bool                    `json:"stream"`
	UserId   string                  `json:"user_id"`
}

type Bloomz7b1Response

type Bloomz7b1Response struct {
	ErnieBotResponse
}

type Cache added in v1.0.7

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

func NewCache added in v1.0.7

func NewCache() *Cache

func (*Cache) Del added in v1.0.8

func (c *Cache) Del(key string)

func (*Cache) Get added in v1.0.7

func (c *Cache) Get(key string) (interface{}, bool)

func (*Cache) Set added in v1.0.7

func (c *Cache) Set(key string, value interface{}, expiration time.Duration)

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role         string             `json:"role"`
	Content      string             `json:"content"`
	Name         string             `json:"name,omitempty"`
	FunctionCall *ErnieFunctionCall `json:"function_call,omitempty"`
}

type Client

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

func NewClient

func NewClient(accessToken string) *Client

func NewClientWithConfig

func NewClientWithConfig(config ClientConfig) *Client

func NewDefaultClient

func NewDefaultClient(clientId, clientSecret string) *Client

func (*Client) ClearAccessToken added in v1.0.8

func (c *Client) ClearAccessToken(ctx context.Context)

func (*Client) CreateBaiduChatCompletion added in v1.0.4

func (c *Client) CreateBaiduChatCompletion(
	ctx context.Context,
	request BaiduChatRequest,
) (response BaiduChatResponse, err error)

func (*Client) CreateBaiduChatCompletionStream added in v1.0.4

func (c *Client) CreateBaiduChatCompletionStream(
	ctx context.Context,
	request BaiduChatRequest,
) (stream *BaiduChatCompletionStream, err error)

func (*Client) CreateBaiduTxt2Img added in v1.0.4

func (c *Client) CreateBaiduTxt2Img(
	ctx context.Context,
	request BaiduTxt2ImgRequest,
) (response BaiduTxt2ImgResponse, err error)

func (*Client) CreateBgeLargeEnEmbedding added in v1.0.5

func (c *Client) CreateBgeLargeEnEmbedding(ctx context.Context, request EmbeddingRequest) (response EmbeddingResponse, err error)

func (*Client) CreateBgeLargeZhEmbedding added in v1.0.5

func (c *Client) CreateBgeLargeZhEmbedding(ctx context.Context, request EmbeddingRequest) (response EmbeddingResponse, err error)

func (*Client) CreateBloomz7b1ChatCompletion

func (c *Client) CreateBloomz7b1ChatCompletion(
	ctx context.Context,
	request Bloomz7b1Request,
) (response Bloomz7b1Response, err error)

func (*Client) CreateBloomz7b1ChatCompletionStream

func (c *Client) CreateBloomz7b1ChatCompletionStream(
	ctx context.Context,
	request Bloomz7b1Request,
) (stream *Bloomz7b1ChatCompletionStream, err error)

func (*Client) CreateCompletion added in v1.0.5

func (c *Client) CreateCompletion(
	ctx context.Context,
	request CompletionRequest,
) (response CompletionResponse, err error)

func (*Client) CreateCompletionStream added in v1.0.5

func (c *Client) CreateCompletionStream(
	ctx context.Context,
	request CompletionRequest,
) (stream *CompletionResponseStream, err error)

func (*Client) CreateEmbeddings

func (c *Client) CreateEmbeddings(ctx context.Context, request EmbeddingRequest) (response EmbeddingResponse, err error)

func (*Client) CreateErnieBot4ChatCompletion added in v1.0.5

func (c *Client) CreateErnieBot4ChatCompletion(
	ctx context.Context,
	request ErnieBot4Request,
) (response ErnieBot4Response, err error)

func (*Client) CreateErnieBot4ChatCompletionStream added in v1.0.5

func (c *Client) CreateErnieBot4ChatCompletionStream(
	ctx context.Context,
	request ErnieBot4Request,
) (stream *ErnireBot4ChatCompletionStream, err error)

func (*Client) CreateErnieBot8KChatCompletion added in v1.0.9

func (c *Client) CreateErnieBot8KChatCompletion(
	ctx context.Context,
	request ErnieBot8KRequest,
) (response ErnieBot8KResponse, err error)

func (*Client) CreateErnieBot8KChatCompletionStream added in v1.0.9

func (c *Client) CreateErnieBot8KChatCompletionStream(
	ctx context.Context,
	request ErnieBot8KRequest,
) (stream *ErnireBot8KChatCompletionStream, err error)

func (*Client) CreateErnieBotChatCompletion

func (c *Client) CreateErnieBotChatCompletion(
	ctx context.Context,
	request ErnieBotRequest,
) (response ErnieBotResponse, err error)

func (*Client) CreateErnieBotChatCompletionStream

func (c *Client) CreateErnieBotChatCompletionStream(
	ctx context.Context,
	request ErnieBotRequest,
) (stream *ErnireBotChatCompletionStream, err error)

func (*Client) CreateErnieBotTurboAIChatCompletion added in v1.0.9

func (c *Client) CreateErnieBotTurboAIChatCompletion(
	ctx context.Context,
	request ErnieBotTurboAIRequest,
) (response ErnieBotTurboAIResponse, err error)

func (*Client) CreateErnieBotTurboAIChatCompletionStream added in v1.0.9

func (c *Client) CreateErnieBotTurboAIChatCompletionStream(
	ctx context.Context,
	request ErnieBotTurboAIRequest,
) (stream *ErnireBotTurboAIChatCompletionStream, err error)

func (*Client) CreateErnieBotTurboChatCompletion

func (c *Client) CreateErnieBotTurboChatCompletion(
	ctx context.Context,
	request ErnieBotTurboRequest,
) (response ErnieBotTurboResponse, err error)

func (*Client) CreateErnieBotTurboChatCompletionStream

func (c *Client) CreateErnieBotTurboChatCompletionStream(
	ctx context.Context,
	request ErnieBotTurboRequest,
) (stream *ErnireBotChatCompletionStream, err error)

func (*Client) CreateErnieCustomPluginChatCompletion added in v1.0.4

func (c *Client) CreateErnieCustomPluginChatCompletion(
	ctx context.Context,
	request ErnieCustomPluginRequest,
) (response ErnieCustomPluginResponse, err error)

func (*Client) CreateErnieCustomPluginStreamChatCompletion added in v1.0.4

func (c *Client) CreateErnieCustomPluginStreamChatCompletion(
	ctx context.Context,
	request ErnieCustomPluginRequest,
) (stream *ErnieCustomPluginStream, err error)

func (*Client) CreateImageStableDiffusionXL added in v1.0.5

func (c *Client) CreateImageStableDiffusionXL(ctx context.Context, request ImageRequest) (response ImageResponse, err error)

func (*Client) CreateImageVisualGLM added in v1.0.5

func (c *Client) CreateImageVisualGLM(ctx context.Context, request ImageRequest) (response ImageResponse, err error)

func (*Client) CreateLlamaChatCompletion

func (c *Client) CreateLlamaChatCompletion(
	ctx context.Context,
	request LlamaChatRequest,
) (response LlamaChatResponse, err error)

func (*Client) CreateLlamaChatCompletionStream

func (c *Client) CreateLlamaChatCompletionStream(
	ctx context.Context,
	request LlamaChatRequest,
) (stream *LlamaChatCompletionStream, err error)

func (*Client) GetAccessToken

func (c *Client) GetAccessToken(ctx context.Context) (*string, error)

type ClientConfig

type ClientConfig struct {
	AccessToken        string
	ClientId           string
	ClientSecret       string
	BaseURL            string
	HTTPClient         *http.Client
	EmptyMessagesLimit uint
	Cache              *Cache
}

func DefaultConfig

func DefaultConfig(accessToken string) ClientConfig

type CompletionRequest added in v1.0.5

type CompletionRequest struct {
	Model  string `json:"-"`
	Prompt string `json:"prompt"`
	Stream bool   `json:"stream,omitempty"`
	UserId string `json:"user_id,omitempty"`
}

CompletionRequest 文本续写模型

type CompletionResponse added in v1.0.5

type CompletionResponse struct {
	Id         string     `json:"id"`
	Object     string     `json:"object"`
	Created    int        `json:"created"`
	SentenceId int        `json:"sentence_id"`
	IsEnd      bool       `json:"is_end"`
	Result     string     `json:"result"`
	IsSafe     bool       `json:"is_safe"`
	Usage      ErnieUsage `json:"usage"`
	APIError
}

type CompletionResponseStream added in v1.0.5

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

func (CompletionResponseStream) Close added in v1.0.5

func (stream CompletionResponseStream) Close()

func (CompletionResponseStream) Recv added in v1.0.5

func (stream CompletionResponseStream) Recv() (response T, err error)

type EmbeddingData

type EmbeddingData struct {
	Object    string    `json:"object"`
	Embedding []float64 `json:"embedding"`
	Index     int       `json:"index"`
}

type EmbeddingRequest

type EmbeddingRequest struct {
	Input  []string `json:"input"`
	UserId string   `json:"user_id"`
}

type EmbeddingResponse

type EmbeddingResponse struct {
	Id      string          `json:"id"`
	Object  string          `json:"object"`
	Created int             `json:"created"`
	Data    []EmbeddingData `json:"data"`
	Usage   EmbeddingUsage  `json:"usage"`
	APIError
}

type EmbeddingUsage

type EmbeddingUsage struct {
	PromptTokens int `json:"prompt_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

type ErnieBot4Request added in v1.0.5

type ErnieBot4Request struct {
	Messages       []ChatCompletionMessage `json:"messages"`
	Temperature    float32                 `json:"temperature,omitempty"`
	TopP           float32                 `json:"top_p,omitempty"`
	Stream         bool                    `json:"stream"`
	UserId         string                  `json:"user_id,omitempty"`
	Functions      []ErnieFunction         `json:"functions,omitempty"`
	PenaltyScore   float32                 `json:"penalty_score,omitempty"`
	System         string                  `json:"system,omitempty"`
	Stop           []string                `json:"stop,omitempty"`
	DisableSearch  bool                    `json:"disable_search,omitempty"`
	EnableCitation bool                    `json:"enable_citation,omitempty"`
}

type ErnieBot4Response added in v1.0.5

type ErnieBot4Response struct {
	ErnieBotResponse
}

type ErnieBot8KRequest added in v1.0.9

type ErnieBot8KRequest struct {
	Messages       []ChatCompletionMessage `json:"messages"`
	Temperature    float32                 `json:"temperature,omitempty"`
	TopP           float32                 `json:"top_p,omitempty"`
	Stream         bool                    `json:"stream"`
	UserId         string                  `json:"user_id,omitempty"`
	Functions      []ErnieFunction         `json:"functions,omitempty"`
	PenaltyScore   float32                 `json:"penalty_score,omitempty"`
	System         string                  `json:"system,omitempty"`
	Stop           []string                `json:"stop,omitempty"`
	DisableSearch  bool                    `json:"disable_search,omitempty"`
	EnableCitation bool                    `json:"enable_citation,omitempty"`
}

type ErnieBot8KResponse added in v1.0.9

type ErnieBot8KResponse struct {
	ErnieBotResponse
}

type ErnieBotRequest

type ErnieBotRequest struct {
	Messages        []ChatCompletionMessage `json:"messages"`
	Temperature     float32                 `json:"temperature,omitempty"`
	TopP            float32                 `json:"top_p,omitempty"`
	PresencePenalty float32                 `json:"presence_penalty,omitempty"`
	Stream          bool                    `json:"stream"`
	UserId          string                  `json:"user_id,omitempty"`
	PenaltyScore    float32                 `json:"penalty_score,omitempty"`
	Functions       []ErnieFunction         `json:"functions,omitempty"`
	System          string                  `json:"system,omitempty"`
	Stop            []string                `json:"stop,omitempty"`
	DisableSearch   bool                    `json:"disable_search,omitempty"`
	EnableCitation  bool                    `json:"enable_citation,omitempty"`
}

type ErnieBotResponse

type ErnieBotResponse struct {
	Id               string            `json:"id"`
	Object           string            `json:"object"`
	Created          int               `json:"created"`
	SentenceId       int               `json:"sentence_id"`
	IsEnd            bool              `json:"is_end"`
	IsTruncated      bool              `json:"is_truncated"`
	Result           string            `json:"result"`
	NeedClearHistory bool              `json:"need_clear_history"`
	Usage            ErnieUsage        `json:"usage"`
	FunctionCall     ErnieFunctionCall `json:"function_call"`
	BanRound         int               `json:"ban_round"`
	SearchInfo       ErnieSearchInfo   `json:"search_info"`
	APIError
}

type ErnieBotTurboAIRequest added in v1.0.9

type ErnieBotTurboAIRequest struct {
	Messages        []ChatCompletionMessage `json:"messages"`
	Stream          bool                    `json:"stream"`
	UserId          string                  `json:"user_id"`
	Temperature     float32                 `json:"temperature,omitempty"`
	TopP            float32                 `json:"top_p,omitempty"`
	PresencePenalty float32                 `json:"presence_penalty,omitempty"`
	PenaltyScore    float32                 `json:"penalty_score,omitempty"`
	System          string                  `json:"system,omitempty"`
}

type ErnieBotTurboAIResponse added in v1.0.9

type ErnieBotTurboAIResponse struct {
	ErnieBotTurboResponse
}

type ErnieBotTurboRequest

type ErnieBotTurboRequest struct {
	Messages        []ChatCompletionMessage `json:"messages"`
	Stream          bool                    `json:"stream"`
	UserId          string                  `json:"user_id"`
	Temperature     float32                 `json:"temperature,omitempty"`
	TopP            float32                 `json:"top_p,omitempty"`
	PresencePenalty float32                 `json:"presence_penalty,omitempty"`
	PenaltyScore    float32                 `json:"penalty_score,omitempty"`
	System          string                  `json:"system,omitempty"`
}

type ErnieBotTurboResponse

type ErnieBotTurboResponse struct {
	Id               string             `json:"id"`
	Object           string             `json:"object"`
	Created          int                `json:"created"`
	SentenceId       int                `json:"sentence_id"`
	IsEnd            bool               `json:"is_end"`
	IsTruncated      bool               `json:"is_truncated"`
	Result           string             `json:"result"`
	NeedClearHistory bool               `json:"need_clear_history"`
	Usage            ErnieBotTurboUsage `json:"usage"`
	BanRound         int                `json:"ban_round"`
	APIError
}

type ErnieBotTurboUsage added in v1.0.9

type ErnieBotTurboUsage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type ErnieCustomPluginRequest added in v1.0.4

type ErnieCustomPluginRequest struct {
	PluginName     string                  `json:"-"`
	Query          string                  `json:"query"`
	Stream         bool                    `json:"stream"`
	Plugins        []string                `json:"plugins"`
	LLM            any                     `json:"llm,omitempty"`
	InputVariables any                     `json:"input_variables,omitempty"`
	History        []ChatCompletionMessage `json:"history,omitempty"`
	Verbose        bool                    `json:"verbose,omitempty"`
	FileUrl        string                  `json:"fileurl,omitempty"`
}

type ErnieCustomPluginResponse added in v1.0.4

type ErnieCustomPluginResponse struct {
	LogId            int64      `json:"log_id"`
	Id               string     `json:"id"`
	Object           string     `json:"object"`
	Created          int        `json:"created"`
	SentenceId       int        `json:"sentence_id"`
	IsEnd            bool       `json:"is_end"`
	Result           string     `json:"result"`
	NeedClearHistory bool       `json:"need_clear_history"`
	BanRound         int        `json:"ban_round"`
	Usage            ErnieUsage `json:"usage"`
	MetaInfo         any        `json:"meta_info"`
	APIError
}

type ErnieCustomPluginStream added in v1.0.4

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

func (ErnieCustomPluginStream) Close added in v1.0.4

func (stream ErnieCustomPluginStream) Close()

func (ErnieCustomPluginStream) Recv added in v1.0.4

func (stream ErnieCustomPluginStream) Recv() (response T, err error)

type ErnieFunction added in v1.0.5

type ErnieFunction struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Parameters  any                    `json:"parameters"`
	Responses   any                    `json:"responses"`
	Examples    []ErnieFunctionExample `json:"examples,omitempty"`
}

type ErnieFunctionCall added in v1.0.5

type ErnieFunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
	Thoughts  string `json:"thoughts"`
}

type ErnieFunctionExample added in v1.0.5

type ErnieFunctionExample struct {
	Role         string            `json:"role"`
	Content      string            `json:"content"`
	Name         string            `json:"name,omitempty"`
	FunctionCall ErnieFunctionCall `json:"function_call,omitempty"`
}

type ErniePluginUsage added in v1.0.5

type ErniePluginUsage struct {
	Name           string `json:"name"`
	ParseTokens    int    `json:"parse_tokens"`
	AbstractTokens int    `json:"abstract_tokens"`
	SearchTokens   int    `json:"search_tokens"`
	TotalTokens    int    `json:"total_tokens"`
}

type ErnieSearchInfo added in v1.0.9

type ErnieSearchInfo struct {
	IsBeset       bool                    `json:"is_beset"`
	ReWrite       string                  `json:"re_write"`
	SearchResults []ErnieSearchInfoResult `json:"search_results"`
}

type ErnieSearchInfoResult added in v1.0.9

type ErnieSearchInfoResult struct {
	Index        int    `json:"index"`
	Url          string `json:"url"`
	Title        string `json:"title"`
	DataSourceId string `json:"data_source_id"`
}

type ErnieUsage

type ErnieUsage struct {
	PromptTokens     int                `json:"prompt_tokens"`
	CompletionTokens int                `json:"completion_tokens"`
	TotalTokens      int                `json:"total_tokens"`
	Plugins          []ErniePluginUsage `json:"plugins"`
}

type ErnireBot4ChatCompletionStream added in v1.0.5

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

func (ErnireBot4ChatCompletionStream) Close added in v1.0.5

func (stream ErnireBot4ChatCompletionStream) Close()

func (ErnireBot4ChatCompletionStream) Recv added in v1.0.5

func (stream ErnireBot4ChatCompletionStream) Recv() (response T, err error)

type ErnireBot8KChatCompletionStream added in v1.0.9

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

func (ErnireBot8KChatCompletionStream) Close added in v1.0.9

func (stream ErnireBot8KChatCompletionStream) Close()

func (ErnireBot8KChatCompletionStream) Recv added in v1.0.9

func (stream ErnireBot8KChatCompletionStream) Recv() (response T, err error)

type ErnireBotChatCompletionStream

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

func (ErnireBotChatCompletionStream) Close

func (stream ErnireBotChatCompletionStream) Close()

func (ErnireBotChatCompletionStream) Recv

func (stream ErnireBotChatCompletionStream) Recv() (response T, err error)

type ErnireBotTurboAIChatCompletionStream added in v1.0.9

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

func (ErnireBotTurboAIChatCompletionStream) Close added in v1.0.9

func (stream ErnireBotTurboAIChatCompletionStream) Close()

func (ErnireBotTurboAIChatCompletionStream) Recv added in v1.0.9

func (stream ErnireBotTurboAIChatCompletionStream) Recv() (response T, err error)

type ErnireBotTurboChatCompletionStream

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

func (ErnireBotTurboChatCompletionStream) Close

func (stream ErnireBotTurboChatCompletionStream) Close()

func (ErnireBotTurboChatCompletionStream) Recv

func (stream ErnireBotTurboChatCompletionStream) Recv() (response T, err error)

type ImageRequest added in v1.0.5

type ImageRequest struct {
	Prompt string `json:"prompt"`
	Width  int    `json:"width,omitempty"`
	Height int    `json:"height,omitempty"`
	Model  string `json:"-"`
}

type ImageResponse added in v1.0.5

type ImageResponse struct {
	Images []string `json:"images"`
	APIError
}

type LlamaChatCompletionStream

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

func (LlamaChatCompletionStream) Close

func (stream LlamaChatCompletionStream) Close()

func (LlamaChatCompletionStream) Recv

func (stream LlamaChatCompletionStream) Recv() (response T, err error)

type LlamaChatRequest

type LlamaChatRequest struct {
	Messages []ChatCompletionMessage `json:"messages"`
	Stream   bool                    `json:"stream"`
	UserId   string                  `json:"user_id"`
	Model    string                  `json:"-"`
}

type LlamaChatResponse

type LlamaChatResponse struct {
	ErnieBotResponse
}

type RequestError

type RequestError struct {
	HTTPStatusCode int
	Err            error
}

func (*RequestError) Error

func (e *RequestError) Error() string

func (*RequestError) Unwrap

func (e *RequestError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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