- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_app.py
More file actions
Latest commit
52 lines (41 loc) · 1.61 KB
/
Copy pathfunction_app.py
File metadata and controls
52 lines (41 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
importazure.functionsasfunc
importlogging
importopenai
importtiktoken
app=func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
@app.route(route="http_trigger_count_tokens")
defhttp_trigger_count_tokens(req: func.HttpRequest) ->func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name=req.params.get('name')
ifnotname:
try:
req_body=req.get_json()
exceptValueError:
pass
else:
name=req_body.get('name')
ifname:
returnfunc.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
returnfunc.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
@app.route(route="http_trigger", auth_level=func.AuthLevel.FUNCTION)
defhttp_trigger(req: func.HttpRequest) ->func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name=req.params.get('name')
ifnotname:
try:
req_body=req.get_json()
exceptValueError:
pass
else:
name=req_body.get('name')
ifname:
returnfunc.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
returnfunc.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)