copilot

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BASE_PROMPT = fmt.Sprintf(`
When asked for your name, you must respond with "GitHub Copilot".
Follow the user's requirements carefully & to the letter.
Follow Microsoft content policies.
Avoid content that violates copyrights.
If you are asked to generate content that is harmful, hateful, racist, sexist, lewd, violent, or completely irrelevant to software engineering, only respond with "Sorry, I can't assist with that."
Keep your answers short and impersonal.
The user works in an IDE called Neovim which has a concept for editors with open files, integrated unit test support, an output pane that shows the output of running the code as well as an integrated terminal.
The user is working on a %s machine. Please respond with system specific commands if applicable.
`, utils.SetCurrentOSName())
View Source
var COPILOT_EXPLAIN = `
You are a programming instructor focused on clear, practical explanations.
When explaining code:
- Balance high-level concepts with implementation details
- Highlight key programming principles and patterns
- Address any code diagnostics or warnings
` + BASE_PROMPT
View Source
var COPILOT_GENERATE = COPILOT_INSTRUCTIONS + `
Your task is to modify the provided code according to the user's request. Follow these instructions precisely:

1. Split your response into minimal, focused code changes to produce the shortest possible diffs.

2. IMPORTANT: Every code block MUST have a header with this exact format:
   [file:<file_name>](<file_path>) line:<start_line>-<end_line>
   The line numbers are REQUIRED - never omit them.

3. Return ONLY the modified code blocks - no explanations or comments.

4. Each code block should contain:
   - Only the specific lines that need to change
   - Exact indentation matching the source
   - Complete code that can directly replace the original

5. When fixing code, check and address any diagnostics issues.

6. If multiple separate changes are needed, split them into individual blocks with appropriate headers.

7. If response would be too long:
   - Never cut off in the middle of a code block
   - Complete the current code block
   - End with "**` + "`[Response truncated] Please ask for the remaining changes.`" + `**"
   - Next response should continue with the next code block

Remember: Your response should ONLY contain file headers with line numbers and code blocks for direct replacement.
`
View Source
var COPILOT_INSTRUCTIONS = `
You are a code-focused AI programming assistant that specializes in practical software engineering solutions.
` + BASE_PROMPT
View Source
var COPILOT_REVIEW = COPILOT_INSTRUCTIONS + `
Review the code for readability and maintainability issues. Report problems in this format:
line=<line_number>: <issue_description>
line=<start_line>-<end_line>: <issue_description>

Check for:
- Unclear or non-conventional naming
- Comment quality (missing or unnecessary)
- Complex expressions needing simplification
- Deep nesting
- Inconsistent style
- Code duplication

Multiple issues on one line should be separated by semicolons.
End with: "**` + "`To clear buffer highlights, please ask a different question.`" + `**"

If no issues found, confirm the code is well-written.
`
View Source
var ErrGithubTokenNotSet = errors.New("no GitHub token found, please use `:Copilot auth` to set it up from copilot.lua or `:Copilot setup` for copilot.vim")

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	Default     bool   `json:"default"`
	Description string `json:"description"`
}

type Choice

type Choice struct {
	ContentFilterResults ContentFilterResults `json:"content_filter_results"`
	FinishReason         string               `json:"finish_reason"`
	Index                int64                `json:"index"`
	Message              Message              `json:"message"`
}

type CompletionResponse

type CompletionResponse struct {
	Choices             []Choice             `json:"choices"`
	Created             int64                `json:"created"`
	ID                  string               `json:"id"`
	Model               string               `json:"model"`
	PromptFilterResults []PromptFilterResult `json:"prompt_filter_results"`
	SystemFingerprint   string               `json:"system_fingerprint"`
	Usage               Usage                `json:"usage"`
}

type CompletionTokensDetails

type CompletionTokensDetails struct {
	ReasoningTokens int64 `json:"reasoning_tokens"`
}

type ContentFilterResults

type ContentFilterResults struct {
	Hate     Hate `json:"hate"`
	SelfHarm Hate `json:"self_harm"`
	Sexual   Hate `json:"sexual"`
	Violence Hate `json:"violence"`
}

type Copilot

type Copilot interface {
	FetchModels(ctx context.Context) (map[string]*Model, error)
	FetchAgents(ctx context.Context) (map[string]*Agent, error)

	Ask(ctx context.Context, prompt string, opts any) (string, error)
}

func NewCopilot

func NewCopilot() Copilot

type GithubEndpoint

type GithubEndpoint struct {
	API           string `json:"api"`
	OriginTracker string `json:"origin-tracker"`
	Proxy         string `json:"proxy"`
	Telemetry     string `json:"telemetry"`
}

type GithubToken

type GithubToken struct {
	AnnotationsEnabled           bool           `json:"annotations_enabled"`
	ChatEnabled                  bool           `json:"chat_enabled"`
	ChatJetbrainsEnabled         bool           `json:"chat_jetbrains_enabled"`
	CodeQuoteEnabled             bool           `json:"code_quote_enabled"`
	CodeReviewEnabled            bool           `json:"code_review_enabled"`
	Codesearch                   bool           `json:"codesearch"`
	CopilotignoreEnabled         bool           `json:"copilotignore_enabled"`
	Endpoints                    GithubEndpoint `json:"endpoints"`
	ExpiresAt                    int            `json:"expires_at"`
	Individual                   bool           `json:"individual"`
	LimitedUserQuotas            any            `json:"limited_user_quotas"`
	LimitedUserResetDate         any            `json:"limited_user_reset_date"`
	NesEnabled                   bool           `json:"nes_enabled"`
	Prompt8K                     bool           `json:"prompt_8k"`
	PublicSuggestions            string         `json:"public_suggestions"`
	RefreshIn                    int            `json:"refresh_in"`
	Sku                          string         `json:"sku"`
	SnippyLoadTestEnabled        bool           `json:"snippy_load_test_enabled"`
	Telemetry                    string         `json:"telemetry"`
	Token                        string         `json:"token"`
	TrackingID                   string         `json:"tracking_id"`
	TriggerCompletionAfterAccept bool           `json:"trigger_completion_after_accept"`
	VscElectronFetcherV2         bool           `json:"vsc_electron_fetcher_v2"`
	Xcode                        bool           `json:"xcode"`
	XcodeChat                    bool           `json:"xcode_chat"`
}

type Hate

type Hate struct {
	Filtered bool   `json:"filtered"`
	Severity string `json:"severity"`
}

type Message

type Message struct {
	Content string `json:"content"`
	Role    string `json:"role"`
}

type Model

type Model struct {
	Capabilities       ModelCapabilities `json:"capabilities"`
	ID                 string            `json:"id"`
	ModelPickerEnabled bool              `json:"model_picker_enabled"`
	Name               string            `json:"name"`
	Object             string            `json:"object"`
	Preview            bool              `json:"preview"`
	Vendor             string            `json:"vendor"`
	Version            string            `json:"version"`
}

type ModelCapabilities

type ModelCapabilities struct {
	Family   string               `json:"family"`
	Limits   ModelCapabilityLimit `json:"limits"`
	Object   string               `json:"object"`
	Supports struct {
		Streaming bool `json:"streaming"`
		ToolCalls bool `json:"tool_calls"`
	} `json:"supports"`
	Tokenizer string `json:"tokenizer"`
	Type      string `json:"type"`
}

type ModelCapabilityLimit

type ModelCapabilityLimit struct {
	MaxContextWindowTokens int `json:"max_context_window_tokens"`
	MaxOutputTokens        int `json:"max_output_tokens"`
	MaxPromptTokens        int `json:"max_prompt_tokens"`
}

type PromptFilterResult

type PromptFilterResult struct {
	ContentFilterResults ContentFilterResults `json:"content_filter_results"`
	PromptIndex          int64                `json:"prompt_index"`
}

type PromptMessage

type PromptMessage struct {
	Content string `json:"content"`
	Role    string `json:"role"`
}

type PromptTokensDetails

type PromptTokensDetails struct {
	CachedTokens int64 `json:"cached_tokens"`
}

type Usage

type Usage struct {
	CompletionTokens        int64                   `json:"completion_tokens"`
	CompletionTokensDetails CompletionTokensDetails `json:"completion_tokens_details"`
	PromptTokens            int64                   `json:"prompt_tokens"`
	PromptTokensDetails     PromptTokensDetails     `json:"prompt_tokens_details"`
	TotalTokens             int64                   `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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