coze

package
v0.0.0-...-e9a2108 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(server string, key string, dialer proxy.Dialer) base.Provider

Types

type Client

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

func (*Client) Completion

func (client *Client) Completion(ctx context.Context, openaiReq openai.ChatCompletionRequest, w http.ResponseWriter) error

func (*Client) CompletionStream

func (client *Client) CompletionStream(ctx context.Context, openaiReq openai.ChatCompletionRequest, w http.ResponseWriter) error

type ErrorInformation

type ErrorInformation struct {
	Code int    `json:"code,omitempty"`
	Msg  string `json:"msg,omitempty"`
}

type Message

type Message struct {
	// Role The role who returns the message
	// user: the content from user input
	// assistant: returned by bot
	Role string `json:"role"`
	// Type The type of the message when the role is assistant.
	// answer: The completed messages that the bot returns to the user.
	// function_cal:The intermediate result when deciding to use the function call during the bot conversation process.
	// tool_response:The final result from the function call.
	// follow_up:The content is returned when the auto-suggestion is enabled for the bot.
	Type string `json:"type,omitempty"`
	// Content The returned content
	Content string `json:"content"`
	// ContentType The type of the return content.
	// When the type is answer, the content will be returned in Markdown.
	ContentType string `json:"content_type,omitempty"`
}

type Request

type Request struct {
	// BotID The ID of the bot that the API interacts with.
	// Go to the Develop page of your Coze bot. The number after the bot parameter in the page URL is the bot ID.
	// For example: https://www.coze.com/space/73428668341****/bot/73428668*****. The bot ID is73428668*****.
	BotID string `json:"bot_id"`
	// ConversationID Indicate which conversation the dialog is taking place in.
	// If there is no need to distinguish the context of the conversation (just a question and answer),
	// skip this parameter. It will be generated by the system.
	ConversationID string `json:"conversation_id,omitempty"`
	// User The user who calls the API to chat with the bot.
	User string `json:"user"`
	// Query The query sent to the bot
	Query string `json:"query"`
	// ChatHistory The chat history to pass as the context.
	// If you want to manually add the chat history in the conversation, do as follows:
	// - chat_history is a list containing the user request and conversation data returned by the API. For details, refer to the Message structure in the Response parameters section.
	// - The whole list is sorted in ascending order of time. That is, the latest message of the previous conversation appears at the end of the list.
	// - (Optional) Pass the intermediate results returned by the API back through the chat history and insert them into the chat_history in ascending order by index.
	ChatHistory []Message `json:"chat_history,omitempty"`
	// Stream Whether to stream the response to the client.
	// - false: if no value is specified or set to false, a non-streaming response is returned.
	//   "Non-streaming response" means that all responses will be returned at once after they are all ready,
	//   and the client does not need to concatenate the content.
	// - true: set to true, partial message deltas will be sent .
	//   "Streaming response" will provide real-time response of the model to the client, and the client needs to assemble
	//   the final reply based on the type of message.
	Stream bool `json:"stream"`
	// CustomVariables The customized variable in a key-value pair
	CustomVariables map[string]string `json:"custom_variables,omitempty"`
}

type Response

type Response struct {
	// ConversationID The ID of the conversation
	ConversationID string `json:"conversation_id,omitempty"`
	// Messages The completed messages returned in JSON array.
	// For details, refer to the Message structure in the Response parameters section.
	Messages []Message `json:"messages"`
	// Code The ID of the code. 0 represents a successful call.
	Code int `json:"code,omitempty"`
	// Msg The message of the request.
	Msg string `json:"msg,omitempty"`

	// Event The data set returned in the event.
	// - message: the real-time message returned.
	//   data:{"event":"message","message":{"role":"assistant","type":"answer","content":"!","content_type":"text","extra_info":null},"is_finish":false,"index":0,"conversation_id":"123"}
	//
	// - done: indicates that the chat is finished.
	//   data:{"event":"done"}
	//
	// - error: indicates that an error occurs when responsing the message.
	//   data:{"event":"error", "error_information":{"code": 700007,"msg":invalid permission}}
	Event string `json:"event,omitempty"`
	// IsFinish Whether the current message is completed.
	// - false: not completed.
	// - true: completed. The current message is completed, not the whole message is sent completed when the value is true.
	IsFinish bool `json:"is_finish,omitempty"`
	// Index The identifier of the message. Each unique index corresponds to a single message.
	Index int `json:"index,omitempty"`
	// Message Incremental response messages in stream mode
	Message Message `json:"message,omitempty"`

	ErrorInformation ErrorInformation `json:"error_information,omitempty"`
}

Jump to

Keyboard shortcuts

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