mirror of
https://github.com/System-End/self-learning-ai-website.git
synced 2026-04-19 21:05:09 +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
|
from textblob import TextBlob
|
||||||
import openai
|
import openai
|
||||||
import os
|
import os
|
||||||
import logging
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# Set up OpenAI API key
|
# Set up OpenAI API key
|
||||||
openai.api_key = os.getenv('OPENAI_API_KEY')
|
openai.api_key = os.getenv('OPENAI_API_KEY')
|
||||||
|
|
||||||
# Configure logging
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
|
|
||||||
# Route to handle AI chat responses
|
# Route to handle AI chat responses
|
||||||
@app.route('/chat', methods=['POST'])
|
@app.route('/chat', methods=['POST'])
|
||||||
def chat():
|
def chat():
|
||||||
logging.info('Received chat request')
|
|
||||||
data = request.json
|
data = request.json
|
||||||
logging.debug(f'Received data: {data}')
|
|
||||||
prompt = data.get('prompt')
|
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(
|
response = openai.Completion.create(
|
||||||
engine="text-davinci-003",
|
engine="gpt-4o-2024-05-13",
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
max_tokens=300
|
max_tokens=300
|
||||||
)
|
)
|
||||||
|
|
@ -34,7 +25,6 @@ def chat():
|
||||||
# Route to scrape content from teamparadise1165.com
|
# Route to scrape content from teamparadise1165.com
|
||||||
@app.route('/scrape', methods=['GET'])
|
@app.route('/scrape', methods=['GET'])
|
||||||
def scrape():
|
def scrape():
|
||||||
logging.info('Received scrape request')
|
|
||||||
url = 'https://teamparadise1165.com'
|
url = 'https://teamparadise1165.com'
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
|
|
@ -42,7 +32,6 @@ def scrape():
|
||||||
content = soup.prettify()
|
content = soup.prettify()
|
||||||
return content
|
return content
|
||||||
else:
|
else:
|
||||||
logging.error(f'Failed to retrieve content: {response.status_code}')
|
|
||||||
return 'Failed to retrieve content', 500
|
return 'Failed to retrieve content', 500
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue