corefactorer

package
v0.0.0-...-782f10a Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	// CreateRefactoringTarget creates `RefactoringTarget` from the given prompt with GenAI FunctionCalling feature
	CreateRefactoringTarget(ctx context.Context, prompt string, model string, temperature float32) (*RefactoringTarget, error)

	// CreateRefactoringResult sends a request of refactoring to GenAI API.
	// The chat message in the request includes an original user prompt and fetched pull-request info and file content in given `RefactoringRequest`.
	CreateRefactoringResult(ctx context.Context, req *RefactoringRequest) (*RefactoringResult, error)
}

func NewAgent

func NewAgent(model string, logger *slog.Logger) (Agent, error)

func NewClaudeAgent

func NewClaudeAgent(client *anthropic.Client, logger *slog.Logger) Agent

func NewGeminiAgent

func NewGeminiAgent(client *genai.Client, logger *slog.Logger) Agent

func NewOpenAIAgent

func NewOpenAIAgent(client *openai.Client, logger *slog.Logger) Agent

type App

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

func New

func New(
	logger *slog.Logger,
	agent Agent,
	githubClient *github.Client,
	httpClient *http.Client,
) *App

func (*App) ApplyRefactoringResult

func (a *App) ApplyRefactoringResult(ctx context.Context, result *RefactoringResult) error

func (*App) CreateRefactoringRequest

func (a *App) CreateRefactoringRequest(ctx context.Context, target *RefactoringTarget) (*RefactoringRequest, error)

CreateRefactoringRequest creates `RefactoringRequest`. It fetches pull request content from GitHub and file content local machine.

func (*App) CreateRefactoringResult

func (a *App) CreateRefactoringResult(ctx context.Context, req *RefactoringRequest) (*RefactoringResult, error)

CreateRefactoringResult sends a request of refactoring to OpenAI API. The chat message in the request includes an original user prompt and fetched pull-request info and file content in given `RefactoringRequest`.

func (*App) CreateRefactoringTarget

func (a *App) CreateRefactoringTarget(
	ctx context.Context,
	prompt string,
	model string,
	temperature float32,
) (*RefactoringTarget, error)

CreateRefactoringTarget creates `RefactoringTarget` from the given prompt with OpenAI FunctionCalling feature

type ClaudeAgent

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

func (*ClaudeAgent) CreateRefactoringResult

func (a *ClaudeAgent) CreateRefactoringResult(ctx context.Context, req *RefactoringRequest) (*RefactoringResult, error)

func (*ClaudeAgent) CreateRefactoringTarget

func (a *ClaudeAgent) CreateRefactoringTarget(ctx context.Context, prompt string, modelName string, temperature float32) (*RefactoringTarget, error)

type GeminiAgent

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

func (*GeminiAgent) CreateRefactoringResult

func (a *GeminiAgent) CreateRefactoringResult(ctx context.Context, req *RefactoringRequest) (*RefactoringResult, error)

func (*GeminiAgent) CreateRefactoringTarget

func (a *GeminiAgent) CreateRefactoringTarget(ctx context.Context, prompt string, modelName string, temperature float32) (*RefactoringTarget, error)

type OpenAIAgent

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

func (*OpenAIAgent) CreateRefactoringResult

func (a *OpenAIAgent) CreateRefactoringResult(ctx context.Context, req *RefactoringRequest) (*RefactoringResult, error)

func (*OpenAIAgent) CreateRefactoringTarget

func (a *OpenAIAgent) CreateRefactoringTarget(ctx context.Context, prompt string, model string, temperature float32) (*RefactoringTarget, error)

type PullRequest

type PullRequest struct {
	URL   string
	Title string
	Body  string
	Diff  string
}

type RefactoringRequest

type RefactoringRequest struct {
	// UserPrompt is a message given from user
	UserPrompt string
	// ToolCallID is an ID of ToolCall in first chat completion. It'll be used in the future.
	ToolCallID string
	// PullRequests is a list of pull requests to be referred. Currently only 1st PR is used.
	PullRequests []*PullRequest
	// TargetFiles is a list of files to be refactored.
	TargetFiles []*TargetFile
}

func (*RefactoringRequest) CreateAssistanceMessage

func (rr *RefactoringRequest) CreateAssistanceMessage() (string, error)

func (*RefactoringRequest) String

func (rr *RefactoringRequest) String() string

type RefactoringResult

type RefactoringResult struct {
	RawContent string
}

type RefactoringTarget

type RefactoringTarget struct {
	// UserPrompt is a message given from user
	UserPrompt string
	// ToolCallID is an ID of ToolCall in first chat completion. It'll be used in the future.
	ToolCallID      string
	PullRequestURLs []string
	Files           []string
}

func (*RefactoringTarget) String

func (rt *RefactoringTarget) String() string

func (*RefactoringTarget) Unique

func (rt *RefactoringTarget) Unique() *RefactoringTarget

func (*RefactoringTarget) Validate

func (rt *RefactoringTarget) Validate() error

type TargetFile

type TargetFile struct {
	Path    string
	Content string
}

Jump to

Keyboard shortcuts

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