Skip to content

Commit a307f43

Browse files
authored
Merge pull request #14 from ks6088ts-labs/feature/issue-13_azure-functions
support Azure Functions
2 parents ba8a753 + 8db6d5b commit a307f43

File tree

15 files changed

+148
-15
lines changed

15 files changed

+148
-15
lines changed

.funcignore

Whitespace-only changes.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,5 @@ cython_debug/
161161

162162
# Project
163163
*.env
164+
requirements.txt
165+
azure-functions.json

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions"
4+
]
5+
}

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ format: ## format code
3333
.PHONY: lint
3434
lint: ## lint
3535
poetry run ruff check .
36+
shellcheck scripts/*.sh
3637

3738
.PHONY: test
3839
test: ## run tests
@@ -89,3 +90,27 @@ backend: ## run backend
8990
.PHONY: frontend
9091
frontend: ## run frontend
9192
poetry run streamlit run main.py -- frontend -- --solution-name=$(SOLUTION_NAME)
93+
94+
# ---
95+
# Azure Functions
96+
# ---
97+
.PHONY: azure-functions-start
98+
azure-functions-start: ## start Azure Functions
99+
poetry run func start
100+
101+
.PHONY: azure-functions-deploy
102+
azure-functions-deploy: ## deploy Azure Functions resources
103+
sh ./scripts/deploy-azure-functions.sh
104+
105+
.PHONY: azure-functions-destroy
106+
azure-functions-destroy: ## destroy Azure Functions resources
107+
sh ./scripts/destroy-azure-functions.sh
108+
109+
.PHONY: azure-functions-functionapp-deploy
110+
azure-functions-functionapp-deploy: ## deploy Azure Functions App
111+
poetry export \
112+
--format requirements.txt \
113+
--output requirements.txt \
114+
--with backend,azure-functions \
115+
--without-hashes
116+
func azure functionapp publish $(shell jq -r '.FUNCTION_APP_NAME' < azure-functions.json)

azure_openai.env.sample

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ENDPOINT = "https://<aoai-name>.openai.azure.com/"
2-
API_KEY = "<aoai-api-key>"
3-
API_VERSION = "2024-02-01"
4-
EMBEDDING_MODEL = "text-embedding-ada-002"
5-
GPT_MODEL = "gpt-35-turbo"
1+
AZURE_OPENAI_ENDPOINT = "https://<aoai-name>.openai.azure.com/"
2+
AZURE_OPENAI_API_KEY = "<aoai-api-key>"
3+
AZURE_OPENAI_API_VERSION = "2024-02-01"
4+
AZURE_OPENAI_EMBEDDING_MODEL = "text-embedding-ada-002"
5+
AZURE_OPENAI_GPT_MODEL = "gpt-35-turbo"

backend/internals/azure_openai.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ def create_chat_completions(
1515
body: azure_openai_schemas.ChatCompletionRequest,
1616
) -> azure_openai_schemas.ChatCompletionResponse:
1717
client = AzureOpenAI(
18-
api_key=settings.api_key,
19-
api_version=settings.api_version,
20-
azure_endpoint=settings.endpoint,
18+
api_key=settings.azure_openai_api_key,
19+
api_version=settings.azure_openai_api_version,
20+
azure_endpoint=settings.azure_openai_endpoint,
2121
)
2222
response: ChatCompletion = client.chat.completions.create(
23-
model=settings.gpt_model,
23+
model=settings.azure_openai_gpt_model,
2424
messages=[
2525
{
2626
"role": "user",

backend/settings/azure_openai.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33

44
class Settings(BaseSettings):
5-
endpoint: str = "https://<aoai-name>.openai.azure.com/"
6-
api_key: str = "<aoai-api-key>"
7-
api_version: str = "2024-02-01"
8-
embedding_model: str = "text-embedding-ada-002"
9-
gpt_model: str = "gpt-35-turbo"
5+
azure_openai_endpoint: str = "https://<aoai-name>.openai.azure.com/"
6+
azure_openai_api_key: str = "<aoai-api-key>"
7+
azure_openai_api_version: str = "2024-02-01"
8+
azure_openai_embedding_model: str = "text-embedding-ada-002"
9+
azure_openai_gpt_model: str = "gpt-35-turbo"
1010

1111
model_config = SettingsConfigDict(
1212
env_file="azure_openai.env",

docs/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@
1919

2020
## Azure
2121

22+
### Azure OpenAI Service
23+
2224
- [Azure-Samples/openai](https://github.com/Azure-Samples/openai)
25+
26+
### Azure Functions
27+
28+
- [Quickstart: Create a Python function in Azure from the command line](https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-python?tabs=linux%2Cbash%2Cazure-cli%2Cbrowser)
29+
- [Using FastAPI Framework with Azure Functions](https://learn.microsoft.com/en-us/samples/azure-samples/fastapi-on-azure-functions/fastapi-on-azure-functions/)

function_app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import azure.functions as func
2+
3+
from backend.fastapi import app as fastapi_app
4+
5+
app = func.AsgiFunctionApp(
6+
app=fastapi_app,
7+
http_auth_level=func.AuthLevel.ANONYMOUS,
8+
)

host.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": "2.0",
3+
"extensions": {
4+
"http": {
5+
"routePrefix": ""
6+
}
7+
},
8+
"logging": {
9+
"applicationInsights": {
10+
"samplingSettings": {
11+
"isEnabled": true,
12+
"excludedTypes": "Request"
13+
}
14+
}
15+
},
16+
"extensionBundle": {
17+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
18+
"version": "[4.*, 5.0.0)"
19+
}
20+
}

0 commit comments

Comments
 (0)