xhttp

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleNonStreamResponseUnTyped

func HandleNonStreamResponseUnTyped(ctx context.Context, resp *http.Response, isOpenAI bool, ch chan<- any) error

HandleNonStreamResponseUnTyped 处理非流式响应

func HandleStreamResponseUnTyped

func HandleStreamResponseUnTyped(ctx context.Context, resp *http.Response, isOpenAI bool, ch chan<- any) error

HandleStreamResponseUnTyped 处理流式响应

func HandlerHttpWithChannel

func HandlerHttpWithChannel(xRequest XRequest, isPreCooked bool, ch chan<- any) error

HandlerHttpWithChannel HTTP 请求处理函数

Types

type ChatGPTRequest

type ChatGPTRequest struct {
	Model       string              `json:"model"`
	Messages    []map[string]string `json:"messages"`
	Stream      *bool               `json:"stream"`
	MaxTokens   *int                `json:"max_tokens"`
	Temperature *float32            `json:"temperature"`
	TopP        *float32            `json:"top_p"`
}

ChatGPTRequest ChatGPT API 请求的结构体

type ChatGPTResponse

type ChatGPTResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Model   string `json:"model"`
	Usage   Usage  `json:"usage"`
	Choices []struct {
		Index   int `json:"index"`
		Message struct {
			Role    string `json:"role"`
			Content string `json:"content"`
		} `json:"message"`
		FinishReason string `json:"finish_reason,omitempty"`
	} `json:"choices"`
}

ChatGPTResponse OpenAI API 响应的结构体(非流式)

func (*ChatGPTResponse) GetResponse

func (c *ChatGPTResponse) GetResponse() string

type ChatGPTStreamResponse

type ChatGPTStreamResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Model   string `json:"model"`
	Choices []struct {
		Delta struct {
			Content string `json:"content"`
		} `json:"delta"`
		FinishReason string `json:"finish_reason,omitempty"`
	} `json:"choices"`
}

ChatGPTStreamResponse OpenAI API 流式响应的结构体

func (*ChatGPTStreamResponse) GetResponse

func (c *ChatGPTStreamResponse) GetResponse() string

type Usage

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

type XRequest

type XRequest struct {
	Id      string              `json:"id"`
	Url     string              `json:"url"`
	Method  string              `json:"method"`
	Headers map[string][]string `json:"headers"`
	Body    any                 `json:"body"`
}

Jump to

Keyboard shortcuts

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