Documentation
¶
Index ¶
- Constants
- func WithHTTPClient(httpClientFunc func() http.HTTPClient) func(*DeepCodeLLMBindingImpl)
- func WithInstrumentor(instrumentor observability.Instrumentor) func(*DeepCodeLLMBindingImpl)
- func WithLogger(logger *zerolog.Logger) func(*DeepCodeLLMBindingImpl)
- func WithOutputFormat(outputFormat OutputFormat) func(*DeepCodeLLMBindingImpl)
- type AIRequest
- type AutofixEventDetails
- type AutofixFeedbackOptions
- type AutofixIdeExtensionDetails
- type AutofixOptions
- type AutofixRequest
- type AutofixRequestKey
- type AutofixResponse
- type AutofixStatus
- type AutofixUnifiedDiffSuggestion
- type AutofixUserEvent
- type CodeRequestContext
- type CodeRequestContextOrg
- type DeepCodeLLMBinding
- type DeepCodeLLMBindingImpl
- func (d *DeepCodeLLMBindingImpl) Explain(ctx context.Context, input AIRequest, _ OutputFormat, output chan<- string) error
- func (d *DeepCodeLLMBindingImpl) ExplainWithOptions(ctx context.Context, options ExplainOptions) (ExplainResult, error)
- func (d *DeepCodeLLMBindingImpl) GetAutofixDiffs(ctx context.Context, _ string, options AutofixOptions) (unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, status AutofixStatus, ...)
- func (d *DeepCodeLLMBindingImpl) PublishIssues(_ context.Context, _ []map[string]string) error
- func (d *DeepCodeLLMBindingImpl) SubmitAutofixFeedback(ctx context.Context, fixId string, options AutofixFeedbackOptions) error
- type ExplainOptions
- type ExplainResult
- type Explanations
- type Option
- type OutputFormat
- type SnykLLMBindings
Constants ¶
View Source
const ( SHORT explanationLength = "SHORT" MEDIUM explanationLength = "MEDIUM" LONG explanationLength = "LONG" )
Variables ¶
This section is empty.
Functions ¶
func WithHTTPClient ¶
func WithHTTPClient(httpClientFunc func() http.HTTPClient) func(*DeepCodeLLMBindingImpl)
func WithInstrumentor ¶
func WithInstrumentor(instrumentor observability.Instrumentor) func(*DeepCodeLLMBindingImpl)
func WithLogger ¶
func WithLogger(logger *zerolog.Logger) func(*DeepCodeLLMBindingImpl)
func WithOutputFormat ¶
func WithOutputFormat(outputFormat OutputFormat) func(*DeepCodeLLMBindingImpl)
Types ¶
type AutofixEventDetails ¶ added in v1.21.4
type AutofixEventDetails struct {
FixId string `json:"fixId"`
}
type AutofixFeedbackOptions ¶ added in v1.21.4
type AutofixFeedbackOptions struct {
FixID string
Result string
Host string
CodeRequestContext CodeRequestContext
IdeExtensionDetails AutofixIdeExtensionDetails
}
type AutofixIdeExtensionDetails ¶ added in v1.21.4
type AutofixOptions ¶ added in v1.21.4
type AutofixOptions struct {
RuleID string
BundleHash string
ShardKey string
BaseDir string
FilePath string
LineNum int
Host string
CodeRequestContext CodeRequestContext
IdeExtensionDetails AutofixIdeExtensionDetails
}
type AutofixRequest ¶ added in v1.21.4
type AutofixRequest struct {
Key AutofixRequestKey `json:"key"`
AnalysisContext CodeRequestContext `json:"analysisContext"`
IdeExtensionDetails AutofixIdeExtensionDetails `json:"ideExtensionDetails"`
}
type AutofixRequestKey ¶ added in v1.21.4
type AutofixRequestKey struct {
Type string `json:"type"`
Hash string `json:"hash"`
Shard string `json:"shard"`
FilePath string `json:"filePath"`
RuleId string `json:"ruleId"`
// 1-based to comply with Sarif and Code API, see
// https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html#_Ref493492556
LineNum int `json:"lineNum"`
}
type AutofixResponse ¶ added in v1.21.4
type AutofixResponse struct {
Status string `json:"status"`
AutofixSuggestions []autofixResponseSingleFix `json:"fixes"`
}
AutofixResponse is the json-based structure to which we can translate the results of the HTTP request to Autofix upstream.
type AutofixStatus ¶ added in v1.21.4
type AutofixStatus struct {
Message string
}
type AutofixUnifiedDiffSuggestion ¶ added in v1.21.4
type AutofixUnifiedDiffSuggestion struct {
FixId string `json:"fixId"`
UnifiedDiffsPerFile map[string]string `json:"unifiedDiffsPerFile"`
FullTextPerFile map[string]string `json:"fullTextPerFile"`
Explanation string `json:"explanation"`
}
AutofixUnifiedDiffSuggestion represents the diff between the original and the fixed source code.
type AutofixUserEvent ¶ added in v1.21.4
type AutofixUserEvent struct {
AnalysisContext CodeRequestContext `json:"analysisContext"`
Channel string `json:"channel"`
EventType string `json:"eventType"`
EventDetails AutofixEventDetails `json:"eventDetails"`
IdeExtensionDetails AutofixIdeExtensionDetails `json:"ideExtensionDetails"`
}
type CodeRequestContext ¶ added in v1.21.4
type CodeRequestContext struct {
Initiator string `json:"initiator"`
Flow string `json:"flow,omitempty"`
Org CodeRequestContextOrg `json:"org,omitempty"`
}
type CodeRequestContextOrg ¶ added in v1.21.4
type DeepCodeLLMBinding ¶
type DeepCodeLLMBinding interface {
SnykLLMBindings
ExplainWithOptions(ctx context.Context, options ExplainOptions) (ExplainResult, error)
GetAutofixDiffs(ctx context.Context, baseDir string, options AutofixOptions) (unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, status AutofixStatus, err error)
SubmitAutofixFeedback(ctx context.Context, requestId string, options AutofixFeedbackOptions) error
}
type DeepCodeLLMBindingImpl ¶ added in v1.14.1
type DeepCodeLLMBindingImpl struct {
// contains filtered or unexported fields
}
DeepCodeLLMBindingImpl is an LLM binding for the Snyk Code LLM.
func NewDeepcodeLLMBinding ¶
func NewDeepcodeLLMBinding(opts ...Option) *DeepCodeLLMBindingImpl
func (*DeepCodeLLMBindingImpl) Explain ¶ added in v1.14.1
func (d *DeepCodeLLMBindingImpl) Explain(ctx context.Context, input AIRequest, _ OutputFormat, output chan<- string) error
func (*DeepCodeLLMBindingImpl) ExplainWithOptions ¶ added in v1.14.1
func (d *DeepCodeLLMBindingImpl) ExplainWithOptions(ctx context.Context, options ExplainOptions) (ExplainResult, error)
func (*DeepCodeLLMBindingImpl) GetAutofixDiffs ¶ added in v1.21.4
func (d *DeepCodeLLMBindingImpl) GetAutofixDiffs(ctx context.Context, _ string, options AutofixOptions) (unifiedDiffSuggestions []AutofixUnifiedDiffSuggestion, status AutofixStatus, err error)
func (*DeepCodeLLMBindingImpl) PublishIssues ¶ added in v1.14.1
func (*DeepCodeLLMBindingImpl) SubmitAutofixFeedback ¶ added in v1.21.4
func (d *DeepCodeLLMBindingImpl) SubmitAutofixFeedback(ctx context.Context, fixId string, options AutofixFeedbackOptions) 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
Diffs []string `json:"diffs"`
// Endpoint to call
Endpoint *url.URL `json:"endpoint"`
}
type ExplainResult ¶ added in v1.16.0
type ExplainResult []string
type Explanations ¶ added in v1.16.0
type Option ¶
type Option func(*DeepCodeLLMBindingImpl)
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(ctx context.Context, 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:
// ctx - request context
// 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(ctx context.Context, input AIRequest, format OutputFormat, output chan<- string) error
}
Click to show internal directories.
Click to hide internal directories.