llm

package
v1.14.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SHORT  explanationLength = "SHORT"
	MEDIUM explanationLength = "MEDIUM"
	LONG   explanationLength = "LONG"
)

Variables

This section is empty.

Functions

func WithEndpoint

func WithEndpoint(endpoint *url.URL) func(*DeepcodeLLMBinding)

func WithHTTPClient

func WithHTTPClient(httpClientFunc func() http.HTTPClient) func(*DeepcodeLLMBinding)

func WithInstrumentor

func WithInstrumentor(instrumentor observability.Instrumentor) func(*DeepcodeLLMBinding)

func WithLogger

func WithLogger(logger *zerolog.Logger) func(*DeepcodeLLMBinding)

func WithOutputFormat

func WithOutputFormat(outputFormat OutputFormat) func(*DeepcodeLLMBinding)

Types

type AIRequest

type AIRequest struct {
	Id    string `json:"id"`
	Input string `json:"inputs"`
}

type DeepCodeLLMBinding

type DeepCodeLLMBinding interface {
	SnykLLMBindings
	ExplainWithOptions(options ExplainOptions) (string, error)
}

type DeepcodeLLMBinding

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

DeepcodeLLMBinding is an LLM binding for the Snyk Code LLM. Currently, it only supports explain.

func NewDeepcodeLLMBinding

func NewDeepcodeLLMBinding(opts ...Option) *DeepcodeLLMBinding

func (*DeepcodeLLMBinding) Explain

func (d *DeepcodeLLMBinding) Explain(input string, format OutputFormat, output chan<- string) error

func (*DeepcodeLLMBinding) ExplainWithOptions

func (d *DeepcodeLLMBinding) ExplainWithOptions(options ExplainOptions) (string, error)

func (*DeepcodeLLMBinding) PublishIssues

func (d *DeepcodeLLMBinding) PublishIssues(issues []map[string]string) error

type ExplainOptions

type ExplainOptions struct {
	// Derivation = Code Flow
	// const derivationLineNumbers: Set<number> = new Set<number>();
	//          for (const markerLocation of suggestion.markers!) {
	//            for (const markerPos of markerLocation.pos) {
	//              const lines = markerPos.rows;
	//              for (const line of lines) {
	//                derivationLineNumbers.add(line + 1);
	//              }
	//            }
	//            markerLocation.pos;
	//          }
	//          console.log('Derivation lines: ', ...derivationLineNumbers);
	//
	//          const derivationLines: string[] = [];
	//          const fileLines: string[] = fileContent.split('\n');
	//          for (const derivationLineNumber of derivationLineNumbers) {
	//            derivationLines.push(fileLines.at(derivationLineNumber - 1)!);
	//          }
	//          let Derivation = derivationLines.join(',');
	//          Derivation = Derivation.replace(/\t/g, '  ');
	//          console.log('Derivation: ', Derivation);
	Derivation string `json:"derivation"`

	// vulnerability name from Snyk Code (rule)
	RuleKey string `json:"rule_key"`

	// Snyk Code message for the vulnerability
	RuleMessage string `json:"rule_message"`

	// fix difference
	Diff string `json:"diff"`
}

type Option

type Option func(*DeepcodeLLMBinding)

type OutputFormat

type OutputFormat string
const HTML OutputFormat = "html"
const JSON OutputFormat = "json"
const MarkDown OutputFormat = "md"

type SnykLLMBindings

type SnykLLMBindings interface {
	// PublishIssues sends issues to an LLM for further processing.
	// the map in the slice of issues map is a json representation of json key : value
	// In case of errors, they are returned
	PublishIssues(issues []map[string]string) error

	// Explain forwards an input and desired output format to an LLM to
	// receive an explanation. The implementation should alter the LLM
	// prompt to honor the output format, but is not required to enforce
	// the format. The results should be streamed into the given channel
	//
	// Parameters:
	// input - the thing to be explained as a string
	// format - the requested outputFormat
	// output - a channel that can be used to stream the results
	Explain(input AIRequest, format OutputFormat, output chan<- string) error
}

Jump to

Keyboard shortcuts

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