Skip to content

Commit

Permalink
Merge pull request #5 from Emerald33/main
Browse files Browse the repository at this point in the history
Frontend and backend
  • Loading branch information
henrii1 authored Mar 26, 2024
2 parents 25814e4 + 3bc3d1d commit aded7bc
Show file tree
Hide file tree
Showing 25 changed files with 807 additions and 119 deletions.
102 changes: 102 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from flask import Flask, render_template, jsonify, request
from utils import api_keys, uploaded_files
from llamaindex import main
from langchain_folder import agent
from crewai_local import trip_crew

app = Flask(__name__)

path_to_directory=[]
api_key_dict = {}

@app.route("/")
def welcome_page():
return render_template('home.html')

@app.route('/agents/file_api_key')
def api():
return render_template('file_apikey.html')

@app.route('/agents/langchain')
def langchain_main():
return render_template('langchain.html')

@app.route('/agents/llamaindex')
def llamaindex_main():
return render_template('llamaindex.html')

@app.route('/agents/crewai')
def crewai_main():
return render_template('crewai.html')


@app.route("/agents/file_api_key", methods = ['post'])
def upload_api_page():
openai_api_key = request.form.get('openai_api_key')
serper_api_key = request.form.get('serper_api_key')
browserless_api_key = request.form.get('browserless_api_key')

file_one = request.files.get('file_one')
file_two = request.files.get('file_two')

files = uploaded_files(file_one, file_two)
path_to_directory.extend(files)

keys = api_keys(openai_api_key, serper_api_key, browserless_api_key)

for k, v in keys.items():
api_key_dict[k]=v

return render_template('api_thankyou.html')


@app.route("/agents/langchain", methods = ['post'])
def langchain_page():
data = request.form
model = agent.langchain_agent(api_key_dict['OPENAI_API_KEY'],
api_key_dict['SERPER_API_KEY'],
path_to_directory[1],
path_to_directory[2])
response = model.generate_langchain(data['text_input'])

return render_template('langchain_result.html',
generated = response)


@app.route("/agents/llamaindex", methods=['post'])
def llama_index_page():
data = request.form
model = main.generate_llamaindex(data['text_input'],
path_to_directory[0],
api_key_dict["OPENAI_API_KEY"])

return render_template('llamaindex_result.html',
generated = model)


@app.route("/agents/crewai", methods=['post'])
def crewai_page():
data = request.form
model = trip_crew.TripCrew(data['location'],
data['cities'],
data['date_range'],
data['interests'],
api_key_dict['OPENAI_API_KEY'])

response = model.run()

return render_template('crewai_result.html',
generated = response)











if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
Empty file removed crewai_local/main.py
Empty file.
10 changes: 3 additions & 7 deletions crewai_local/trip_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from langchain_community.chat_models import ChatOllama
from langchain_openai.chat_models import ChatOpenAI

from tools.browser_tools import BrowserTools
from tools.calculator_tools import CalculatorTools
from tools.search_tools import SearchTools
#from langchain_local.tools import serper_tool
from crewai_local.tools.browser_tools import BrowserTools
from crewai_local.tools.calculator_tools import CalculatorTools
from crewai_local.tools.search_tools import SearchTools

from dotenv import load_dotenv
load_dotenv()
Expand All @@ -30,7 +29,6 @@ def city_selection_agent(self):
tools = [
SearchTools.search_internet,
#BrowserTools.scrape_and_summarize_website,
#serper_tool.serper_tool
],
verbose=False,
allow_delegation=True,
Expand All @@ -46,7 +44,6 @@ def local_expert(self):
tools = [
SearchTools.search_internet,
#BrowserTools.scrape_and_summarize_website,
#serper_tool.serper_tool
],
verbose=False,
allow_delegation=True,
Expand All @@ -61,7 +58,6 @@ def travel_concierge(self):
tools=[
SearchTools.search_internet,
#BrowserTools.scrape_and_summarize_website,
#serper_tool.serper_tool,
CalculatorTools.calculate
],
allow_delegation=True,
Expand Down
10 changes: 5 additions & 5 deletions crewai_local/trip_crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from textwrap import dedent
from langchain_openai.chat_models import ChatOpenAI
from langchain_community.chat_models import ChatOllama
from trip_agents import TripAgents
from trip_task import TripTasks
from crewai_local.trip_agents import TripAgents
from crewai_local.trip_task import TripTasks

from dotenv import load_dotenv
load_dotenv()
Expand All @@ -14,14 +14,14 @@

class TripCrew:

def __init__(self, origin, cities, date_range, interests):
def __init__(self, origin, cities, date_range, interests, openai_api_key):

self.origin = origin
self.cities = cities
self.date_range = date_range
self.interests = interests
self.mistral = ChatOllama(model="mistral")
self.openai = ChatOpenAI(api_key=api_key, temperature=0)
self.openai = ChatOpenAI(api_key=openai_api_key, temperature=0)

def run(self):
agents = TripAgents()
Expand Down Expand Up @@ -59,7 +59,7 @@ def run(self):
crew = Crew(
agents=[city_selector_agent, local_expert_agent, travel_concierge_agent],
tasks=[identify_task, gather_task, plan_task],
process= Process.hierarchical,
process= Process.sequential,
manager_llm=self.openai
)

Expand Down
Loading

0 comments on commit aded7bc

Please sign in to comment.