palmapi

package
v0.0.0-...-210767f Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package palmapi provides a client and utilities for interacting with the PaLM API (https://developers.generativeai.google/guide/palm_api_overview).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Citation

type Citation struct {
	Sources []Source `json:"citationSources,omitempty"`
}

See https://developers.generativeai.google/api/rest/generativelanguage/CitationMetadata

type Client

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

func NewClient

func NewClient(httpClient *http.Client, url string, getAPIKey func() (string, error)) *Client

func NewDefaultClient

func NewDefaultClient() *Client

NewDefaultClient returns a new default client for the PaLM API that reads an API key from the environment variable "PALM_API_KEY".

func (*Client) GenerateText

func (c *Client) GenerateText(prompt string) (*GenerateTextResponse, error)

GenerateText is a wrapper for the PaLM API "generateText" endpoint. See https://developers.generativeai.google/api/rest/generativelanguage/models/generateText.

func (*Client) Suggest

func (c *Client) Suggest(in *Input) ([]*Suggestion, error)

Suggest uses the PaLM API to generate suggestions for vulnerability reports based on the input. This function must be called from the root of the vulndb repo, as it accesses a specific file to read examples.

type Example

type Example struct {
	Input      `json:"Input"`
	Suggestion `json:"Suggestion"`
}

type Examples

type Examples []*Example

Examples represents a list of input/output pairs to be used as examples to follow by the Suggest function. Can be used to create few-shot prompts or fine-tune a model.

func (*Examples) ReadJSON

func (es *Examples) ReadJSON(r io.Reader) error

func (Examples) WriteFiles

func (es Examples) WriteFiles(folder string) error

WriteFiles writes the examples to the given folder in the following formats:

  • <folder>/data/examples.json: a JSON array of the examples (used directly by the Suggest function)
  • <folder>/data/examples.csv: a CSV-formatted list of each example, where the input and output are comma-separated JSON objects. Can be used as an input to a Makersuite data prompt.
  • <folder>/data/prompt.txt: the prompt that will be used by Suggest (with placeholder data for the final input)

type GenerateTextRequest

type GenerateTextRequest struct {
	Prompt          TextPrompt      `json:"prompt"`
	Temperature     float32         `json:"temperature,omitempty"`
	CandidateCount  int             `json:"candidateCount,omitempty"`
	TopK            int             `json:"topK,omitempty"`
	TopP            float32         `json:"topP,omitempty"`
	MaxOutputTokens int             `json:"maxOutputTokens,omitempty"`
	StopSequences   []string        `json:"stopSequences,omitempty"`
	SafetySettings  []SafetySetting `json:"safetySettings,omitempty"`
}

See https://developers.generativeai.google/api/rest/generativelanguage/models/generateText#request-body

type GenerateTextResponse

type GenerateTextResponse struct {
	Candidates []TextCompletion `json:"candidates"`
}

See https://developers.generativeai.google/api/rest/generativelanguage/GenerateTextResponse

type Input

type Input struct {
	// The path of the affected module to include in the summary.
	Module string
	// The original description (can be copied from a GHSA or CVE)
	// of the vulnerability.
	Description string
}

type SafetySetting

type SafetySetting struct {
	Category  string `json:"category,omitempty"`
	Threshold int    `json:"threshold,omitempty"`
}

See https://developers.generativeai.google/api/rest/generativelanguage/SafetySetting

type Source

type Source struct {
	StartIndex int    `json:"startIndex,omitempty"`
	EndIndex   int    `json:"endIndex,omitempty"`
	URI        string `json:"uri,omitempty"`
	License    string `json:"license,omitempty"`
}

See https://developers.generativeai.google/api/rest/generativelanguage/CitationMetadata#CitationSource

type Suggestion

type Suggestion struct {
	// A short summary of the vulnerability.
	Summary string
	// A re-written description of the vulnerability.
	Description string
}

type TextCompletion

type TextCompletion struct {
	Output string `json:"output"`
	// Field "safetyRatings" omitted.
	Citations Citation `json:"citationMetadata,omitempty"`
}

See https://developers.generativeai.google/api/rest/generativelanguage/GenerateTextResponse#TextCompletion

Directories

Path Synopsis
Command gen_examples generates and stores examples that can be used to create prompts / training inputs for the PaLM API.
Command gen_examples generates and stores examples that can be used to create prompts / training inputs for the PaLM API.

Jump to

Keyboard shortcuts

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