package
0.2.0
Repository: https://github.com/mgla96/snappr.git
Documentation: pkg.go.dev

# README

clients

import "github.com/Mgla96/snappr/internal/adapters/clients"

package clients provides the clients for the external services used by the application.

Index

Constants

const (
    // GPT3_5Turbo0125 is the GPT-3.5-turbo-0125 model.
    GPT3_5Turbo0125            ModelType = "gpt-3.5-turbo-0125"
    GPT4_turbo                 ModelType = "gpt-4-turbo"
    ErrNoChatCompletionChoices           = errors.New("no chat completion choices returned")
    OLLAMAAPI                  APIType   = "ollama"
    OPENAIAPI                  APIType   = "openai"
)

func IsDoNotEditFile

func IsDoNotEditFile(data []byte) bool

IsDoNotEditFile checks if the file has a DO NOT EDIT comment.

func ModelToContextWindow

func ModelToContextWindow(model ModelType) int

ModelToContextWindow returns the context window size for the given model.

func Shuffle

func Shuffle(slice interface{})

Shuffle shuffles a slice of any type

type APIType

type APIType string

type CodeFilter

CodeFilter is used to filter files based on a regex pattern.

type CodeFilter struct {
    FileRegexPattern string
}

type GithubClient

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

func NewGithubClient

func NewGithubClient(token string, logger zerolog.Logger) *GithubClient

NewGithubClient creates a new instance of the GithubClient.

func (*GithubClient) AddCommentToPullRequestReview

func (gc *GithubClient) AddCommentToPullRequestReview(ctx context.Context, owner, repo string, prNumber int, commentBody, commitID, path string, startLine, line int) (*github.PullRequestComment, error)

AddCommentToPullRequestReview adds a comment to a pull request review.

Parameters:

  • ctx: The context for the API request.
  • owner: The owner of the repository.
  • repo: The repository name.
  • prNumber: The pull request number.
  • commentBody: The content of the comment to be added.
  • commitID: The SHA of the commit to comment on.
  • path: The file path in the repository where the comment should be added.
  • position: The position in the diff where the comment should be added.

Returns:

  • The created PullRequestComment object.
  • An error if any occurred during the API request.

func (*GithubClient) AddCommitToBranch

func (gc *GithubClient) AddCommitToBranch(ctx context.Context, owner, repo, branch, filePath, commitMessage string, fileContent []byte) error

AddCommitToBranch adds a commit to the specified branch.

func (*GithubClient) CreateBranch

func (gc *GithubClient) CreateBranch(ctx context.Context, owner, repo, newBranch, baseBranch string) error

CreateBranch creates a new branch from the specified base branch.

func (*GithubClient) CreatePullRequest

func (gc *GithubClient) CreatePullRequest(ctx context.Context, owner, repo, title, head, base, body string) (*github.PullRequest, error)

CreatePullRequest creates a new pull request.

func (*GithubClient) GetCommitCode

func (gc *GithubClient) GetCommitCode(context context.Context, owner, repo, commitSHA string, codeFilter CodeFilter) (map[string]string, error)

GetCommitCode gets the code from a commit.

func (*GithubClient) GetLatestCommitFromBranch

func (gc *GithubClient) GetLatestCommitFromBranch(ctx context.Context, owner, repo, branch string) (string, error)

GetLatestCommitFromBranch gets the latest commit SHA from a branch.

func (*GithubClient) GetPRCode

func (gc *GithubClient) GetPRCode(ctx context.Context, owner, repo string, prNumber int, opts *github.ListOptions, codeFilter CodeFilter) (map[string]string, error)

GetPRCode gets the code from a pull request.

func (*GithubClient) GetPRDiff

func (gc *GithubClient) GetPRDiff(ctx context.Context, owner, repo string, prNumber int) (string, error)

func (*GithubClient) GetPRPatch

func (gc *GithubClient) GetPRPatch(ctx context.Context, owner, repo string, prNumber int) (string, error)

func (*GithubClient) ListPullRequests

func (gc *GithubClient) ListPullRequests(ctx context.Context, owner, repo string, opts *github.PullRequestListOptions) ([]*github.PullRequest, error)

ListPullRequests lists all pull requests in a repository.

func (*GithubClient) MergePullRequest

func (gc *GithubClient) MergePullRequest(ctx context.Context, owner, repo string, prNumber int, commitMessage string) (*github.PullRequestMergeResult, error)

MergePullRequest merges a pull request.

type ModelType

type ModelType string

type OllamaClient

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

func NewOllamaClient

func NewOllamaClient(cfg openai.ClientConfig) *OllamaClient

func (*OllamaClient) CreateChatCompletion

func (c *OllamaClient) CreateChatCompletion(ctx context.Context, request openai.ChatCompletionRequest) (response openai.ChatCompletionResponse, err error)
curl http://localhost:11434/api/chat -d '{
	  "model": "llama3.2",
	  "messages": [
	    { "role": "user", "content": "why is the sky blue?" }
	  ]
	}'

type OpenAIClient

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

func NewCustomOpenAIClient

func NewCustomOpenAIClient(authToken, baseURL string, apiType APIType) *OpenAIClient

func NewOpenAIClient

func NewOpenAIClient(apiKey string) *OpenAIClient

NewOpenAIClient creates a new instance of the OpenAIClient.

func (*OpenAIClient) GenerateChatCompletion

func (oc *OpenAIClient) GenerateChatCompletion(ctx context.Context, messages []openai.ChatCompletionMessage, model ModelType) (string, error)

GenerateChatCompletion generates a chat completion based on the provided messages.

Parameters:

  • ctx: The context for the API request.
  • messages: The list of messages to use as input for the chat completion.

Returns:

  • The generated chat completion.
  • An error if any occurred during the API request.

Generated by gomarkdoc

# Packages

Code generated by counterfeiter.

# Functions

IsDoNotEditFile checks if the file has a DO NOT EDIT comment.
ModelToContextWindow returns the context window size for the given model.
No description provided by the author
NewGithubClient creates a new instance of the GithubClient.
No description provided by the author
NewOpenAIClient creates a new instance of the OpenAIClient.
Shuffle shuffles a slice of any type.

# Constants

No description provided by the author
GPT3_5Turbo0125 is the GPT-3.5-turbo-0125 model.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

CodeFilter is used to filter files based on a regex pattern.
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author