This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
def temp_model(date): | |
""" | |
Converts a date to a number. | |
Parameters: | |
date (str): The date in 'YYYY-MM-DD' format. | |
Returns: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
from langchain.chat_models import ChatOpenAI | |
from run_chains import get_args, find_flights | |
from search_flights import pull_flights | |
from utils import SingletonToken, query_template | |
st.markdown( | |
""" | |
#### Prototype Built by [Data-Centric Solutions](https://www.data-centric-solutions.com/) | |
""", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = f'''Find me the {TypeofflightReuqest} journey from {originLocationCode} to {destinationLocationCode}. | |
Departing from {originLocationCode} on {departureDate} and returning from {destinationLocationCode} on {returnDate}. | |
respond with following structure delimited by quotation marks as an example for a journey with 4 legs, 2 for Outbound and 2 for Inbound flights: | |
## Journey ID: 1, Total (currency): | |
### travel_direction: Outbound, Journey Start: , Journey End: , total_duration(hrs): | |
**leg_id:1** | |
- Departure Time: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This module provides the data transformation function | |
""" | |
import pandas as pd | |
import numpy as np | |
from utils import parse_duration | |
def transform_data(response_flights_data, response_airline_lookup_data, originLocationCode, destinationLocationCode): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This module provides functionality to load data into a | |
sqlite database stored in memory | |
""" | |
from sqlalchemy import create_engine | |
import pandas as pd | |
from langchain import SQLDatabase | |
def load_data(journey_pricing, flights): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This module provides utility functions | |
""" | |
import yaml | |
import os | |
from dateutil.relativedelta import relativedelta | |
import re | |
def read_config(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run SQLDatabase chain | |
def find_flights(query, llm, db): | |
""" | |
Executes a search for flights using a language model and a SQL database toolkit. | |
Parameters: | |
query (str): The query to be executed, typically a natural language description of the flights to find. | |
llm (LanguageModel): The language model used to process the query and generate SQL commands. | |
db (Database): The database object where the flight data is stored and from which data will be retrieved. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine | |
import pandas as pd | |
from langchain import SQLDatabase | |
def load_data(journey_pricing, flights): | |
""" | |
Loads flight and journey pricing data into an in-memory SQLite database. | |
This function creates an in-memory SQLite database, loads flight and journey pricing data | |
into this database, and returns an SQLDatabase object that serves as the interface to this database. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from amadeus import Client, ResponseError | |
from create_database import load_data | |
from data_transformation import transform_data | |
from utils import read_config | |
import os | |
def pull_flights(originLocationCode, destinationLocationCode, departureDate, returnDate, num_adults): | |
""" | |
Searches for flights using the Amadeus API and returns structured data. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import openai | |
def get_args(query_user, OPENAI_KEY): | |
""" | |
Extracts necessary parameters for flight search from user query using OpenAI API. | |
This function takes a user query and an OpenAI key as inputs, sends the user query to | |
OpenAI API to extract necessary parameters including the number of adults, departure date, | |
return date, destination location code, and origin location code for flight search. |