copilot

package module
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 21 Imported by: 8

README

copilot-go

copilot-go copilot provides the types and functions for authoring GitHub Copilot Extensions.

Use this package to build GitHub Copilot agents and skillsets.

Go Reference

Installing

copilot-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/colbylwilliams/copilot-go

will resolve and add the package to the current development module, along with its dependencies.

Alternatively the same can be achieved if you use import in a package:

import "github.com/colbylwilliams/copilot-go"

and run go get without parameters.

Finally, to use the top-of-trunk version of this repo, use the following command:

go get github.com/colbylwilliams/copilot-go@main

Usage

See the _examples directory for complete and runnable examples.

This simple example agent uses chi and go-github:

package main

import (
    "context"
    "net/http"

    "github.com/colbylwilliams/copilot-go"
    "github.com/go-chi/chi/v5"
    "github.com/go-chi/chi/v5/middleware"
    "github.com/google/go-github/v67/github"
)

func main() {
    cfg, _ := copilot.LoadConfig()
    v, _ := copilot.NewPayloadVerifier()

    a := &MyAgent{cfg: cfg}

    r := chi.NewRouter()
    r.Use(middleware.Logger)
    r.Use(middleware.RequestID)

    r.Post("/agent", copilot.AgentHandler(v, a))

    return http.ListenAndServe(":3333", r)
}

type MyAgent struct{ cfg *copilot.Config }

func (a *MyAgent) Execute(ctx context.Context, token string, req *copilot.Request, w http.ResponseWriter) error {
    rid := middleware.GetReqID(ctx)
    gh := github.NewClient(nil).WithAuthToken(token)

    me, _, _ := gh.Users.Get(ctx, "")

    sse.WriteStreamingHeaders(w)

    sse.WriteDelta(w, rid, fmt.Sprintf("Hello %s\n", me.GetName()))
    sse.WriteDelta(w, rid, "How are you today?\n")

    sse.WriteStop(w, rid)
}
Configuration

LoadConfig above loads .env file(s) with godotenv, then loads the required configuration information from environment variables. Here's an example .env file with the required variables:

GITHUB_APP_CLIENT_ID=Iv23abcdef1234567890
GITHUB_APP_PRIVATE_KEY_PATH=my-agent.2024-08-20.private-key.pem
GITHUB_APP_FQDN=https://my_unique_devtunnelid-3333.use2.devtunnels.ms

These values will come from your Copilot extension's GitHub App. See "Creating a GitHub App for your Copilot Extension" and "Configuring your GitHub App for your Copilot extension" for details.

See the Config and azure.Config types for a full set of available configuration variables.

Copilot's LLM

In the first example, the agent replies with a static message. We can easily enhance it to use Copilot's LLM to generate the response.

package main

import (
    "context"
    "net/http"

    "github.com/colbylwilliams/copilot-go"
    "github.com/go-chi/chi/v5"
    "github.com/go-chi/chi/v5/middleware"
    "github.com/google/go-github/v67/github"
)

func main() {
    cfg, _ := copilot.LoadConfig()
    v, _ := copilot.NewPayloadVerifier()

    a := &MyAgent{cfg: cfg}

    r := chi.NewRouter()
    r.Use(middleware.Logger)
    r.Use(middleware.RequestID)

    r.Post("/agent", copilot.AgentHandler(v, a))

    return http.ListenAndServe(":3333", r)
}

type MyAgent struct{ cfg *copilot.Config }

func (a *MyAgent) Execute(ctx context.Context, token string, req *copilot.Request, w http.ResponseWriter) error {

    const prompt = "You are a helpful AI assistant."

    msg := &copilot.Message{Role: copilot.ChatRoleSystem, Content: prompt}

    comp := &copilot.CompletionsRequest{
        Messages: []*copilot.Message{msg},
        Model:    copilot.CopilotModelGPT4o,
    }

    comp.Messages = append(comp.Messages, req.Messages...)

    stream, _ := copilot.ChatCompletionsStream(ctx, token, *comp, w)

    _, err = io.Copy(w, stream)

    return nil
}

Documentation

Overview

Package copilot provides the types and functions for authoring GitHub Copilot Extensions.

Use this package to build GitHub Copilot agents and skillsets.

Index

Constants

View Source
const (
	GitHubTokenHeader         = "X-Github-Token"
	PublicKeyIdentifierHeader = "Github-Public-Key-Identifier"
	PublicKeySignatureHeader  = "Github-Public-Key-Signature"
)
View Source
const (
	GitHubAppIDKey             string = "GITHUB_APP_ID"
	GitHubAppClientIDKey       string = "GITHUB_APP_CLIENT_ID"
	GitHubAppClientSecretKey   string = "GITHUB_APP_CLIENT_SECRET"
	GitHubAppPrivateKeyPathKey string = "GITHUB_APP_PRIVATE_KEY_PATH"
	GitHubAppWebhookSecretKey  string = "GITHUB_APP_WEBHOOK_SECRET"
	GitHubAppFQDNKey           string = "GITHUB_APP_FQDN"
	GitHubAppUserAgentKey      string = "GITHUB_APP_USER_AGENT"
	OpenAIChatModelKey         string = "OPENAI_CHAT_MODEL"
)
View Source
const (
	ChatFinishReasonStop         string = "stop"
	ChatFinishReasonToolCalls    string = "tool_calls"
	ChatFinishReasonFunctionCall string = "function_call"
)
View Source
const (
	OpenAIChatModelDefault string = "gpt-4o"
)

Variables

View Source
var (
	ClientConfirmationStateAccepted  = ClientConfirmationState{"accepted"}
	ClientConfirmationStateDismissed = ClientConfirmationState{"dismissed"}
)
View Source
var (
	ErrorTypeReference = ErrorType{"reference"}
	ErrorTypeFunction  = ErrorType{"function"}
	ErrorTypeAgent     = ErrorType{"agent"}
)
View Source
var (
	RepoItemRefTypeIssue = RepoItemRefType{"issue", "issues"}
	RepoItemRefTypePull  = RepoItemRefType{"pull", "pulls"}
)
View Source
var (
	ConfirmationTypeAction = ConfirmationType{"action"}
)

Functions

func AddGetHubToken added in v1.0.4

func AddGetHubToken(ctx context.Context, data string) context.Context

AddGetHubToken adds the SessionInfo object to the context.

func AddSessionInfo added in v1.0.4

func AddSessionInfo(ctx context.Context, data *SessionInfo) context.Context

AddSessionInfo adds the SessionInfo object to the context.

func AgentHandler

func AgentHandler(v PayloadVerifier, a Agent) http.HandlerFunc

func ChatCompletions added in v1.0.1

func ChatCompletions(ctx context.Context, token string, r CompletionsRequest, w io.Writer) (io.ReadCloser, error)

ChatCompletions sends a request to the the Copilot API to get completions.

func ChatCompletionsStream added in v1.0.1

func ChatCompletionsStream(ctx context.Context, token string, r CompletionsRequest, w io.Writer) (io.ReadCloser, error)

ChatCompletionsStream is a convenience function that sets the Stream field to true and calls ChatCompletions.

func GetGetHubToken added in v1.0.4

func GetGetHubToken(ctx context.Context) string

GetGetHubToken returns the SessionInfo object from the context.

Types

type Agent

type Agent interface {
	Execute(ctx context.Context, token string, req *Request, w http.ResponseWriter) error
}

type ChatChoice

type ChatChoice struct {
	Index        int64           `json:"index"`
	FinishReason string          `json:"finish_reason,omitempty"`
	Delta        ChatChoiceDelta `json:"delta"`
}

type ChatChoiceDelta

type ChatChoiceDelta struct {
	Content      string                       `json:"content"`
	Role         string                       `json:"role,omitempty"`
	Name         string                       `json:"name,omitempty"`
	FunctionCall *ChatChoiceDeltaFunctionCall `json:"function_call,omitempty"`
}

type ChatChoiceDeltaFunctionCall

type ChatChoiceDeltaFunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type ChatRole

type ChatRole string
const (
	ChatRoleUser      ChatRole = "user"
	ChatRoleAssistant ChatRole = "assistant"
	ChatRoleFunction  ChatRole = "function"
	ChatRoleTool      ChatRole = "tool"
	ChatRoleSystem    ChatRole = "system"
)

type ClientConfirmation

type ClientConfirmation struct {
	State        ClientConfirmationState `json:"state"`
	Confirmation any                     `json:"confirmation"`
}

ClientConfirmation represents a confirmation that the user has accepted or dismissed.

type ClientConfirmationState

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

func (ClientConfirmationState) MarshalJSON

func (c ClientConfirmationState) MarshalJSON() ([]byte, error)

func (*ClientConfirmationState) UnmarshalJSON

func (c *ClientConfirmationState) UnmarshalJSON(data []byte) error

type CompletionsRequest added in v1.0.1

type CompletionsRequest struct {
	Model    CopilotModel       `json:"model" default:"gpt-4o"`
	Messages []*Message         `json:"messages"`
	Tools    []*CompletionsTool `json:"tools,omitempty"`
	Stream   bool               `json:"stream"`
}

CompletionsRequest is a request to the Copilot API to get completions.

type CompletionsTool added in v1.0.1

type CompletionsTool struct {
	Type     string                 `json:"type" default:"function"`
	Function ToolFunctionDefinition `json:"function"`
}

CompletionsTool represents a tool to use for completions.

type Config

type Config struct {
	// Environment is the environment the app is running in (development, production, etc).
	// It is resolved from the ENVIRONMENT environment variable.
	Environment string
	// HTTPPort is the port the HTTP server will listen on.
	// It is resolved from the PORT environment variable.
	HTTPPort string
	// GitHubAppFQDN is the fully qualified domain name of the GitHub App.
	// It is resolved from the GITHUB_APP_FQDN environment variable.
	// If using devoutness or ngrok, this should be the public URL.
	GitHubAppFQDN string
	// GitHubAppID is the app ID of the GitHub App.
	// It is resolved from the GITHUB_APP_ID environment variable.
	// Note that this is not required for the GitHub App to function.
	GitHubAppID int64
	// GitHubAppClientID is the client ID of the GitHub App.
	// It is resolved from the GITHUB_APP_CLIENT_ID environment variable.
	GitHubAppClientID string
	// GitHubAppClientSecret is the client secret of the GitHub App.
	// It is resolved from the GITHUB_APP_CLIENT_SECRET environment variable.
	GitHubAppClientSecret string
	// GitHubAppPrivateKeyPath is the path to the private key of the GitHub App.
	// It is resolved from the GITHUB_APP_PRIVATE_KEY_PATH environment variable.
	// The file should be a PEM file.
	GitHubAppPrivateKeyPath string
	// GitHubAppPrivateKey is the private key of the GitHub App.
	// It is resolved from the pem file at GitHubAppPrivateKeyPath.
	GitHubAppPrivateKey []byte
	// GitHubAppWebhookSecret is the secret used to validate GitHub App webhooks.
	// It is resolved from the GITHUB_APP_WEBHOOK_SECRET environment variable.
	GitHubAppWebhookSecret string
	// GitHubAppUserAgent is the user agent to use when making requests to the GitHub API.
	// It is resolved from the GITHUB_APP_USER_AGENT environment variable.
	GitHubAppUserAgent string
	// ChatModel is the OpenAI chat model to use.
	// It is resolved from the OPENAI_CHAT_MODEL environment variable.
	// If not set, it defaults to "gpt-4o".
	ChatModel string
	// Azure is the configuration for Azure OpenAI.
	Azure *azure.Config
}

Config represents the configuration of the app.

func LoadConfig

func LoadConfig(env ...string) (*Config, error)

LoadConfig reads the environment variables (optionally loading them first from .env files using godotenv), and returns a new Config.

env is the .env file(s) to load

  • If none are provided, it will default to loading .env in the current path.
  • If multiple are provided, they will be loaded in order, with later files overriding earlier ones.
  • To skip loading .env files with godotenv, pass an empty string.

func (*Config) IsDevelopment

func (cfg *Config) IsDevelopment() bool

IsDevelopment reports whether the environment is development.

func (*Config) IsProduction

func (cfg *Config) IsProduction() bool

IsProduction reports whether the environment is production (or staging).

type Confirmation

type Confirmation struct {
	// Type is a string that specifies the confirmation's type.
	// Currently, action is the only supported value for type.
	Type ConfirmationType `json:"type" default:"action"`
	// Title is the title of the confirmation dialog shown to the user.
	Title string `json:"title"`
	// Message is the message of the confirmation dialog shown to the user.
	Message string `json:"message"`
	// Confirmation an optional field for the agent to include any data needed
	// to uniquely identify this confirmation and take action once the decision
	// is received from the client.
	Confirmation any `json:"confirmation"`
}

Confirmation represents a confirmation that the agent has sent to the user.

type ConfirmationType

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

func (ConfirmationType) MarshalJSON

func (c ConfirmationType) MarshalJSON() ([]byte, error)

func (*ConfirmationType) UnmarshalJSON

func (c *ConfirmationType) UnmarshalJSON(data []byte) error

type CopilotModel added in v1.0.1

type CopilotModel string

CopilotModel represents the model to use for completions.

const (
	CopilotModelGPT35      CopilotModel = "gpt-3.5-turbo"
	CopilotModelGPT4       CopilotModel = "gpt-4"
	CopilotModelGPT4o      CopilotModel = "gpt-4o"
	CopilotModelEmbeddings CopilotModel = "text-embedding-ada-002"
)

type Error

type Error struct {
	// Type is a string that specifies the error's type. type can have a value of
	// reference, function or agent.
	Type ErrorType `json:"type"`
	// Code is string controlled by the agent describing the nature of an error.
	Code string `json:"code"`
	// Message is string that specifies the error message shown to the user.
	Message string `json:"message"`
	// Identifier is string that serves as a unique identifier to link the error
	// with other resources such as references or function calls.
	Identifier string `json:"identifier"`
}

Error represents an error that occurred during the agent request.

func (*Error) Error

func (a *Error) Error() string

type ErrorType

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

ErrorType is a string that specifies the error's type. type can have a value of reference, function or agent.

func (ErrorType) MarshalJSON

func (a ErrorType) MarshalJSON() ([]byte, error)

func (*ErrorType) UnmarshalJSON

func (a *ErrorType) UnmarshalJSON(b []byte) error

type Issue

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

Issue represents a github issue

type Message

type Message struct {
	Role          ChatRole              `json:"role"`
	Content       string                `json:"content"`
	Name          string                `json:"name,omitempty"`
	References    []*Reference          `json:"copilot_references"`
	Confirmations []*ClientConfirmation `json:"copilot_confirmations"`
	FunctionCall  *ToolFunctionCall     `json:"function_call,omitempty"`
	ToolCalls     []*ToolCall           `json:"tool_calls,omitempty"`
	ToolCallID    string                `json:"tool_call_id,omitempty"`
}

Message is a message in the request.

func (*Message) IsSessionMessage added in v1.0.4

func (msg *Message) IsSessionMessage() bool

IsSessionMessage returns true if the message has the role of "system" and the name of "_session"

type PayloadVerifier

type PayloadVerifier interface {
	Verify(body []byte, sig string) (bool, error)
}

PayloadVerifier is for verifying a payload using ECDSA to ensure it's from GitHub.

func NewPayloadVerifier

func NewPayloadVerifier() (PayloadVerifier, error)

NewVerifier returns a new Verifier.

func NewPayloadVerifierWithKey

func NewPayloadVerifierWithKey(pubKey string) (PayloadVerifier, error)

NewPayloadVerifierWithKey returns a new Verifier with the given public key.

type PullRequest

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

PullRequest represents a github pull request

type Reference

type Reference struct {
	// Type is the type of the copilot references.
	Type ReferenceType `json:"type"`
	// ID is the unique identifier of the copilot references.
	ID string `json:"id"`
	// IsImplicit specifies if the reference was passed implicitly or explicitly.
	IsImplicit bool `json:"is_implicit"`
	// Metadata includes any metadata to display in the user's environment.
	// If any of the Metadata required fields are missing, the reference will
	// not be rendered in the UI.
	Metadata ReferenceMetadata `json:"metadata"`
	// Data that is specific to the copilot references.
	Data    ReferenceData   `json:"-"`
	RawData json.RawMessage `json:"data"`
}

Reference is a copilot_reference in chat messages

func (*Reference) UnmarshalJSON

func (r *Reference) UnmarshalJSON(data []byte) error

type ReferenceData

type ReferenceData interface{}

ReferenceData is the data that is specific to the copilot_reference type.

type ReferenceDataClientFile

type ReferenceDataClientFile struct {
	Content  string `json:"content"`
	Language string `json:"language"`
}

ReferenceDataClientFile contains information about a specific file on a client. Included on copilot references of type: "client.file"

"client.file" is sent by the vscode chat client (and likely visual studio).

type ReferenceDataClientSelection

type ReferenceDataClientSelection struct {
	Content string                               `json:"content"`
	End     ReferenceDataClientSelectionLocation `json:"end"`
	Start   ReferenceDataClientSelectionLocation `json:"start"`
}

ReferenceDataClientSelection contains information about a selection in a file. Included on copilot references of type: "client.selection"

"client.selection" is sent by the vscode chat client (and likely visual studio).

type ReferenceDataClientSelectionLocation

type ReferenceDataClientSelectionLocation struct {
	Col  int32 `json:"col"`
	Line int32 `json:"line"`
}

type ReferenceDataGitHubAgent

type ReferenceDataGitHubAgent struct {
	AvatarURL string `json:"avatarURL"`
	ID        int64  `json:"id"`
	Login     string `json:"login"`
	Type      string `json:"type" default:"github.agent"`
	URL       string `json:"url"`
}

ReferenceDataGitHubAgent contains information about a GitHub Copilot agent. Included on copilot references of type: "github.agent"

type ReferenceDataGitHubCurrentUrl

type ReferenceDataGitHubCurrentUrl struct {
	URL   string `json:"url"`
	Owner string `json:"owner"`
	Repo  string `json:"repo"`
	Path  string `json:"path,omitempty"`
	Hash  string `json:"hash,omitempty"`
}

ReferenceDataGitHubCurrentUrl contains information about the users current URL. Included on copilot references of type: "github.current-url"

Note: this is a special copilot_reference that only seems to be present in a message with role: "user" and name: "_session"

Only the URL field is sent by the client, the rest of the fields are extracted during unmarshaling.

"github.current-url" is ONLY sent by the github.com (web) chat client.

func (*ReferenceDataGitHubCurrentUrl) UnmarshalJSON

func (u *ReferenceDataGitHubCurrentUrl) UnmarshalJSON(data []byte) error

type ReferenceDataGitHubFile

type ReferenceDataGitHubFile struct {
	CommitOID    string `json:"commitOID"`
	LanguageID   int64  `json:"languageID"`
	LanguageName string `json:"languageName"`
	Path         string `json:"path"`
	Ref          string `json:"ref"`
	RepoID       int64  `json:"repoID"`
	RepoName     string `json:"repoName"`
	RepoOwner    string `json:"repoOwner"`
	Type         string `json:"type" default:"file"`
	URL          string `json:"url"`
}

ReferenceDataGitHubFile contains information about a file in a github repository. Included on copilot references of type: "github.file"

"github.file" is ONLY sent by github.com (web) chat client.

type ReferenceDataGitHubRedacted

type ReferenceDataGitHubRedacted struct {
	// Type is the type of the copilot references that was redacted.
	Type ReferenceType `json:"type"`
}

ReferenceDataGitHubRedacted contains information about a redacted copilot_reference. Included on copilot references of type: "github.redacted"

type ReferenceDataGitHubRepository

type ReferenceDataGitHubRepository struct {
	CommitOID   string                                   `json:"commitOID"`
	Description string                                   `json:"description"`
	ID          int64                                    `json:"id"`
	Languages   []*ReferenceDataGitHubRepositoryLanguage `json:"languages"`
	Name        string                                   `json:"name"`
	OwnerLogin  string                                   `json:"ownerLogin"`
	OwnerType   string                                   `json:"ownerType"`
	ReadmePath  string                                   `json:"readmePath"`
	Ref         string                                   `json:"ref"`
	RefInfo     ReferenceDataGitHubRepositoryRefInfo     `json:"refInfo"`
	Type        string                                   `json:"type" default:"repository"`
	Visibility  string                                   `json:"visibility"`
}

ReferenceDataGitHubRepository contains information about a github repository. Included on copilot references of type: "github.repository"

Note: fields set by different clients vary, and are not guaranteed to be present. ID, OwnerLogin, Name, and Type do seem to be present across clients.

"github.repository" is sent by the vscode and github.com (web) chat clients.

type ReferenceDataGitHubRepositoryLanguage

type ReferenceDataGitHubRepositoryLanguage struct {
	Name    string  `json:"name"`
	Percent float64 `json:"percent"`
}

type ReferenceDataGitHubRepositoryRefInfo

type ReferenceDataGitHubRepositoryRefInfo struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type ReferenceDataGitHubSnippet

type ReferenceDataGitHubSnippet struct {
	CommitOID    string                          `json:"commitOID"`
	LanguageID   int64                           `json:"languageID"`
	LanguageName string                          `json:"languageName"`
	Path         string                          `json:"path"`
	Range        ReferenceDataGitHubSnippetRange `json:"range"`
	Ref          string                          `json:"ref"`
	RepoID       int64                           `json:"repoID"`
	RepoName     string                          `json:"repoName"`
	RepoOwner    string                          `json:"repoOwner"`
	Type         string                          `json:"type" default:"snippet"`
	URL          string                          `json:"url"`
}

ReferenceDataGitHubSnippet contains information about a code snippet from a file in a github repository. Included on copilot references of type: "github.snippet"

"github.snippet" is ONLY sent by github.com (web) chat client.

type ReferenceDataGitHubSnippetRange

type ReferenceDataGitHubSnippetRange struct {
	End   int32 `json:"end"`
	Start int32 `json:"start"`
}

type ReferenceDataOther added in v1.0.1

type ReferenceDataOther struct {
	Type string `json:"type"`
}

ReferenceDataOther contains information about a copilot_reference that is not included in the well-known types.

type ReferenceMetadata

type ReferenceMetadata struct {
	DisplayName string `json:"display_name"`
	DisplayIcon string `json:"display_icon"`
	DisplayURL  string `json:"display_url"`
}

ReferenceMetadata contains metadata about a copilot_reference to display in the user's environment. If any of the required fields are missing, the reference will not be rendered in the UI.

type ReferenceType

type ReferenceType string

ReferenceType is the type of copilot_reference.

const (
	// ReferenceTypeGitHubRedacted is another reference that has been redacted.
	ReferenceTypeGitHubRedacted ReferenceType = "github.redacted"
	// ReferenceTypeGitHubAgent is a GitHub Copilot agent.
	ReferenceTypeGitHubAgent ReferenceType = "github.agent"
	// ReferenceTypeGitHubCurrentUrl is the current URL of the user.
	ReferenceTypeGitHubCurrentUrl ReferenceType = "github.current-url"
	// ReferenceTypeGitHubFile is a file in a GitHub repository.
	ReferenceTypeGitHubFile ReferenceType = "github.file"
	// ReferenceTypeGitHubRepository is a GitHub repository.
	ReferenceTypeGitHubRepository ReferenceType = "github.repository"
	// ReferenceTypeGitHubSnippet is a code snippet from a file in a GitHub repository.
	ReferenceTypeGitHubSnippet ReferenceType = "github.snippet"
	// ReferenceTypeClientFile is a file from a client like vscode.
	ReferenceTypeClientFile ReferenceType = "client.file"
	// ReferenceTypeClientSelection is a selection in a file from a client like vscode.
	ReferenceTypeClientSelection ReferenceType = "client.selection"
)

type RepoItemRefType

type RepoItemRefType struct {
	Singular string
	Plural   string
}

func (RepoItemRefType) MarshalJSON

func (t RepoItemRefType) MarshalJSON() ([]byte, error)

func (*RepoItemRefType) UnmarshalJSON

func (t *RepoItemRefType) UnmarshalJSON(data []byte) error

type Request

type Request struct {
	ThreadID         string     `json:"copilot_thread_id"`
	Messages         []*Message `json:"messages"`
	Stop             []string   `json:"stop"`
	TopP             float32    `json:"top_p"`
	Temperature      float32    `json:"temperature"`
	MaxTokens        int32      `json:"max_tokens"`
	PresencePenalty  float32    `json:"presence_penalty"`
	FrequencyPenalty float32    `json:"frequency_penalty"`
	Skills           []string   `json:"copilot_skills"`
	Agent            string     `json:"agent"`
}

Request is the request to the agent.

func (*Request) GetSessionInfo added in v1.0.4

func (req *Request) GetSessionInfo() (*SessionInfo, error)

GetSessionInfo returns the context of the chat session, including the current url, the relevant repository, agent details, and the associated issue or pull request if the current url is a valid issue or pull request url

func (*Request) GetSessionMessage added in v1.0.4

func (req *Request) GetSessionMessage() *Message

GetSessionMessage returns the message with the role of "system" and the name of "_session" which is the message that the github.com chat interface sends to communicate the current url and other context of the chat session

type Response

type Response struct {
	ID                string        `json:"id,omitempty"`
	Created           int64         `json:"created,omitempty"`
	Object            string        `json:"object,omitempty" default:"chat.completion.chunk"`
	Model             string        `json:"model,omitempty"`
	SystemFingerprint string        `json:"system_fingerprint,omitempty"`
	Choices           []ChatChoice  `json:"choices"`
	References        []*Reference  `json:"copilot_references,omitempty"`
	Confirmation      *Confirmation `json:"copilot_confirmation,omitempty"`
	Errors            []*Error      `json:"copilot_errors,omitempty"`
}

Response is the response from the agent.

type SessionInfo added in v1.0.4

type SessionInfo struct {
	URL         *ReferenceDataGitHubCurrentUrl `json:"url,omitempty"`
	Issue       *Issue                         `json:"issue,omitempty"`
	PullRequest *PullRequest                   `json:"pull_request,omitempty"`
	Repo        *ReferenceDataGitHubRepository `json:"repo,omitempty"`
	Agent       *ReferenceDataGitHubAgent      `json:"agent,omitempty"`
}

SessionInfo represents the context of the chat session based on the copilot references in the chat messages

func GetSessionInfo added in v1.0.4

func GetSessionInfo(ctx context.Context) *SessionInfo

GetSessionInfo returns the SessionInfo object from the context.

type ToolCall

type ToolCall struct {
	ID       string            `json:"id"`
	Type     string            `json:"type" default:"function"`
	Function *ToolFunctionCall `json:"function"`
}

type ToolFunctionCall added in v1.0.1

type ToolFunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type ToolFunctionDefinition added in v1.0.1

type ToolFunctionDefinition struct {
	Name        string                `json:"name"`
	Description string                `json:"description,omitempty"`
	Parameters  jsonschema.Definition `json:"parameters"`
}

Directories

Path Synopsis
_examples
azure_openai Module
Package azure provides helpful types and functions for use with Azure OpenAI.
Package azure provides helpful types and functions for use with Azure OpenAI.
github module
Package jsonschema provides a simple way to describe JSON Schemas.
Package jsonschema provides a simple way to describe JSON Schemas.
Package sse provides utilities for Server-Sent Events (SSE) in the context of the GitHub Copilot Extensions APIs.
Package sse provides utilities for Server-Sent Events (SSE) in the context of the GitHub Copilot Extensions APIs.

Jump to

Keyboard shortcuts

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