mirror of
https://github.com/System-End/self-learning-ai-website.git
synced 2026-04-19 15:28:20 +00:00
Update server.py
This commit is contained in:
parent
88e060840b
commit
fb8ae8ac86
1 changed files with 1 additions and 12 deletions
13
server.py
13
server.py
|
|
@ -4,28 +4,19 @@ import requests
|
|||
from textblob import TextBlob
|
||||
import openai
|
||||
import os
|
||||
import logging
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Set up OpenAI API key
|
||||
openai.api_key = os.getenv('OPENAI_API_KEY')
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
# Route to handle AI chat responses
|
||||
@app.route('/chat', methods=['POST'])
|
||||
def chat():
|
||||
logging.info('Received chat request')
|
||||
data = request.json
|
||||
logging.debug(f'Received data: {data}')
|
||||
prompt = data.get('prompt')
|
||||
if not prompt:
|
||||
logging.error('No prompt provided in the request')
|
||||
return jsonify({'error': 'No prompt provided'}), 400
|
||||
response = openai.Completion.create(
|
||||
engine="text-davinci-003",
|
||||
engine="gpt-4o-2024-05-13",
|
||||
prompt=prompt,
|
||||
max_tokens=300
|
||||
)
|
||||
|
|
@ -34,7 +25,6 @@ def chat():
|
|||
# Route to scrape content from teamparadise1165.com
|
||||
@app.route('/scrape', methods=['GET'])
|
||||
def scrape():
|
||||
logging.info('Received scrape request')
|
||||
url = 'https://teamparadise1165.com'
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
|
|
@ -42,7 +32,6 @@ def scrape():
|
|||
content = soup.prettify()
|
||||
return content
|
||||
else:
|
||||
logging.error(f'Failed to retrieve content: {response.status_code}')
|
||||
return 'Failed to retrieve content', 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue