openai

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: MulanPSL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DeepSeekR1 深度思考模型
	DeepSeekR1 = common.Model{
		Url:       "https://api.deepseek.com/chat/completions",
		ModelType: "deepseek-reasoner",
		IsReason:  true,
	}
	// DeepSeekV3 对话模型
	DeepSeekV3 = common.Model{
		Url:       "https://api.deepseek.com/chat/completions",
		ModelType: "deepseek-chat",
		IsReason:  false,
	}
	// IflytekX 讯飞星火对话模型
	IflytekX = common.Model{
		Url:       "http://maas-api.cn-huabei-1.xf-yun.com/v1/chat/completions",
		ModelType: "xsparkprox",
		IsReason:  false,
	}
)

Functions

This section is empty.

Types

type ChatResponse

type ChatResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	Choices []struct {
		Message struct {
			Role    string `json:"role"`
			Content string `json:"content"`
		} `json:"message"`
		FinishReason string `json:"finish_reason"`
	} `json:"choices"`
	Usage struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
		TotalTokens      int `json:"total_tokens"`
	} `json:"usage"`
}

ChatResponse 响应结构体(根据实际 API 响应格式调整)

func (*ChatResponse) Message

func (cr *ChatResponse) Message() string

func (*ChatResponse) Think

func (cr *ChatResponse) Think() string

type OpenAI

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

func NewOpenAiClient

func NewOpenAiClient(model common.Model) *OpenAI

func (*OpenAI) Chat added in v0.0.3

func (o *OpenAI) Chat(message string) (*common.Response, error)

Chat 发送对话,获取结果

func (*OpenAI) SetApiKey added in v0.0.3

func (o *OpenAI) SetApiKey(apiKey string) *OpenAI

SetApiKey 设置更新apikey

func (*OpenAI) SetMaxRounds

func (o *OpenAI) SetMaxRounds(maxRounds int) *OpenAI

SetMaxRounds 设置历史保存轮数

func (*OpenAI) SetMaxTokens

func (o *OpenAI) SetMaxTokens(maxTokens int) *OpenAI

SetMaxTokens 设置最大token数

func (*OpenAI) SetResponseType added in v0.0.4

func (o *OpenAI) SetResponseType(t string) *OpenAI

SetResponseType 设置OpenAI实例的响应格式类型。

func (*OpenAI) SetStream

func (o *OpenAI) SetStream(enable bool) *OpenAI

SetStream 设置是否流式返回

func (*OpenAI) SetTemperature

func (o *OpenAI) SetTemperature(temperature float64) *OpenAI

SetTemperature 设置模型温度 0~1 值越高模型约自由发挥

Jump to

Keyboard shortcuts

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