-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor code into app and utils script
- Loading branch information
1 parent
8bfadd2
commit 5b91680
Showing
3 changed files
with
60 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pandas as pd | ||
import os | ||
import openai | ||
from sqlalchemy.engine import create_engine | ||
from pathlib import Path | ||
|
||
class Prompter: | ||
def __init__(self, api_key, gpt_model): | ||
if not api_key: | ||
raise Exception("Please provide the OpenAI API key") | ||
|
||
|
||
openai.api_key = os.environ.get("OPENAI_API_KEY") | ||
|
||
self.gpt_model = gpt_model | ||
|
||
def prompt_model_return(self, messages: list): | ||
response = openai.ChatCompletion.create(model=self.gpt_model, | ||
messages=messages, | ||
temperature=0.2) | ||
return response["choices"][0]["message"]["content"] | ||
|
||
def data_cleaner(df): | ||
|
||
|
||
# Replace the characters '.', '/', '(' and ')'with '_per_' all entries | ||
df.columns = df.columns.str.replace('.', '_') | ||
df.columns = df.columns.str.replace('/', '_per_') | ||
df.columns = df.columns.str.replace('(', '_') | ||
df.columns = df.columns.str.replace(')', '_') | ||
|
||
# drop column hybrid_in_fuel hybrid_in_electric aggregate_levels vehicle_type_cat | ||
df = df.drop(['hybrid_in_fuel', 'hybrid_in_electric', 'aggregate_levels','transmission_','fuel_type'], axis=1) | ||
|
||
return df | ||
|
||
def init_database(df): | ||
# Set up engine | ||
engine = create_engine("sqlite://") | ||
df.to_sql("vehicleDB", engine) | ||
|
||
return engine | ||
|