Skip to content

Commit

Permalink
fixed azure connection issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 20, 2024
1 parent 62fd2bd commit 9b1bc30
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/anthropic.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: anthropic tests
on:
workflow_dispatch:
release:
types:
- created
pull_request:
paths:
- yarn.lock
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/azure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: azure openai tests
on:
workflow_dispatch:
release:
types:
- created
pull_request:
paths:
- yarn.lock
- ".github/workflows/azure.yml"
- "packages/core/**/*"
- "packages/cli/**/*"
- "packages/samples/**/*"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-azure
cancel-in-progress: true
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: yarn
- run: yarn install --frozen-lockfile
- name: typecheck
run: yarn typecheck
- name: compile
run: yarn compile
- name: poem
run: yarn run:script poem --model azure:gpt-4o -tlp 5 --out-trace $GITHUB_STEP_SUMMARY
env:
AZURE_OPENAI_API_ENDPOINT: ${{ secrets.AZURE_OPENAI_API_ENDPOINT }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
5 changes: 4 additions & 1 deletion .github/workflows/google.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: google tests
on:
workflow_dispatch:
release:
types:
- created
pull_request:
paths:
- yarn.lock
- ".github/workflows/anthropic.yml"
- ".github/workflows/google.yml"
- "packages/core/**/*"
- "packages/cli/**/*"
- "packages/samples/**/*"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ollama.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: ollama smoke tests
on:
workflow_dispatch:
release:
types:
- created
pull_request:
paths:
- yarn.lock
Expand Down
6 changes: 3 additions & 3 deletions docs/src/content/docs/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ The rest of the steps are the same: Find the deployment name and use it in your

## Azure AI Serverless Deployments <a id="azure_serverless" href=""></a>

You can deploy "serverless" models through [Azure AI Studio](https://ai.azure.com/) and pay as you go per token.
You can deploy "serverless" models through [Azure AI Foundry](https://ai.azure.com/) and pay as you go per token.
You can browse the [Azure AI model catalog](https://ai.azure.com/explore/models)
and use the [serverless API](https://learn.microsoft.com/en-us/azure/ai-studio/how-to/deploy-models-serverless-availability) filter to see the available models.

Expand All @@ -493,7 +493,7 @@ They are configured slightly differently.

### Azure AI OpenAI

The `azure_serverless` provider supports OpenAI models deployed through the Azure AI Studio serverless deployments.
The `azure_serverless` provider supports OpenAI models deployed through the Azure AI Foundry serverless deployments.
It supports both Entra ID and key-based authentication.

```js "azure_serverless:"
Expand Down Expand Up @@ -593,7 +593,7 @@ AZURE_SERVERLESS_OPENAI_API_KEY=...

### Azure AI Models <a href="" id="azure_serverless_models" />

The `azure_serverless_models` provider supports non-OpenAI models deployed through the Azure AI Studio serverless deployments.
The `azure_serverless_models` provider supports non-OpenAI models deployed through the Azure AI Foundary serverless deployments.

```js "azure_serverless_models:"
script({ model: "azure_serverless_models:deployment-id" })
Expand Down
18 changes: 7 additions & 11 deletions packages/cli/src/azuretoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,44 +108,40 @@ class AzureTokenResolverImpl implements AzureTokenResolver {
return this._error
}

clear() {
this._token = undefined
this._error = undefined
this._resolver = undefined
}

async token(
credentialsType: AzureCredentialsType,
options?: CancellationOptions
): Promise<{ token?: AuthenticationToken; error?: SerializedError }> {
// cached
const { cancellationToken } = options || {}

if (isAzureTokenExpired(this._token)) this._token = undefined
if (isAzureTokenExpired(this._token)) {
logVerbose(`azure: ${this.name} token expired`)
this._token = undefined
this._error = undefined
}
if (this._token || this._error)
return { token: this._token, error: this._error }
if (!this._resolver) {
const scope = await runtimeHost.readSecret(this.envName)
const scopes = scope ? scope.split(",") : this.scopes
const resolver = (this._resolver = createAzureToken(
this._resolver = createAzureToken(
scopes,
credentialsType,
cancellationToken
)
.then((res) => {
if (this._resolver !== resolver) return undefined
this._token = res
this._error = undefined
this._resolver = undefined
return { token: this._token, error: this._error }
})
.catch((err) => {
if (this._resolver !== resolver) return undefined
this._resolver = undefined
this._token = undefined
this._error = serializeError(err)
return { token: this._token, error: this._error }
}))
})
}
return this._resolver
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export function isAzureTokenExpired(token: AuthenticationToken) {
}

export interface AzureTokenResolver {
clear(): void
token(
credentialsType: AzureCredentialsType,
options?: CancellationOptions
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ import { INITryParse } from "./ini"
import { serializeChunkChoiceToLogProbs } from "./logprob"

export function getConfigHeaders(cfg: LanguageModelConfiguration) {
const { provider } = parseModelIdentifier(cfg.model)
let { token, type, base } = cfg
let { token, type, base, provider } = cfg
if (type === "azure_serverless_models") {
const keys = INITryParse(token)
if (keys && Object.keys(keys).length > 1) token = keys[cfg.model]
Expand Down

0 comments on commit 9b1bc30

Please sign in to comment.