Skip to content

Commit 8bcb123

Browse files
docs: Added files to support vs code web
2 parents fd33de9 + ceaba45 commit 8bcb123

File tree

11 files changed

+295
-0
lines changed

11 files changed

+295
-0
lines changed

infra/vscode_web/.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
AZURE_EXISTING_AGENT_ID="<%= agentId %>"
2+
AZURE_ENV_NAME="<%= playgroundName %>"
3+
AZURE_LOCATION="<%= location %>"
4+
AZURE_SUBSCRIPTION_ID="<%= subscriptionId %>"
5+
AZURE_EXISTING_AIPROJECT_ENDPOINT="<%= endpoint %>"
6+
AZURE_EXISTING_AIPROJECT_RESOURCE_ID="<%= projectResourceId %>"
7+
AZD_ALLOW_NON_EMPTY_FOLDER=true

infra/vscode_web/.gitignore

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# ========== .NET ========== #
2+
## Build results
3+
bin/
4+
obj/
5+
[Bb]uild/
6+
[Ll]ogs/
7+
*.log
8+
## User-specific files
9+
*.user
10+
*.suo
11+
*.userosscache
12+
*.sln.docstates
13+
*.vsp
14+
*.vspx
15+
*.vspscc
16+
## Rider / VS Code / Visual Studio
17+
.idea/
18+
.vscode/
19+
.vs/
20+
## NuGet packages
21+
*.nupkg
22+
packages/
23+
*.snupkg
24+
project.lock.json
25+
project.assets.json
26+
## Dotnet tools
27+
.tools/
28+
# ========== Java ========== #
29+
## Compiled class files
30+
*.class
31+
## Logs
32+
*.log
33+
## Maven
34+
target/
35+
## Gradle
36+
.gradle/
37+
build/
38+
## Eclipse
39+
.project
40+
.classpath
41+
.settings/
42+
.loadpath
43+
## IntelliJ IDEA
44+
*.iml
45+
*.ipr
46+
*.iws
47+
out/
48+
.idea/
49+
# ========== Python ========== #
50+
## Byte-compiled / cache
51+
__pycache__/
52+
*.py[cod]
53+
*$py.class
54+
## Virtual environment
55+
env/
56+
venv/
57+
ENV/
58+
.venv/
59+
.env*
60+
## PyInstaller
61+
*.spec
62+
dist/
63+
build/
64+
## Jupyter Notebook
65+
.ipynb_checkpoints/
66+
## Misc
67+
*.log
68+
*.pot
69+
*.pyc
70+
.DS_Store
71+
*.sqlite3
72+
# ========== General ========== #
73+
## OS generated
74+
Thumbs.db
75+
ehthumbs.db
76+
Desktop.ini
77+
.DS_Store
78+
*.swp
79+
*.swo
80+
*.bak
81+
*.tmp
82+
*.old
83+
## Node (just in case mixed project)
84+
node_modules/
85+
# End

infra/vscode_web/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

infra/vscode_web/README-noazd.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# VS Code for the Web - Azure AI Foundry Templates
2+

infra/vscode_web/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# VS Code for the Web - Azure AI Foundry Templates
2+
3+
We've generated a simple development environment for you to deploy the templates.
4+
5+
The Azure AI Foundry extension provides tools to help you build, test, and deploy AI models and AI Applications directly from VS Code. It offers simplified operations for interacting with your models, agents, and threads without leaving your development environment. Click on the Azure AI Foundry Icon on the left to see more.
6+
7+
Follow the instructions below to get started!
8+
9+
You should see a terminal opened with the template code already cloned.
10+
11+
## Deploy the template
12+
13+
You can provision and deploy this template using:
14+
15+
```bash
16+
azd up
17+
```
18+
19+
Follow any instructions from the deployment script and launch the application.
20+
21+
22+
If you need to delete the deployment and stop incurring any charges, run:
23+
24+
```bash
25+
azd down
26+
```
27+
28+
## Continuing on your local desktop
29+
30+
You can keep working locally on VS Code Desktop by clicking "Continue On Desktop..." at the bottom left of this screen. Be sure to take the .env file with you using these steps:
31+
32+
- Right-click the .env file
33+
- Select "Download"
34+
- Move the file from your Downloads folder to the local git repo directory
35+
- For Windows, you will need to rename the file back to .env using right-click "Rename..."
36+
37+
## More examples
38+
39+
Check out [Azure AI Projects client library for Python](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/README.md) for more information on using this SDK.
40+
41+
## Troubleshooting
42+
43+
- If you are instantiating your client via endpoint on an Azure AI Foundry project, ensure the endpoint is set in the `.env` as https://{your-foundry-resource-name}.services.ai.azure.com/api/projects/{your-foundry-project-name}`

infra/vscode_web/codeSample.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from azure.ai.projects import AIProjectClient
2+
from azure.identity import DefaultAzureCredential
3+
4+
project_client = AIProjectClient.from_connection_string(
5+
credential=DefaultAzureCredential(),
6+
conn_str="<%= connectionString %>")
7+
8+
agent = project_client.agents.get_agent("<%= agentId %>")
9+
10+
thread = project_client.agents.create_thread()
11+
print(f"Created thread, ID: {thread.id}")
12+
13+
message = project_client.agents.create_message(
14+
thread_id=thread.id,
15+
role="user",
16+
content="<%= userMessage %>"
17+
)
18+
19+
run = project_client.agents.create_and_process_run(
20+
thread_id=thread.id,
21+
agent_id=agent.id)
22+
messages = project_client.agents.list_messages(thread_id=thread.id)
23+
24+
for text_message in messages.text_messages:
25+
print(text_message.as_dict())
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
azure-ai-projects==1.0.0b12
2+
azure-identity==1.20.0
3+
ansible-core~=2.17.0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from azure.ai.projects import AIProjectClient
2+
from azure.identity import DefaultAzureCredential
3+
from azure.ai.agents.models import ListSortOrder
4+
5+
project = AIProjectClient(
6+
credential=DefaultAzureCredential(),
7+
endpoint="<%= endpoint %>")
8+
9+
agent = project.agents.get_agent("<%= agentId %>")
10+
11+
thread = project.agents.threads.create()
12+
print(f"Created thread, ID: {thread.id}")
13+
14+
message = project.agents.messages.create(
15+
thread_id=thread.id,
16+
role="user",
17+
content="<%= userMessage %>"
18+
)
19+
20+
run = project.agents.runs.create_and_process(
21+
thread_id=thread.id,
22+
agent_id=agent.id)
23+
24+
if run.status == "failed":
25+
print(f"Run failed: {run.last_error}")
26+
else:
27+
messages = project.agents.messages.list(thread_id=thread.id, order=ListSortOrder.ASCENDING)
28+
29+
for message in messages:
30+
if message.text_messages:
31+
print(f"{message.role}: {message.text_messages[-1].text.value}")

infra/vscode_web/index.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"ai-projects-sdk": {
3+
"python": {
4+
"default-azure-auth": {
5+
"connectionString": [
6+
{
7+
"name": "run_agent.py",
8+
"type": "code",
9+
"path": "/codeSample.py"
10+
},
11+
{
12+
"name": "INSTRUCTIONS.md",
13+
"type": "readme",
14+
"path": "/README-noazd.md"
15+
},
16+
{
17+
"name": "requirements.txt",
18+
"type": "dependencies",
19+
"path": "/requirements.txt"
20+
},
21+
{
22+
"name": ".env",
23+
"type": "env",
24+
"path": "/.env"
25+
},
26+
{
27+
"name": "install.sh",
28+
"type": "install",
29+
"path": "/install.sh"
30+
},
31+
{
32+
"name": ".gitignore",
33+
"type": "code",
34+
"path": "/.gitignore"
35+
}
36+
],
37+
"endpoint": [
38+
{
39+
"name": "run_agent.py",
40+
"type": "code",
41+
"path": "/endpointCodeSample.py"
42+
},
43+
{
44+
"name": "INSTRUCTIONS.md",
45+
"type": "readme",
46+
"path": "/README.md"
47+
},
48+
{
49+
"name": "requirements.txt",
50+
"type": "dependencies",
51+
"path": "/endpoint-requirements.txt"
52+
},
53+
{
54+
"name": ".env",
55+
"type": "env",
56+
"path": "/.env"
57+
},
58+
{
59+
"name": "install.sh",
60+
"type": "install",
61+
"path": "/install.sh"
62+
},
63+
{
64+
"name": ".gitignore",
65+
"type": "code",
66+
"path": "/.gitignore"
67+
}
68+
]
69+
}
70+
}
71+
}
72+
}

infra/vscode_web/install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pip install -r requirements.txt --user -q
2+
3+
azd init -t microsoft/content-processing-solution-accelerator

0 commit comments

Comments
 (0)