Skip to content

Commit e1ed4d0

Browse files
committed
Add HTTP
1 parent 5b07ccc commit e1ed4d0

File tree

7 files changed

+115
-3
lines changed

7 files changed

+115
-3
lines changed

.devcontainer/devcontainer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"vscode": {
99
"extensions": [
1010
"ms-python.python",
11-
"ms-python.vscode-pylance",
12-
"charliermarsh.ruff",
11+
"ms-python.vscode-pylance",
12+
"charliermarsh.ruff",
1313
"ms-azuretools.azure-dev",
14-
"ms-azuretools.vscode-bicep"
14+
"ms-azuretools.vscode-bicep",
15+
"humao.rest-client"
1516
],
1617
"python.defaultInterpreterPath": "/usr/local/bin/python",
1718
"[python]": {

http/.env.azure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
AZURE_OPENAI_SERVICE=
2+
AZURE_OPENAI_GPT_DEPLOYMENT=
3+
AZURE_OPENAI_TOKEN=

http/.env.github

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# In Codespaces, you can find this value in the env variables. Otherwise, generate a new Personal Access Token in GitHub.
2+
GITHUB_TOKEN=

http/azure_openai.http

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
POST https://{{$dotenv AZURE_OPENAI_SERVICE}}.openai.azure.com/openai/deployments/{{$dotenv AZURE_OPENAI_GPT_DEPLOYMENT}}/chat/completions?api-version=2024-08-01-preview
2+
Authorization: Bearer {{$dotenv AZURE_OPENAI_TOKEN}}
3+
Content-Type: application/json
4+
5+
{
6+
"messages": [
7+
{"role": "system", "content": "Extract the event information."},
8+
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."}
9+
],
10+
"response_format": {
11+
"type": "json_schema",
12+
"json_schema": {
13+
"name": "CalendarEventResponse",
14+
"strict": true,
15+
"schema": {
16+
"type": "object",
17+
"properties": {
18+
"name": {
19+
"type": "string"
20+
},
21+
"date": {
22+
"type": "string"
23+
},
24+
"participants": {
25+
"type": "array",
26+
"items": {
27+
"type": "string"
28+
}
29+
}
30+
},
31+
"required": [
32+
"name",
33+
"date",
34+
"participants"
35+
],
36+
"additionalProperties": false
37+
}
38+
}
39+
}
40+
}

http/github_models.http

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
POST https://models.inference.ai.azure.com/chat/completions?api-version=2024-08-01-preview
2+
Authorization: Bearer {{$dotenv GITHUB_TOKEN}}
3+
Content-Type: application/json
4+
5+
{
6+
"model": "gpt-4o",
7+
"messages": [
8+
{"role": "system", "content": "Extract the event information."},
9+
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."}
10+
],
11+
"response_format": {
12+
"type": "json_schema",
13+
"json_schema": {
14+
"name": "CalendarEventResponse",
15+
"strict": true,
16+
"schema": {
17+
"type": "object",
18+
"properties": {
19+
"name": {
20+
"type": "string"
21+
},
22+
"date": {
23+
"type": "string"
24+
},
25+
"participants": {
26+
"type": "array",
27+
"items": {
28+
"type": "string"
29+
}
30+
}
31+
},
32+
"required": [
33+
"name",
34+
"date",
35+
"participants"
36+
],
37+
"additionalProperties": false
38+
}
39+
}
40+
}
41+
}

http/write_env_azure.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
from pathlib import Path
3+
4+
import azure.identity
5+
from dotenv_azd import load_azd_env
6+
7+
load_azd_env()
8+
9+
# Get a token from Azure
10+
token_provider = azure.identity.get_bearer_token_provider(
11+
azure.identity.AzureDeveloperCliCredential(tenant_id=os.getenv("AZURE_TENANT_ID")),
12+
"https://cognitiveservices.azure.com/.default"
13+
)
14+
token = token_provider()
15+
16+
# Path to the .env file in the current directory
17+
env_path = Path(__file__).parent / ".env"
18+
19+
# Write the new .env
20+
with open(env_path, "w") as f:
21+
f.write("")
22+
f.write(f"AZURE_OPENAI_SERVICE={os.getenv('AZURE_OPENAI_SERVICE')}\n")
23+
f.write(f"AZURE_OPENAI_GPT_DEPLOYMENT={os.getenv('AZURE_OPENAI_GPT_DEPLOYMENT')}\n")
24+
f.write(f"AZURE_OPENAI_TOKEN={token}\n")

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ rich
66
beautifulsoup4
77
pymupdf4llm
88
azure-ai-inference
9+
dotenv-azd

0 commit comments

Comments
 (0)