Skip to content

Latest commit

 

History

History
310 lines (226 loc) · 6.28 KB

File metadata and controls

310 lines (226 loc) · 6.28 KB

Quick Reference - Copilot SDK Setup

Quick commands and references for setting up and using the GitHub Copilot SDK.

Prerequisites Checklist

# Check if prerequisites are installed
gh --version              # GitHub CLI
copilot --version         # Copilot CLI
node -v                   # Node.js (optional)
python3 --version         # Python (optional)
go version                # Go (optional)
dotnet --version          # .NET (optional)

One-Line Installations

GitHub CLI

# macOS
brew install gh

# Linux (Debian/Ubuntu)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
sudo apt update && sudo apt install gh

# Windows (PowerShell)
winget install --id GitHub.cli

Copilot CLI

gh extension install github/gh-copilot

Runtime Environments

# Node.js - visit https://nodejs.org/
# macOS: brew install node

# Python - visit https://python.org/
# macOS: brew install python

# Go - visit https://go.dev/
# macOS: brew install go

# .NET - visit https://dotnet.microsoft.com/
# macOS: brew install --cask dotnet-sdk

Automated Setup

# Run automated setup (Linux/macOS)
bash scripts/setup-dev-env.sh

# Run automated setup (Windows PowerShell)
.\scripts\setup-dev-env.ps1

# Validate your environment
bash scripts/validate-env.sh

Quick Start Commands

TypeScript Project

# Create from template
cp -r templates/typescript-quickstart my-app
cd my-app

# Setup
npm install
cp ../../templates/.env.example .env

# Run
npm start

Python Project

# Create from template
cp -r templates/python-quickstart my-app
cd my-app

# Setup
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp ../../templates/.env.example .env

# Run
python src/main.py

Go Project

mkdir my-app && cd my-app
go mod init my-app
go get github.com/github/copilot-sdk/go

.NET Project

dotnet new console -n MyApp
cd MyApp
dotnet add package GitHub.Copilot.SDK
dotnet run

SDK Installation

# Node.js/TypeScript
npm install @github/copilot-sdk tsx

# Python
pip install github-copilot-sdk

# Python with uv (faster)
uv pip install github-copilot-sdk

# Go
go get github.com/github/copilot-sdk/go

# .NET
dotnet add package GitHub.Copilot.SDK

Authentication

# Login to GitHub
gh auth login

# Refresh Copilot token
gh auth refresh -s copilot

# Check auth status
gh auth status

Environment Variables

Create .env file:

COPILOT_MODEL=gpt-4.1
COPILOT_STREAMING=true
LOG_LEVEL=info

Testing Your Setup

CLI Test

copilot "what is 2+2?"

TypeScript Test

import { CopilotClient } from "@github/copilot-sdk";

const client = new CopilotClient();
const session = await client.createSession({ model: "gpt-4.1" });
const response = await session.sendAndWait({ prompt: "Hello!" });
if (response?.data.content) {
    console.log(response.data.content);
}
await client.stop();
npx tsx test.ts

Python Test

import asyncio
from copilot import CopilotClient

async def main():
    client = CopilotClient()
    await client.start()
    session = await client.create_session({"model": "gpt-4.1"})
    response = await session.send_and_wait({"prompt": "Hello!"})
    print(response.data.content)
    await client.stop()

asyncio.run(main())
python test.py

Common Issues

copilot: command not found

gh extension install github/gh-copilot
# Add to PATH if needed
export PATH="$PATH:$HOME/.local/bin"

Authentication Errors

gh auth login
gh auth refresh -s copilot

Port Already in Use

# The SDK handles this automatically
# If issues persist, find and kill processes
ps aux | grep copilot
kill <PID>

Module Not Found (Node.js)

npm install

Module Not Found (Python)

source venv/bin/activate  # or .venv/bin/activate
pip install -r requirements.txt

Available Models

Check available models:

copilot models

Common models:

  • gpt-4.1 - Latest GPT-4 (recommended)
  • gpt-4o - GPT-4 Optimized
  • claude-3.5-sonnet - Claude 3.5 Sonnet

Directory Structure

my-agentic-app/
├── .env                  # Environment variables
├── .gitignore            # Git ignore rules
├── src/                  # Source code
│   ├── agents/           # Custom agent definitions
│   ├── tools/            # Custom tool implementations
│   └── main.[ts|py]      # Entry point
└── tests/                # Test files

Useful Links

Getting Help

Scripts Overview

Script Purpose Usage
scripts/setup-dev-env.sh Automated setup (Linux/macOS) bash scripts/setup-dev-env.sh
scripts/setup-dev-env.ps1 Automated setup (Windows) .\scripts\setup-dev-env.ps1
scripts/validate-env.sh Validate installation bash scripts/validate-env.sh

Template Overview

Template Language Features
typescript-quickstart TypeScript Interactive CLI, Custom tools, Hot reload
python-quickstart Python Interactive CLI, Custom tools, Async/await

Next Steps After Setup

  1. ✅ Validate environment: bash scripts/validate-env.sh
  2. ✅ Choose a template: cd templates/typescript-quickstart
  3. ✅ Install dependencies: npm install or pip install -r requirements.txt
  4. ✅ Create .env: cp ../../templates/.env.example .env
  5. ✅ Run: npm start or python src/main.py
  6. ✅ Customize tools and build your app!