utils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommonPrompts = struct {
	// RootCauseAnalysis 根因分析模板
	RootCauseAnalysis string

	// ProblemSummary 问题摘要模板
	ProblemSummary string

	// RecommendationGeneration 建议生成模板
	RecommendationGeneration string
}{
	RootCauseAnalysis: `You are an expert system administrator analyzing system failures.

## Context
{{context}}

## Task
Analyze the above information and identify the root cause of the failure.

## Output Format
Provide your analysis in the following JSON format:
{
  "root_cause": "Brief description of the root cause",
  "confidence": 0.0-1.0,
  "reasoning": "Detailed explanation of your analysis",
  "contributing_factors": ["factor1", "factor2", ...]
}`,

	ProblemSummary: `Summarize the following problem in a clear and concise manner.

## Problem Details
{{problem}}

## Requirements
1. Keep it under 100 words
2. Focus on the key issues
3. Use technical but accessible language`,

	RecommendationGeneration: `Based on the following root cause analysis, generate actionable recommendations.

## Root Cause
{{root_cause}}

## Context
{{context}}

## Requirements
1. Provide at least 3 recommendations
2. Prioritize by impact and feasibility
3. Include specific steps where possible`,
}

CommonPrompts 提供常用的 Prompt 模板

Functions

This section is empty.

Types

type Example

type Example struct {
	Input  string
	Output string
}

Example 示例定义

type PromptBuilder

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

PromptBuilder 提供 Prompt 构建工具

func NewPromptBuilder

func NewPromptBuilder() *PromptBuilder

NewPromptBuilder 创建 Prompt 构建器

func (*PromptBuilder) Build

func (b *PromptBuilder) Build() string

Build 构建最终的 Prompt

func (*PromptBuilder) BuildWithTemplate

func (b *PromptBuilder) BuildWithTemplate(template string, vars map[string]string) string

BuildWithTemplate 使用模板构建 Prompt

func (*PromptBuilder) Reset

func (b *PromptBuilder) Reset() *PromptBuilder

Reset 重置构建器

func (*PromptBuilder) WithConstraint

func (b *PromptBuilder) WithConstraint(constraint string) *PromptBuilder

WithConstraint 添加约束条件

func (*PromptBuilder) WithConstraints

func (b *PromptBuilder) WithConstraints(constraints []string) *PromptBuilder

WithConstraints 添加多个约束条件

func (*PromptBuilder) WithContext

func (b *PromptBuilder) WithContext(ctx string) *PromptBuilder

WithContext 添加上下文信息

func (*PromptBuilder) WithContexts

func (b *PromptBuilder) WithContexts(contexts []string) *PromptBuilder

WithContexts 添加多个上下文信息

func (*PromptBuilder) WithExample

func (b *PromptBuilder) WithExample(input, output string) *PromptBuilder

WithExample 添加示例

func (*PromptBuilder) WithOutputFormat

func (b *PromptBuilder) WithOutputFormat(format string) *PromptBuilder

WithOutputFormat 设置输出格式要求

func (*PromptBuilder) WithSystemPrompt

func (b *PromptBuilder) WithSystemPrompt(prompt string) *PromptBuilder

WithSystemPrompt 设置系统提示

func (*PromptBuilder) WithTask

func (b *PromptBuilder) WithTask(task string) *PromptBuilder

WithTask 设置任务描述

type ResponseParser

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

ResponseParser 提供响应解析工具

func NewResponseParser

func NewResponseParser(content string) *ResponseParser

NewResponseParser 创建响应解析器

func (*ResponseParser) ExtractAllCodeBlocks

func (p *ResponseParser) ExtractAllCodeBlocks() map[string]string

ExtractAllCodeBlocks 提取所有代码块

func (*ResponseParser) ExtractCodeBlock

func (p *ResponseParser) ExtractCodeBlock(language string) (string, error)

ExtractCodeBlock 提取指定语言的代码块

func (*ResponseParser) ExtractJSON

func (p *ResponseParser) ExtractJSON() (string, error)

ExtractJSON 提取 JSON 内容

func (*ResponseParser) ExtractKeyValue

func (p *ResponseParser) ExtractKeyValue(key string) (string, error)

ExtractKeyValue 提取键值对

func (*ResponseParser) ExtractList

func (p *ResponseParser) ExtractList() []string

ExtractList 提取列表项

func (*ResponseParser) ExtractSection

func (p *ResponseParser) ExtractSection(title string) (string, error)

ExtractSection 提取指定章节

func (*ResponseParser) GetPlainText

func (p *ResponseParser) GetPlainText() string

GetPlainText 获取纯文本内容

func (*ResponseParser) IsEmpty

func (p *ResponseParser) IsEmpty() bool

IsEmpty 检查内容是否为空

func (*ResponseParser) Length

func (p *ResponseParser) Length() int

Length 返回内容长度

func (*ResponseParser) ParseToMap

func (p *ResponseParser) ParseToMap() (map[string]interface{}, error)

ParseToMap 解析为 map

func (*ResponseParser) ParseToStruct

func (p *ResponseParser) ParseToStruct(v interface{}) error

ParseToStruct 解析为结构体

func (*ResponseParser) RemoveMarkdown

func (p *ResponseParser) RemoveMarkdown() string

RemoveMarkdown 移除 Markdown 格式 使用预编译的正则表达式提升性能,避免每次调用都重新编译

Directories

Path Synopsis
Package httpclient 提供统一的 HTTP 客户端管理
Package httpclient 提供统一的 HTTP 客户端管理

Jump to

Keyboard shortcuts

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