From d76376d7a42ae5082ffda236f6a828ed2e2f872a Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 08:57:19 +0530 Subject: [PATCH 01/14] Update azfunctionapp_cicd.yml --- .github/workflows/azfunctionapp_cicd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/azfunctionapp_cicd.yml b/.github/workflows/azfunctionapp_cicd.yml index bdad421..6324749 100644 --- a/.github/workflows/azfunctionapp_cicd.yml +++ b/.github/workflows/azfunctionapp_cicd.yml @@ -12,12 +12,12 @@ on: GIT_FunctionApp_Name: description: 'Provide the Function App Name' required: true - default: 'functionappsrs' + default: 'bicep-funcgdekhfv' GIT_FunctionApp_URL: description: 'Provide the Function App URL' required: true - default: 'https://functionappsrs.azurewebsites.net' + default: 'https://bicep-funcgdekhfv.azurewebsites.net' # This is the path of your Function app in Git. GIT_FunctionApp_PATH: From 6ad9650c4bc0035460f3a0d3e9e979622e665a50 Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:29:30 +0530 Subject: [PATCH 02/14] Delete FunctionApp/DemoSample/HttpTrigger1 directory --- .../DemoSample/HttpTrigger1/__init__.py | 24 ------------------- .../DemoSample/HttpTrigger1/function.json | 20 ---------------- .../DemoSample/HttpTrigger1/sample.dat | 3 --- 3 files changed, 47 deletions(-) delete mode 100644 FunctionApp/DemoSample/HttpTrigger1/__init__.py delete mode 100644 FunctionApp/DemoSample/HttpTrigger1/function.json delete mode 100644 FunctionApp/DemoSample/HttpTrigger1/sample.dat diff --git a/FunctionApp/DemoSample/HttpTrigger1/__init__.py b/FunctionApp/DemoSample/HttpTrigger1/__init__.py deleted file mode 100644 index d6f3ea7..0000000 --- a/FunctionApp/DemoSample/HttpTrigger1/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -import logging - -import azure.functions as func - - -def main(req: func.HttpRequest) -> func.HttpResponse: - logging.info('Python HTTP trigger function processed a request.') - - name = req.params.get('name') - if not name: - try: - req_body = req.get_json() - except ValueError: - pass - else: - name = req_body.get('name') - - if name: - return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.") - else: - return func.HttpResponse( - "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.Hello i am Sumit", - status_code=200 - ) diff --git a/FunctionApp/DemoSample/HttpTrigger1/function.json b/FunctionApp/DemoSample/HttpTrigger1/function.json deleted file mode 100644 index b8dc650..0000000 --- a/FunctionApp/DemoSample/HttpTrigger1/function.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "function", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} diff --git a/FunctionApp/DemoSample/HttpTrigger1/sample.dat b/FunctionApp/DemoSample/HttpTrigger1/sample.dat deleted file mode 100644 index 26aac46..0000000 --- a/FunctionApp/DemoSample/HttpTrigger1/sample.dat +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "Azure" -} \ No newline at end of file From 26876ba7a6c8f1525f2d253d90716007cc023e23 Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:31:44 +0530 Subject: [PATCH 03/14] Delete FunctionApp/DemoSample/.funcignore --- FunctionApp/DemoSample/.funcignore | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 FunctionApp/DemoSample/.funcignore diff --git a/FunctionApp/DemoSample/.funcignore b/FunctionApp/DemoSample/.funcignore deleted file mode 100644 index 0678ea2..0000000 --- a/FunctionApp/DemoSample/.funcignore +++ /dev/null @@ -1,5 +0,0 @@ -.git* -.vscode -local.settings.json -test -.venv \ No newline at end of file From de4c1db89ef7342dccdbf40ffe0b1d4aa9a37259 Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:32:20 +0530 Subject: [PATCH 04/14] Delete FunctionApp/DemoSample/.gitignore --- FunctionApp/DemoSample/.gitignore | 135 ------------------------------ 1 file changed, 135 deletions(-) delete mode 100644 FunctionApp/DemoSample/.gitignore diff --git a/FunctionApp/DemoSample/.gitignore b/FunctionApp/DemoSample/.gitignore deleted file mode 100644 index 7685fc4..0000000 --- a/FunctionApp/DemoSample/.gitignore +++ /dev/null @@ -1,135 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don’t work, or not -# install all needed dependencies. -#Pipfile.lock - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# Azure Functions artifacts -bin -obj -appsettings.json -local.settings.json - -# Azurite artifacts -__blobstorage__ -__queuestorage__ -__azurite_db*__.json -.python_packages \ No newline at end of file From 28c78c7b89f96c294cb5ebfad4236ad6a0fd868d Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:32:35 +0530 Subject: [PATCH 05/14] Delete FunctionApp/DemoSample/host.json --- FunctionApp/DemoSample/host.json | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 FunctionApp/DemoSample/host.json diff --git a/FunctionApp/DemoSample/host.json b/FunctionApp/DemoSample/host.json deleted file mode 100644 index 3f33af1..0000000 --- a/FunctionApp/DemoSample/host.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } - }, - "extensionBundle": { - "id": "Microsoft.Azure.Functions.ExtensionBundle", - "version": "[2.*, 3.0.0)" - } -} From e67866ac06e2eb61d3cb71aaf9bdcaa4fad39b27 Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:33:16 +0530 Subject: [PATCH 06/14] Update requirements.txt --- FunctionApp/DemoSample/requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/FunctionApp/DemoSample/requirements.txt b/FunctionApp/DemoSample/requirements.txt index bdb8fc5..0f81981 100644 --- a/FunctionApp/DemoSample/requirements.txt +++ b/FunctionApp/DemoSample/requirements.txt @@ -3,3 +3,7 @@ # Manually managing azure-functions-worker may cause unexpected issues azure-functions +azure-cognitiveservices-vision-computervision +azure-ai-vision-imageanalysis +openai +langchain From d68c1d990baba54625af28425e75062de76e25e5 Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:37:26 +0530 Subject: [PATCH 07/14] Create HttpTrigger1 --- FunctionApp/DemoSample/HttpTrigger1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 FunctionApp/DemoSample/HttpTrigger1 diff --git a/FunctionApp/DemoSample/HttpTrigger1 b/FunctionApp/DemoSample/HttpTrigger1 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/FunctionApp/DemoSample/HttpTrigger1 @@ -0,0 +1 @@ + From 972f536086583dedf6f8d1eb86685f868085c69a Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:38:09 +0530 Subject: [PATCH 08/14] Delete FunctionApp/DemoSample/HttpTrigger1 --- FunctionApp/DemoSample/HttpTrigger1 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 FunctionApp/DemoSample/HttpTrigger1 diff --git a/FunctionApp/DemoSample/HttpTrigger1 b/FunctionApp/DemoSample/HttpTrigger1 deleted file mode 100644 index 8b13789..0000000 --- a/FunctionApp/DemoSample/HttpTrigger1 +++ /dev/null @@ -1 +0,0 @@ - From 34709374f5de64726e9715ae9dfb8523e1f9b174 Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:39:16 +0530 Subject: [PATCH 09/14] Add files via upload --- FunctionApp/DemoSample/.funcignore | 8 ++ FunctionApp/DemoSample/.gitignore | 135 +++++++++++++++++++++ FunctionApp/DemoSample/host.json | 15 +++ FunctionApp/DemoSample/local.settings.json | 7 ++ 4 files changed, 165 insertions(+) create mode 100644 FunctionApp/DemoSample/.funcignore create mode 100644 FunctionApp/DemoSample/.gitignore create mode 100644 FunctionApp/DemoSample/host.json create mode 100644 FunctionApp/DemoSample/local.settings.json diff --git a/FunctionApp/DemoSample/.funcignore b/FunctionApp/DemoSample/.funcignore new file mode 100644 index 0000000..046864b --- /dev/null +++ b/FunctionApp/DemoSample/.funcignore @@ -0,0 +1,8 @@ +.git* +.vscode +__azurite_db*__.json +__blobstorage__ +__queuestorage__ +local.settings.json +test +.venv \ No newline at end of file diff --git a/FunctionApp/DemoSample/.gitignore b/FunctionApp/DemoSample/.gitignore new file mode 100644 index 0000000..3e4bf64 --- /dev/null +++ b/FunctionApp/DemoSample/.gitignore @@ -0,0 +1,135 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don’t work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# Azure Functions artifacts +bin +obj +appsettings.json +local.settings.json + +# Azurite artifacts +__blobstorage__ +__queuestorage__ +__azurite_db*__.json +.python_packages \ No newline at end of file diff --git a/FunctionApp/DemoSample/host.json b/FunctionApp/DemoSample/host.json new file mode 100644 index 0000000..9df9136 --- /dev/null +++ b/FunctionApp/DemoSample/host.json @@ -0,0 +1,15 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[4.*, 5.0.0)" + } +} \ No newline at end of file diff --git a/FunctionApp/DemoSample/local.settings.json b/FunctionApp/DemoSample/local.settings.json new file mode 100644 index 0000000..4b4cfce --- /dev/null +++ b/FunctionApp/DemoSample/local.settings.json @@ -0,0 +1,7 @@ +{ + "IsEncrypted": false, + "Values": { + "AzureWebJobsStorage": "", + "FUNCTIONS_WORKER_RUNTIME": "python" + } +} \ No newline at end of file From 719d9ffdeeff43f2b8f17119f85be343f57bc18a Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:45:07 +0530 Subject: [PATCH 10/14] Create __init__.py --- FunctionApp/DemoSample/HttpTrigger1/__init__.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 FunctionApp/DemoSample/HttpTrigger1/__init__.py diff --git a/FunctionApp/DemoSample/HttpTrigger1/__init__.py b/FunctionApp/DemoSample/HttpTrigger1/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/FunctionApp/DemoSample/HttpTrigger1/__init__.py @@ -0,0 +1 @@ + From 691b070aa6ba31570b8478d223882a67103a8cdd Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:45:51 +0530 Subject: [PATCH 11/14] Add files via upload --- .../DemoSample/HttpTrigger1/function.json | 20 +++++++++++++++++++ .../DemoSample/HttpTrigger1/sample.dat | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 FunctionApp/DemoSample/HttpTrigger1/function.json create mode 100644 FunctionApp/DemoSample/HttpTrigger1/sample.dat diff --git a/FunctionApp/DemoSample/HttpTrigger1/function.json b/FunctionApp/DemoSample/HttpTrigger1/function.json new file mode 100644 index 0000000..4667f0a --- /dev/null +++ b/FunctionApp/DemoSample/HttpTrigger1/function.json @@ -0,0 +1,20 @@ +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + } + ] +} \ No newline at end of file diff --git a/FunctionApp/DemoSample/HttpTrigger1/sample.dat b/FunctionApp/DemoSample/HttpTrigger1/sample.dat new file mode 100644 index 0000000..2e60943 --- /dev/null +++ b/FunctionApp/DemoSample/HttpTrigger1/sample.dat @@ -0,0 +1,3 @@ +{ + "name": "Azure" +} \ No newline at end of file From c481bc7e5d2b158becad03281603245a090c165a Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:46:25 +0530 Subject: [PATCH 12/14] Delete FunctionApp/DemoSample/local.settings.json --- FunctionApp/DemoSample/local.settings.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 FunctionApp/DemoSample/local.settings.json diff --git a/FunctionApp/DemoSample/local.settings.json b/FunctionApp/DemoSample/local.settings.json deleted file mode 100644 index 4b4cfce..0000000 --- a/FunctionApp/DemoSample/local.settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "IsEncrypted": false, - "Values": { - "AzureWebJobsStorage": "", - "FUNCTIONS_WORKER_RUNTIME": "python" - } -} \ No newline at end of file From 121098fd2133bdd3e1aa71cbf295b59df05b3bf3 Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:47:03 +0530 Subject: [PATCH 13/14] Delete FunctionApp/DemoSample/HttpTrigger1/__init__.py --- FunctionApp/DemoSample/HttpTrigger1/__init__.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 FunctionApp/DemoSample/HttpTrigger1/__init__.py diff --git a/FunctionApp/DemoSample/HttpTrigger1/__init__.py b/FunctionApp/DemoSample/HttpTrigger1/__init__.py deleted file mode 100644 index 8b13789..0000000 --- a/FunctionApp/DemoSample/HttpTrigger1/__init__.py +++ /dev/null @@ -1 +0,0 @@ - From f78fcfe7bb2521ea4ce2ab7349664b5667d8589f Mon Sep 17 00:00:00 2001 From: krishanbhati <118170853+krishanbhati@users.noreply.github.com> Date: Wed, 1 May 2024 09:47:27 +0530 Subject: [PATCH 14/14] Add files via upload --- .../DemoSample/HttpTrigger1/__init__.py | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 FunctionApp/DemoSample/HttpTrigger1/__init__.py diff --git a/FunctionApp/DemoSample/HttpTrigger1/__init__.py b/FunctionApp/DemoSample/HttpTrigger1/__init__.py new file mode 100644 index 0000000..e352acd --- /dev/null +++ b/FunctionApp/DemoSample/HttpTrigger1/__init__.py @@ -0,0 +1,134 @@ +import logging +import azure.functions as func +from openai import AzureOpenAI +import os +from azure.ai.vision.imageanalysis import ImageAnalysisClient +from azure.ai.vision.imageanalysis.models import VisualFeatures +from azure.core.credentials import AzureKeyCredential +import re +import json +# from langchain.callbacks import get_openai_callback + +def preprocess_text(text): + return re.sub(r'\W+', ' ', text.lower()) + +def DocProcessor(image_url): + endpoint = "https://test-ocr-puc.cognitiveservices.azure.com/" + key = "d20dff6d7c094caeb6f86f7f7c126005" + + client = ImageAnalysisClient( + endpoint=endpoint, + credential=AzureKeyCredential(key) + ) + + visual_features = [ + VisualFeatures.TAGS, VisualFeatures.OBJECTS, VisualFeatures.CAPTION, + VisualFeatures.DENSE_CAPTIONS, VisualFeatures.READ, VisualFeatures.SMART_CROPS, VisualFeatures.PEOPLE, + ] + + result = client.analyze_from_url( + image_url=image_url, + visual_features=visual_features, + smart_crops_aspect_ratios=[0.9, 1.33], + gender_neutral_caption=True, + language="en" + ) + + descriptions_to_match = [] + + if result.caption is not None: + main_caption = result.caption.text + descriptions_to_match.append(main_caption) + + if result.dense_captions is not None: + for caption in result.dense_captions.list: + descriptions_to_match.append(caption.text) + + client = AzureOpenAI( + azure_endpoint="https://aisqlintegration.openai.azure.com/", + api_key="d912d0d7acee490ab6e6adc797abe8ff", + api_version="2024-02-15-preview" + ) + + # Predefined list of categories + categories = [ + "Abandoned Vehicle", "Accessibility", "Animal - Deceased", "Animal - Domestic", "Animal - General", + "Damaged Road", "Damaged Street Sign", "Dumped Rubbish", "Dumped Tyres", "Facility - General Request", + "Fallen Tree", "General - Abandoned Trolley", "General Request", "Graffiti - General", "Graffiti - Public Property", + "Graffiti - Signage", "Illegal Parking", "Litter", "Noise - Animal", "Noise - Construction", "Noise - General", + "Overgrown Vegetation", "Park - General Request", "Parking - Disabled", "Pavement - Damaged", "Pavement - General", + "Pest / Vermin", "Pit and Equipment - General", "Playground Equipment", "Poles and Signage - General", + "Pollution - General", "Pothole", "Public Toilet", "Request Bin Repair or Replacement", "Road Blockage", + "Road Signage", "Roads - General", "Rubbish and Bins - General", "Street Cleaning", "Street Gutters / Storm Water", + "Trees - General", "Vandalism - General", "Water Fountain" + ] + + prompt_messages = [] + + prompt_messages.append({"role": "system", "content": "You are an AI assistant. Only suggest categories from the following list based on the description:"}) + + prompt_messages.append({"role": "user", "content": main_caption}) + + for description in descriptions_to_match: + prompt_messages.append({"role": "user", "content": description}) + + # for category in categories: + prompt_messages.append({"role": "system", "content": f"Suggest one best suitable category strictly from the following list only based on the description: {categories}"}) + + # for category in categories: + # prompt_messages.append({"role": "system", "content": f"Based on MainCaption, DenseCaptions identify best suggested category Type using Enhanced Keyword Extraction, Contextual Analysis and Named Entity Recognition (NER)techniques.Provide suggested category strictly from the category only don't fabricate category on your own.: {category} . Provide answer only strictly."}) + + + completion = client.chat.completions.create( + model="sqlintegration", + messages=prompt_messages, + temperature=0, + max_tokens=1000, + top_p=0, + frequency_penalty=0, + presence_penalty=0, + stop=None + ) + + suggested_category = completion.choices[0].message.content + + # result_with_source = { + # 'main_caption': main_caption, + # 'dense_captions': list(descriptions_to_match), + # 'suggested_category': suggested_category + # } + # json_data = json.dumps(result_with_source) + # return json_data + input_cost=0.00003*completion.usage.prompt_tokens + output_cost=0.00006*completion.usage.completion_tokens + price= input_cost+output_cost + result_with_source = { + 'main_caption': main_caption, + 'dense_captions': list(descriptions_to_match), + 'suggested_category': suggested_category, + 'completion_token':completion.usage.completion_tokens, + 'total_token':completion.usage.total_tokens, + 'prompt_token': completion.usage.prompt_tokens, + 'total_cost': round(price,4) + } + json_data = json.dumps(result_with_source) + return json_data +def main(req: func.HttpRequest) -> func.HttpResponse: + logging.info('Python HTTP trigger function processed a request.') + + image_url = req.params.get('imageurl') + if not image_url: + try: + req_body = req.get_json() + except ValueError: + pass + else: + image_url = req_body.get('imageurl') + + if image_url: + return DocProcessor(image_url) + else: + return func.HttpResponse( + "Please provide an image URL in the query string or in the request body.", + status_code=400 + ) \ No newline at end of file