Skip to content

Commit f266add

Browse files
committed
Fixing function auth level and minor formatting
Signed-off-by: Paul Yuknewicz <[email protected]>
1 parent b9681b9 commit f266add

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

function_app.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@
1919
).token
2020

2121

22-
@app.function_name(name='ask')
23-
@app.route(route='ask', auth_level='anonymous', methods=['POST'])
22+
@app.function_name(name="ask")
23+
@app.route(route="ask", auth_level="function", methods=["POST"])
2424
def main(req):
2525

26-
prompt = req.params.get('prompt')
27-
if not prompt:
28-
try:
29-
req_body = req.get_json()
30-
except ValueError:
26+
try:
27+
req_body = req.get_json()
28+
prompt = req_body.get("prompt")
29+
except ValueError:
30+
raise RuntimeError("prompt data must be set in POST.")
31+
else:
32+
if not prompt:
3133
raise RuntimeError("prompt data must be set in POST.")
32-
else:
33-
prompt = req_body.get('prompt')
34-
if not prompt:
35-
raise RuntimeError("prompt data must be set in POST.")
3634

3735
# Init OpenAI: configure these using Env Variables
3836
AZURE_OPENAI_ENDPOINT = os.environ.get("AZURE_OPENAI_ENDPOINT")
@@ -47,7 +45,7 @@ def main(req):
4745
# configure azure openai for langchain and/or llm
4846
openai.api_key = AZURE_OPENAI_KEY
4947
openai.api_base = AZURE_OPENAI_ENDPOINT
50-
openai.api_type = 'azure'
48+
openai.api_type = "azure"
5149

5250
# this may change in the future
5351
openai.api_version = OPENAI_API_VERSION

0 commit comments

Comments
 (0)