Skip to content

Commit

Permalink
address linting
Browse files Browse the repository at this point in the history
  • Loading branch information
kweinmeister committed Jun 18, 2024
1 parent 30f4dcc commit 8393c36
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions gemini/function-calling/function_calling_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""A Flask app that uses Vertex AI and Nominatim to get address coordinates.
This app takes an address as input and uses the Vertex AI Gemini model to
extract relevant location information. It then uses the Nominatim API to
retrieve the coordinates for the address.
"""

import json
import logging
import os
Expand Down Expand Up @@ -63,15 +70,17 @@


@app.route("/", methods=["GET", "POST"])
def get_coordinates():
def get_coordinates() -> str:
"""
Retrieves coordinates for a given address using the Vertex AI Generative AI API and the Nominatim API.
Retrieves coordinates for an address using Vertex AI and Nominatim APIs.
This function handles both GET and POST requests.
For POST requests, it retrieves the address from the request form and uses it to construct a prompt for the Vertex AI model.
It then extracts the arguments from the function call response and constructs a URL for the Nominatim API.
Finally, it retrieves the coordinates from the Nominatim API and returns them as a JSON object.
For GET requests, it simply renders the index.html template.
For POST requests, it retrieves the address from the request form and uses
it to construct a prompt for the Vertex AI model. It then extracts the
arguments from the function call response and constructs a URL for the
Nominatim API. Finally, it retrieves the coordinates from the Nominatim API
and returns them as a JSON object. For GET requests, it simply renders the
index.html template.
"""
if request.method == "GET":
return render_template("index.html")
Expand All @@ -88,7 +97,7 @@ def get_coordinates():
else:
url = "https://nominatim.openstreetmap.org/search?"
for i in x:
url += '{}="{}"&'.format(i, x[i])
url += f'{i}="{x[i]}&'
url += "format=json"

headers = {
Expand Down

0 comments on commit 8393c36

Please sign in to comment.