Skip to content

Commit

Permalink
Debug comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alemalvarez committed Apr 1, 2024
1 parent bedbb9d commit 6533a64
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 60 deletions.
28 changes: 24 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import logging
from flask import Flask, request, jsonify, Response, send_from_directory
from openai import OpenAI
import datetime
import os
app= Flask(__name__, static_folder='build', static_url_path='/')

# Configure logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

app = Flask(__name__, static_folder='build', static_url_path='/')

# Load OpenAI API key from environment variable
# openai_api_key = os.getenv('OPENAI_API_KEY')
# if not openai_api_key:git
# if not openai_api_key:
# raise ValueError('Your OpenAI API key is not detected in your environment variables. Please check.')

# Initialize OpenAI client
openai_client = OpenAI(organization="org-R588VtVPiLayZlPfc2F0DyAI")

@app.route('/')
def index():
return send_from_directory(app.static_folder, 'index.html')
logging.info('Received request for index route')
return send_from_directory(app.static_folder, 'index.html')

@app.route('/refine/', methods=['POST', 'GET'])
def refine():
logging.info('Received request for /refine route')
data = request.get_json()
logging.debug(f'Received data: {data}')

details = data.get('details', '')
project = data.get('project', '')
Expand All @@ -38,13 +46,15 @@ def refine():
continue # Skip this subtask
else:
prompt = f"This subtask needs work: \"{subtask}\". This is what I feel about it: {task_status}. fix it."
logging.info('Sending completion request to OpenAI API')
completion = openai_client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": instructions},
{"role": "user", "content": prompt}
]
)
logging.debug(f'Received response from OpenAI API: {completion.choices[0].message.content}')
refined_subtasks.append(completion.choices[0].message.content)

response_data = {
Expand All @@ -53,11 +63,14 @@ def refine():
'subtasks': refined_subtasks
}

logging.info('Returning response with refined subtasks')
return jsonify(response_data), 200

@app.route('/response/', methods=['POST'])
def action():
logging.info('Received POST request for /response route')
data = request.get_json()
logging.debug(f'Received data: {data}')

project = data['project']
details = data['details']
Expand All @@ -67,13 +80,15 @@ def action():
prompt = f"You will break down this task: {project} into 10 small subtasks, with the following considerations: {details}"

# Request completion from OpenAI API
logging.info('Sending completion request to OpenAI API')
completion = openai_client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": instructions},
{"role": "user", "content": prompt}
]
)
logging.debug(f'Received response from OpenAI API: {completion.choices[0].message.content}')
response = completion.choices[0].message.content

# Parse response into a list of subtasks
Expand All @@ -86,12 +101,15 @@ def action():
'subtasks': subtasks
}

logging.info('Returning response with subtasks')
return jsonify(context), 200

@app.route('/save_to_ical/', methods=['POST'])
def save_to_ical():
try:
logging.info('Received POST request for /save_to_ical route')
data = request.get_json()
logging.debug(f'Received data: {data}')
project = data['project']
details = data['details']
subtasks = data['subtasks']
Expand Down Expand Up @@ -120,9 +138,11 @@ def save_to_ical():
response = Response(ical_content, mimetype='text/calendar')
response.headers.set('Content-Disposition', 'attachment', filename='tasks.ics')

logging.info('Returning iCal file response')
return response
except Exception as e:
logging.error(f'Error occurred: {e}')
return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
app.run()
app.run()
102 changes: 46 additions & 56 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ function App() {
// Backend Function: Handle what happens when a user submits their input.
const handleSubmit = async (e) => {
e.preventDefault();
console.log('Submitting form...');

try {
console.log('Submitting form...');

const response = await fetch('https://chunkify.azurewebsites.net/response', {
console.log('Sending POST request to /response');
const response = await fetch('/response', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -60,6 +60,7 @@ function App() {
console.log('Response received:', response);

if (!response.ok) {
console.error('Network response was not ok');
throw new Error('Network response was not ok');
}

Expand All @@ -75,9 +76,8 @@ function App() {
// Backend Function: Handle what happens when a user clicks the Get Started button.
const handleGetRequest = async () => {
try {
console.log('Sending GET request...');

const response = await fetch('https://chunkify.azurewebsites.net/response');
console.log('Sending GET request to /response');
const response = await fetch('/response');
console.log('Response received:', response);

const data = await response.json();
Expand All @@ -90,11 +90,13 @@ function App() {

// Function: Handle what happens when a user submits their input.
const handleInputSubmit = () => {
console.log('Handling input submit');
setOutputData(['Output 1', 'Output 2', 'Output 3']); // Pretend processing
};

// Function: Handle what happens when a user clicks the Get Started button.
const handleGetStartedClick = () => {
console.log('Handling Get Started click');
setIsAnimating(true); // Start the animation
setTimeout(() => {
setShowMainPage(true); // Switch to the main page after the animation ends
Expand All @@ -104,7 +106,10 @@ function App() {

// Function: Listen for the Enter key press to submit the input.
const handleKeyPress = (e) => {
if (e.key === 'Enter') handleInputSubmit();
if (e.key === 'Enter') {
console.log('Enter key pressed');
handleInputSubmit();
}
};

// Main Render
Expand All @@ -124,55 +129,40 @@ function App() {
) : (
// Main page content
<div className={`main-page-wrapper animated ${showMainPage && !isAnimating ? 'slide-in-right-fade-in' : ''}`}>
{/* <input
type="text"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder="Enter task here"
onKeyPress={handleKeyPress}
/>
{outputData.length > 0 && (
<div className="ai-popup-container">
<h2>Break down into these tasks?</h2>
<ol>
{outputData.map((item, index) => <li key={index}>{item}</li>)}
</ol>
<form onSubmit={handleSubmit}>
{/*<!-- Project --> */}
<label htmlFor="project">Project:</label>
<input
type="text"
id="project"
value={project}
onChange={(e) => setProject(e.target.value)}
placeholder="What you want to do"
onKeyPress={handleKeyPress}
/>
{/*<!-- Details --> */}
<label htmlFor="details">Details:</label>
<input
type="text"
id="details"
value={details}
placeholder="Additional details"
onChange={(e) => setDetails(e.target.value)}
/>
<button type="submit">Submit</button>
</form>
<button onClick={handleGetRequest}>Fetch Data</button>
{subtasks.length > 0 && (
<div>
<h2>Subtasks:</h2>
<ul>
{subtasks.map((subtask, index) => (
<li key={index}>{subtask}</li>
))}
</ul>
</div>
)} */}
<form onSubmit={handleSubmit}>
{/*<!-- Project --> */}
<label htmlFor="project">Project:</label>
<input
type="text"
id="project"
value={project}
onChange={(e) => setProject(e.target.value)}
placeholder="What you want to do"
onKeyPress={handleKeyPress}
/>
{/*<!-- Details --> */}
<label htmlFor="details">Details:</label>
<input
type="text"
id="details"
value={details}
placeholder="Additional details"
onChange={(e) => setDetails(e.target.value)}
/>
<button type="submit">Submit</button>
</form>
<button onClick={handleGetRequest}>Fetch Data</button>
{subtasks.length > 0 && (
<div>
<h2>Subtasks:</h2>
<ul>
{subtasks.map((subtask, index) => (
<li key={index}>{subtask}</li>
))}
</ul>
</div>
)}
{error && <p>{error}</p>}
)}
{error && <p>{error}</p>}
</div>
)}
</div>
Expand All @@ -182,4 +172,4 @@ function App() {
);
}

export default App;
export default App;

0 comments on commit 6533a64

Please sign in to comment.