diff --git a/.github/instructions/docs-style.instructions.md b/.github/instructions/docs-style.instructions.md index 36ad720156..36abe44d7d 100644 --- a/.github/instructions/docs-style.instructions.md +++ b/.github/instructions/docs-style.instructions.md @@ -160,3 +160,67 @@ Body text here. * [Link text](./relative-path.md): short description ``` + +## Multi-language code examples + +When showing the same concept in multiple programming languages, use consecutive `
` blocks. The docs-internal normalization pipeline converts these into tabbed language switchers on docs.github.com. + +### Rules + +* **Only code inside `
` blocks.** Shared prose, headings, and explanations must go outside the blocks. Each block should contain only a code fence (and optionally a `` comment). +* **Blocks must be consecutive.** No content (headings, paragraphs) between `
` blocks in the same group. Blank lines between blocks are fine. +* **Use the exact `` format:** `LANGUAGE`. Supported labels: `.NET`, `Python`, `TypeScript`, `Go`, `Java`, `Rust`, `Node.js`, `Shell`. +* **Need 2+ blocks to form a group.** A single `
` block won't be converted and renders as raw HTML on docs.github.com. +* **Equal content across tabs.** Each tab should show the same concept in a different language. Language-specific extras should be a separate section outside the tabs. + +### Correct + +Shared prose goes above the group, then each `
` block contains only code: + +```markdown +Install the SDK: + +
+.NET + + + +```bash +dotnet add package GitHub.Copilot.SDK +``` + +
+
+Python + + + +```bash +pip install github-copilot-sdk +``` + +
+``` + +### Incorrect + +Do not put headings, prose, or multiple sections inside a `
` block: + +```markdown +
+Python + +### Prerequisites ← breaks TOC/anchors +Install the packages: ← prose belongs outside + +```bash +pip install github-copilot-sdk +``` + +### Basic usage ← multiple sections in one tab +```python +[code] +``` + +
+``` diff --git a/docs/setup/azure-managed-identity.md b/docs/setup/azure-managed-identity.md index bf90ed99c5..51ca0dc0be 100644 --- a/docs/setup/azure-managed-identity.md +++ b/docs/setup/azure-managed-identity.md @@ -29,20 +29,49 @@ sequenceDiagram ## Code samples +### Prerequisites + +Install the Azure Identity and Copilot SDK packages for your language: +
.NET -### Prerequisites - -Install the required packages: + ```bash dotnet add package GitHub.Copilot.SDK dotnet add package Azure.Core ``` +
+
+Python + + + +```bash +pip install github-copilot-sdk azure-identity +``` + +
+
+TypeScript + + + +```bash +npm install @github/copilot-sdk @azure/identity +``` + +
+ ### Basic usage +Get a token using `DefaultAzureCredential` and pass it as the bearer token in your provider configuration: + +
+.NET + ```csharp @@ -76,20 +105,9 @@ Console.WriteLine(response?.Data.Content); ```
-
Python -### Prerequisites - -Install the required packages: - -```bash -pip install github-copilot-sdk azure-identity -``` - -### Basic usage - ```python @@ -133,9 +151,46 @@ async def main(): asyncio.run(main()) ``` +
+
+TypeScript + + + +```typescript +import { DefaultAzureCredential } from "@azure/identity"; +import { CopilotClient } from "@github/copilot-sdk"; + +const credential = new DefaultAzureCredential({ + requiredEnvVars: ["AZURE_TOKEN_CREDENTIALS"], +}); +const tokenResponse = await credential.getToken( + "https://ai.azure.com/.default" +); + +const client = new CopilotClient(); + +const session = await client.createSession({ + model: "gpt-5.5", + provider: { + type: "openai", + baseUrl: `${process.env.FOUNDRY_RESOURCE_URL}/openai/v1/`, + bearerToken: tokenResponse.token, + wireApi: "responses", + }, +}); + +const response = await session.sendAndWait({ prompt: "Hello!" }); +console.log(response?.data.content); + +await client.stop(); +``` + +
+ ### Token refresh for long-running applications -Bearer tokens expire (typically after ~1 hour). For servers or long-running agents, refresh the token before creating each session: +Bearer tokens expire (typically after ~1 hour). For servers or long-running agents, refresh the token before creating each session. The following Python example demonstrates this pattern: @@ -181,54 +236,6 @@ class ManagedIdentityCopilotAgent: return response.data.content if response else "" ``` -
- -
-TypeScript - -### Prerequisites - -Install the required packages: - -```bash -npm install @github/copilot-sdk @azure/identity -``` - -### Basic usage - - - -```typescript -import { DefaultAzureCredential } from "@azure/identity"; -import { CopilotClient } from "@github/copilot-sdk"; - -const credential = new DefaultAzureCredential({ - requiredEnvVars: ["AZURE_TOKEN_CREDENTIALS"], -}); -const tokenResponse = await credential.getToken( - "https://ai.azure.com/.default" -); - -const client = new CopilotClient(); - -const session = await client.createSession({ - model: "gpt-5.5", - provider: { - type: "openai", - baseUrl: `${process.env.FOUNDRY_RESOURCE_URL}/openai/v1/`, - bearerToken: tokenResponse.token, - wireApi: "responses", - }, -}); - -const response = await session.sendAndWait({ prompt: "Hello!" }); -console.log(response?.data.content); - -await client.stop(); -``` - -
- ## Environment configuration | Variable | Description | Example |