-
Notifications
You must be signed in to change notification settings - Fork 19
/
prompt.go
59 lines (54 loc) · 1.76 KB
/
prompt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// File: gollm/prompt.go
package gollm
import (
"github.com/teilomillet/gollm/llm"
"github.com/teilomillet/gollm/utils"
"strings"
)
// Re-export types from llm package
type (
Prompt = llm.Prompt
CacheType = llm.CacheType
PromptMessage = llm.PromptMessage
Function = utils.Function
Tool = utils.Tool
PromptOption = llm.PromptOption
SchemaOption = llm.SchemaOption
ToolCall = llm.ToolCall
MemoryMessage = llm.MemoryMessage
PromptTemplate = llm.PromptTemplate
)
// Re-export constants
const (
CacheTypeEphemeral = llm.CacheTypeEphemeral
)
// Re-export functions
var (
NewPrompt = llm.NewPrompt
CacheOption = llm.CacheOption
WithSystemPrompt = llm.WithSystemPrompt
WithMessage = llm.WithMessage
WithTools = llm.WithTools
WithToolChoice = llm.WithToolChoice
WithMessages = llm.WithMessages
WithDirectives = llm.WithDirectives
WithOutput = llm.WithOutput
WithContext = llm.WithContext
WithMaxLength = llm.WithMaxLength
WithExamples = llm.WithExamples
WithExpandedStruct = llm.WithExpandedStruct
NewPromptTemplate = llm.NewPromptTemplate
WithPromptOptions = llm.WithPromptOptions
WithJSONSchemaValidation = llm.WithJSONSchemaValidation
)
// CleanResponse removes markdown code block syntax and trims the JSON response
func CleanResponse(response string) string {
response = strings.TrimPrefix(response, "```json")
response = strings.TrimSuffix(response, "```")
start := strings.Index(response, "{")
end := strings.LastIndex(response, "}")
if start != -1 && end != -1 && end > start {
response = response[start : end+1]
}
return strings.TrimSpace(response)
}