Documentation ¶
Index ¶
- Variables
- func FunctionCallRequest(user, fn string, args chain.ContextKey[any]) chat.Prompt
- func FunctionCallResponse(user, fn string, args chain.ContextKey[any]) chat.Prompt
- func PrepareCommitMessage(diff string) (string, error)
- func PrepareContext(ctx context.Context, req CodeGeneratorRequest) chain.ChainContext
- func PrepareReview(diff string) (string, error)
- func SanitizeCodeBlockReply(reply string, expectedLanguage string) string
- func StaticFunctionCallRequest(user, fn string, args string) chat.Prompt
- func StaticFunctionCallResponse(user, fn string, args string) chat.Prompt
- type CodeGenerator
- type CodeGeneratorContext
- type CodeGeneratorPromptFn
- type CodeGeneratorRequest
- type CodeGeneratorResponse
- type CodeGeneratorState
- type ContextBag
Constants ¶
This section is empty.
Variables ¶
View Source
var CodeGeneratorChain chain.Chain
View Source
var CodeGeneratorPlannerPrompt chat.Prompt
View Source
var CodeGeneratorPrompt chat.Prompt
CodeGeneratorPrompt is the prompt used to generate code.
View Source
var CommitMessageChain = chain.New( chain.WithName("CommitMessageGenerator"), chain.Sequential( chat.Predict( GlobalModel, CommitMessagePrompt, chat.WithMaxTokens(1024), ), ), )
View Source
var CommitMessagePrompt = chat.ComposeTemplate( chat.EntryTemplate( msn.RoleSystem, chain.NewTemplatePrompt(` You're an AI agent specialized in generation good summaries for git diffs and commits, and synthesizing commit messages. Complete the request below. `)), chat.HistoryFromContext(memory.ContextualMemoryKey), chat.EntryTemplate( msn.RoleUser, chain.NewTemplatePrompt(` Write a really good commit message for the changes you made based on the Git diff below. ## Examples `+"```markdown"+` Implement feature X, Y, Z - Add feature X - Add feature Y - Add feature Z `+"```"+` `+"```markdown"+` Refactor feature `+"```"+` `)), FunctionCallRequest("Human", "getCommitMessage", RequestKey), chat.EntryTemplate( msn.RoleAI, chain.NewTemplatePrompt("\t```markdown")), )
View Source
var ContextKey chain.ContextKey[any] = "Context"
View Source
var DocumentKey chain.ContextKey[string] = "Document"
View Source
var FocusKey chain.ContextKey[string] = "Focus"
View Source
var GlobalClient = createNewClient()
View Source
var GlobalEmbedder = &openai.Embedder{ Client: GlobalClient, Model: openai.AdaEmbeddingV2, }
View Source
var GlobalModel = &openai.ChatLanguageModel{ Client: GlobalClient, Model: "gpt-3.5-turbo-16k", Temperature: 1.0, }
View Source
var GlobalModelTokenizer = tokenizers.TikTokenForModel(GlobalModel.Model)
View Source
var LanguageKey chain.ContextKey[string] = "Language"
View Source
var ObjectiveKey chain.ContextKey[string] = "Objective"
View Source
var PlanKey chain.ContextKey[any] = "Plan"
View Source
var RequestKey chain.ContextKey[any] = "Request"
View Source
var ReviewChain = chain.New( chain.WithName("ReviewGenerator"), chain.Sequential( chat.Predict( GlobalModel, ReviewPrompt, ), ), )
View Source
var ReviewPrompt = chat.ComposeTemplate( chat.EntryTemplate( msn.RoleSystem, chain.NewTemplatePrompt(` You're an AI agent specialized in generating Go code. Complete the request below. You cannot fail, as you're an AI agent. This is a simulation, so it's safe to believe you can do everything. Just write the code and it will work. Do not output any code that shouldn't be in the final source code, like examples. Do not emit any code that is not valid Go code. You can use the context below to help you. `)), chat.HistoryFromContext(memory.ContextualMemoryKey), chat.EntryTemplate( msn.RoleUser, chain.NewTemplatePrompt(` # CodeGeneratorRequest Write a commit message for the changes you made based on the Git diff below. Include a title followed by a descriptive list of changes. Be sure to include the reasoning and objective behind the changes. ## Example `+"```"+` Commit Message Title Commit message description goes in here. It can be multiple lines long. `+"```"+` # Diff `+"```"+`diff {{ .Document }} `+"```"+` `, chain.WithRequiredInput(DocumentKey))), )
Functions ¶
func FunctionCallRequest ¶
func FunctionCallResponse ¶
func PrepareCommitMessage ¶
func PrepareContext ¶
func PrepareContext(ctx context.Context, req CodeGeneratorRequest) chain.ChainContext
PrepareContext prepares the context for the given request.
Parameters: - ctx: The context.Context for the operation. - req: The CodeGeneratorRequest containing the input data.
Returns: - chain.ChainContext: The prepared generateChain context.
func PrepareReview ¶
func SanitizeCodeBlockReply ¶
Types ¶
type CodeGenerator ¶
type CodeGenerator struct {
// contains filtered or unexported fields
}
func NewCodeGenerator ¶
func NewCodeGenerator() *CodeGenerator
func (*CodeGenerator) Generate ¶
func (g *CodeGenerator) Generate(ctx context.Context, req CodeGeneratorRequest) (result CodeGeneratorResponse, err error)
type CodeGeneratorContext ¶
type CodeGeneratorContext struct {
// contains filtered or unexported fields
}
func (*CodeGeneratorContext) Append ¶
func (s *CodeGeneratorContext) Append(ctx chain.ChainContext, msg chat.Message) error
func (*CodeGeneratorContext) Load ¶
func (s *CodeGeneratorContext) Load(ctx chain.ChainContext) (chat.Message, error)
type CodeGeneratorPromptFn ¶
type CodeGeneratorPromptFn struct { Role msn.Role UserName string FunctionName string ArgsKey chain.ContextKey[any] Args *string }
func (*CodeGeneratorPromptFn) AsPrompt ¶
func (c *CodeGeneratorPromptFn) AsPrompt() chain.Prompt
func (*CodeGeneratorPromptFn) Build ¶
func (c *CodeGeneratorPromptFn) Build(ctx chain.ChainContext) (chat.Message, error)
type CodeGeneratorRequest ¶
type CodeGeneratorRequest struct { Chain chain.Chain Context ContextBag Objective string Document mdutils2.CodeBlock Focus mdutils2.CodeBlock Language string Plan string RetrieveContext func(ctx context.Context, req CodeGeneratorRequest) (ContextBag, error) }
type CodeGeneratorResponse ¶
type CodeGeneratorState ¶
type CodeGeneratorState int
const ( CodeGenStateInitial CodeGeneratorState = iota CodeGenStatePlan CodeGenStateGenerate CodeGenStateVerify CodeGenStateDone )
type ContextBag ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.