Skip to content

Commit

Permalink
Refactor Azure login instructions and streamline configuration update…
Browse files Browse the repository at this point in the history
… process in the VSCode extension
  • Loading branch information
pelikhan committed Sep 5, 2024
1 parent 3e09693 commit f569f0e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
32 changes: 11 additions & 21 deletions docs/src/content/docs/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ for GitHub Models, you can use the `GITHUB_MODELS_TOKEN` variable instead.
## Azure OpenAI <a id="azure" href=""></a>

The [Azure OpenAI](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#chat-completions) provider, `azure` uses the `AZURE_OPENAI_...` environment variables.

Check failure on line 216 in docs/src/content/docs/getting-started/configuration.mdx

View workflow job for this annotation

GitHub Actions / build

Duplicate content found. The sentence "You can use a managed identity (recommended) or a API key to authenticate with the Azure OpenAI service." is repeated.
You can use a managed identity (recommended) or a API key to authenticate with the Azure OpenAI service.
You can use a managed identity (recommended) or a API key to authenticate with the Azure OpenAI service.
You can also use a service principal as documented in [automation](/genaiscript/getting-started/automating-scripts).

Check warning on line 218 in docs/src/content/docs/getting-started/configuration.mdx

View workflow job for this annotation

GitHub Actions / build

The link provided in "[automation](/genaiscript/getting-started/automating-scripts)" might be broken or incorrect. It should be verified if it correctly leads to the automation documentation.

### Managed Identity (Entra ID)
Expand Down Expand Up @@ -262,6 +262,16 @@ Navigate to **deployments** and make sure that you have your LLM deployed and co

<li>

Open a terminal and **login** with [Azure CLI](https://learn.microsoft.com/en-us/javascript/api/overview/azure/identity-readme?view=azure-node-latest#authenticate-via-the-azure-cli).

```sh
az login
```

Check notice on line 269 in docs/src/content/docs/getting-started/configuration.mdx

View workflow job for this annotation

GitHub Actions / build

Content has been relocated. Instructions for logging in with Azure CLI have been moved from a subsection into a list item.

</li>

<li>

Update the `model` field in the `script` function to match the model deployment name in your Azure resource.

Check failure on line 275 in docs/src/content/docs/getting-started/configuration.mdx

View workflow job for this annotation

GitHub Actions / build

Incorrect reference in the documentation. The `model` field should be updated to match the model deployment name, but the provided code snippet incorrectly references 'model: "***:deployment-id"' which is not a valid deployment name.

```js 'model: "azure:deployment-id"'
Expand All @@ -273,30 +283,10 @@ script({

</li>

<li>

Open a terminal and login to Azure. See Visual Studio or CLI instructions below.

</li>

</ol>

</Steps>

#### Visual Studio Code

Visual Studio Code will ask you to allow using the **Microsoft** account
and then will open a browser where you can choose the user or service principal.

#### CLI

Login with [Azure CLI](https://learn.microsoft.com/en-us/javascript/api/overview/azure/identity-readme?view=azure-node-latest#authenticate-via-the-azure-cli)
then use the [cli](/genaiscript/reference/cli) as usual.

```sh
az login
```

### API Key

<Steps>
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,4 @@ export async function updateConnectionConfiguration(
if (!content.includes(DOT_ENV_FILENAME))
await writeText(".gitignore", content + `\n${DOT_ENV_FILENAME}\n`)
}

// update .env
// const { config } = dotEnvTemplate(provider, apiType)
// const current = await tryReadText(DOT_ENV_FILENAME)
//await writeText(DOT_ENV_FILENAME, config)
}
12 changes: 8 additions & 4 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import { activateTestController } from "./testcontroller"
import { activateDocsNotebook } from "./docsnotebook"
import { activateTraceTreeDataProvider } from "./tracetree"
import { registerCommand } from "./commands"
import { EXTENSION_ID, TOOL_NAME } from "../../core/src/constants"
import {
DOCS_CONFIGURATION_URL,
EXTENSION_ID,
TOOL_NAME,
} from "../../core/src/constants"
import type MarkdownIt from "markdown-it"
import MarkdownItGitHubAlerts from "markdown-it-github-alerts"
import { activateConnectionInfoTree } from "./connectioninfotree"
import { updateConnectionConfiguration } from "../../core/src/connection"
import { APIType } from "../../core/src/host"
import { openUrlInTab } from "./browser"

export async function activate(context: ExtensionContext) {
const state = new ExtensionState(context)
Expand All @@ -37,10 +42,9 @@ export async function activate(context: ExtensionContext) {
"genaiscript.connection.configure",
async (provider?: string, apiType?: APIType) => {
await updateConnectionConfiguration(provider, apiType)
const doc = await vscode.workspace.openTextDocument(
state.host.toUri("./.env")
await vscode.env.openExternal(
vscode.Uri.parse(DOCS_CONFIGURATION_URL)
)
await vscode.window.showTextDocument(doc)
}
),
registerCommand("genaiscript.request.abort", async () => {
Expand Down
15 changes: 12 additions & 3 deletions packages/vscode/src/lmaccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,18 @@ export async function pickLanguageModel(

if (res.model) return res.model
else {
vscode.window.showWarningMessage(
`${TOOL_NAME} - model connection not configured.`
)
const configure = "Configure..."
vscode.window
.showWarningMessage(
`${TOOL_NAME} - model connection not configured.`,
configure
)
.then((res) => {
if (res === configure)
vscode.commands.executeCommand(
"genaiscript.connection.configure"
)
})

Check failure on line 158 in packages/vscode/src/lmaccess.ts

View workflow job for this annotation

GitHub Actions / build

The `then` function is used after `showWarningMessage`, but the function inside `then` is not awaited. This could lead to unexpected behavior as the function might not complete before the next line of code is executed. Consider using `await` with `then` or converting the promise chain to async/await for better readability and error handling. 🔄
return undefined
}
}
Expand Down

0 comments on commit f569f0e

Please sign in to comment.