TRIPEO commited on
Commit
c355d60
·
verified ·
1 Parent(s): ea03d9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -5,6 +5,9 @@ import streamlit as st
5
  import pandas as pd
6
  import openai
7
  import os
 
 
 
8
 
9
  # Hotelbeds API credentials
10
  hotelbeds_api_key = "95ce3e45a02fc6fd9720ecc013a6f674"
@@ -20,16 +23,17 @@ def generate_signature():
20
  signature = hashlib.sha256(assemble.encode()).hexdigest()
21
  return signature
22
 
23
- # Function to get geo-coordinates from a location name using OpenAI API
24
  def get_coordinates(location_name):
25
- response = openai.ChatCompletion.create(
26
- model="gpt-3.5-turbo",
27
- messages=[
28
- {"role": "system", "content": "You are a helpful assistant."},
29
- {"role": "user", "content": f"Provide the latitude and longitude for {location_name}."}
30
- ]
31
  )
32
- result = response.choices[0].message['content'].strip()
 
 
 
 
33
  coordinates = result.split(",")
34
  return float(coordinates[0]), float(coordinates[1])
35
 
 
5
  import pandas as pd
6
  import openai
7
  import os
8
+ from langchain.llms import OpenAI
9
+ from langchain.chains import LLMChain
10
+ from langchain.prompts import PromptTemplate
11
 
12
  # Hotelbeds API credentials
13
  hotelbeds_api_key = "95ce3e45a02fc6fd9720ecc013a6f674"
 
23
  signature = hashlib.sha256(assemble.encode()).hexdigest()
24
  return signature
25
 
26
+ # Function to get geo-coordinates from a location name using OpenAI API through Langchain
27
  def get_coordinates(location_name):
28
+ prompt_template = PromptTemplate(
29
+ input_variables=["location"],
30
+ template="Provide the latitude and longitude for {location}."
 
 
 
31
  )
32
+
33
+ llm = OpenAI(model_name="gpt-4", openai_api_key=openai.api_key)
34
+ chain = LLMChain(llm=llm, prompt=prompt_template)
35
+
36
+ result = chain.run(location_name).strip()
37
  coordinates = result.split(",")
38
  return float(coordinates[0]), float(coordinates[1])
39