openai

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnySummarizationPrompt = lo.Must(template.New("anything summarization prompt").Parse("" +
	`内容:{{ .Content }}
你是我的总结助手。我将为你提供一段话,我需要你在不丢失原文主旨和情感、不做更多的解释和说明的情况下帮我用不超过100字总结一下这段话说了什么。`))
View Source
var ChatHistorySummarizationPrompt = lo.Must(template.New("chat histories summarization prompt").Parse("" +
	`Chat histories:"""
{{ .ChatHistory }}
"""

You are a expert in summarizing the refined outlines from documents and dialogues. Please read through the provided chat history and identify the 1-10 distinct discussion topics that discussed and talked about.

Output topics correspond the following JSON Schema types, and output the result in language {{ .Language }}:"""
{"$schema":"http://json-schema.org/draft-07/schema#","title":"Chat Histories Summarization Schema","type":"array","items":{"type":"object","properties":{"topicName":{"type":"string","description":"The title, brief short title of the topic that talked, discussed in the chat history."},"sinceId":{"type":"number","description":"The id of the message from which the topic initially starts."},"participants":{"type":"array","description":"The list of the names of the participated users in the topic.","items":{"type":"string"}},"discussion":{"type":"array","description":"The list of the points that discussed during the topic.","items":{"type":"object","properties":{"point":{"type":"string","description":"The key point that talked, expressed, mentioned, or discussed during the topic."},"keyIds":{"type":"array","description":"The list of the ids of the messages that contain the key point.","items":{"type":"number"}}},"required":["point","keyIds"]},"minItems": 1,"maxItems": 5},"conclusion":{"type":"string","description":"The conclusion of the topic, optional."}},"required":["topicName","sinceId","participants","discussion"]}}
"""

For example:"""
[{"topicName":"Most Important Topic 1","sinceId":123456789,"participants":["John","Mary"],"discussion":[{"point":"Most relevant key point","keyIds":[123456789,987654321]}],"conclusion":"Optional brief conclusion"},{"topicName":"Most Important Topic 2","sinceId":987654321,"participants":["Bob","Alice"],"discussion":[{"point":"Most relevant key point","keyIds":[987654321]}],"conclusion":"Optional brief conclusion"}]
"""

Please note the topics may be discussed in parallel, so please consider the relevant keywords that appeared across the chat histories. Summarize the distinct topics from the chat history. For each topic, extract the most relevant 1-5 points and key message IDs. Be very concise and focused on the key essence of each topic.`))

Functions

func NewClient

func NewClient(enableMetricRecordForTokens bool) func(NewClientParams) (Client, error)

Types

type AnySummarizationInputs

type AnySummarizationInputs struct {
	Content string
}

type ChatHistorySummarizationOutputs

type ChatHistorySummarizationOutputs struct {
	TopicName    string                                       `json:"topicName"`
	SinceID      int64                                        `json:"sinceId"`
	Participants []string                                     `json:"participants"`
	Discussion   []*ChatHistorySummarizationOutputsDiscussion `json:"discussion"`
	Conclusion   string                                       `json:"conclusion"`
}

type ChatHistorySummarizationOutputsDiscussion

type ChatHistorySummarizationOutputsDiscussion struct {
	Point  string  `json:"point"`
	KeyIDs []int64 `json:"keyIds"`
}

type ChatHistorySummarizationPromptInputs

type ChatHistorySummarizationPromptInputs struct {
	ChatHistory string
	Language    string
}

func NewChatHistorySummarizationPromptInputs

func NewChatHistorySummarizationPromptInputs(chatHistory string, language string) *ChatHistorySummarizationPromptInputs

type Client

type Client interface {
	GetModelName() string
	SplitContentBasedByTokenLimitations(textContent string, limits int) []string
	SummarizeAny(ctx context.Context, content string) (*openai.ChatCompletionResponse, error)
	SummarizeChatHistories(ctx context.Context, llmFriendlyChatHistories string) (*openai.ChatCompletionResponse, error)
	SummarizeOneChatHistory(ctx context.Context, llmFriendlyChatHistory string) (*openai.ChatCompletionResponse, error)
	SummarizeWithQuestionsAsSimplifiedChinese(ctx context.Context, title string, by string, content string) (*openai.ChatCompletionResponse, error)
	TruncateContentBasedOnTokens(textContent string, limits int) string
}

type NewClientParams

type NewClientParams struct {
	fx.In

	Config *configs.Config
	Logger *logger.Logger
	Ent    *datastore.Ent
}

type OpenAIClient

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

func (*OpenAIClient) GetModelName added in v0.18.0

func (c *OpenAIClient) GetModelName() string

func (*OpenAIClient) SplitContentBasedByTokenLimitations

func (c *OpenAIClient) SplitContentBasedByTokenLimitations(textContent string, limits int) []string

SplitContentBasedByTokenLimitations 基于 token 计算的方式分割文本。

func (*OpenAIClient) SummarizeAny

func (c *OpenAIClient) SummarizeAny(ctx context.Context, content string) (*openai.ChatCompletionResponse, error)

SummarizeAny 通过 OpenAI 的 Chat API 来为任意内容生成摘要。

func (*OpenAIClient) SummarizeChatHistories

func (c *OpenAIClient) SummarizeChatHistories(ctx context.Context, llmFriendlyChatHistories string) (*openai.ChatCompletionResponse, error)

func (*OpenAIClient) SummarizeOneChatHistory

func (c *OpenAIClient) SummarizeOneChatHistory(ctx context.Context, llmFriendlyChatHistory string) (*openai.ChatCompletionResponse, error)

func (*OpenAIClient) SummarizeWithQuestionsAsSimplifiedChinese

func (c *OpenAIClient) SummarizeWithQuestionsAsSimplifiedChinese(ctx context.Context, title, by, content string) (*openai.ChatCompletionResponse, error)

SummarizeWithQuestionsAsSimplifiedChinese 通过 OpenAI 的 Chat API 来为文章生成摘要和联想问题。

func (*OpenAIClient) TruncateContentBasedOnTokens

func (c *OpenAIClient) TruncateContentBasedOnTokens(textContent string, limits int) string

truncateContentBasedOnTokens 基于 token 计算的方式截断文本。

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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