-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
65 lines (48 loc) · 2 KB
/
Copy pathserver.py
File metadata and controls
65 lines (48 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from flask import Flask, render_template, request, jsonify
import networkx as nx
from Intelligence_AI_V2 import CognitiveAgent
from openai import OpenAI
from os import environ as env
OPENAI_API_KEY = '' # Replace with your actual API key
client = OpenAI(api_key=OPENAI_API_KEY)
app = Flask(__name__)
app.static_folder = '/static'
app.secret_key = env.get("APP_SECRET_KEY")
openai_api_key = env.get("OPENAI_API")
# Placeholder function for simulating a ChatGPT response
def get_chatgpt_response(user_message):
try:
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "je veux que tu répondes à ce thème en citant un maximum tes sources via des liens" + user_message,
}
],
model="gpt-3.5-turbo",
)
print(chat_completion.choices[0].message.content)
return chat_completion.choices[0].message.content
except Exception as e:
return f"An error occurred: {str(e)}"
# Initialize your chatbot and graph
PATH = "Parle moi du regain de tensions entre la Corée du Nord et du Sud".replace(' ', '_')
G = nx.read_gml(f"{PATH}/{PATH}.gml")
agent = CognitiveAgent(data_path="Parle moi du regain de tensions entre la Corée du Nord et du Sud", api_key='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')
# Define your options here
@app.route("/", methods=['GET'])
def home():
return render_template("interface_user.html")
@app.route("/chat", methods=['POST'])
def chat():
data = request.json
user_message = data["message"]
# Get the response from your chatbot
chatbot_response = agent.search(user_message)
# Simulate a ChatGPT response
return jsonify({
"chatbot_response": chatbot_response,
})
app.debug = True
if __name__ == "__main__":
app.run(host="0.0.0.0", port=env.get("PORT", 3000))