-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserv.py
More file actions
97 lines (71 loc) · 2.59 KB
/
serv.py
File metadata and controls
97 lines (71 loc) · 2.59 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from flask import Flask, request, jsonify
from flask_cors import CORS
from graphi import run_rag_agent
from todo import get_todo
from question import generate_question, check_answer, clear_doubt
from flask import Flask, jsonify, request
from uagents import Model
from uagents.query import query
from uagents.envelope import Envelope
import asyncio
# from custom_input_agent import PDFInputResponse
import json
import os
from dotenv import load_dotenv
load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
from langchain.text_splitter import CharacterTextSplitter
from langchain_community.document_loaders import JSONLoader
import json
from pathlib import Path
from pprint import pprint
from langchain_openai import OpenAIEmbeddings
from langchain_community.document_loaders import PyPDFLoader
embeddings = OpenAIEmbeddings()
app = Flask(__name__)
CORS(app)
messages = []
@app.route('/query', methods=['POST'])
def rag_endpoint():
data = request.json
if 'question' not in data:
return jsonify({"error": "Missing 'question' in request body"}), 400
result = run_rag_agent(data['question'])
messages.append(data['question'])
messages.append(result['answer'])
return jsonify(messages)
@app.route('/generate_question', methods=['POST'])
def api_generate_question():
data = request.json
query = data.get('query')
course = data.get('course')
if not query or not course:
return jsonify({"error": "Missing query or course"}), 400
result = generate_question(query, course)
return jsonify(result)
@app.route('/check_answer', methods=['POST'])
def api_check_answer():
data = request.json
question = data.get('question')
sample = data.get('sample')
answer = data.get('answer')
if not question or not sample or not answer:
return jsonify({"error": "Missing question, sample, or answer"}), 400
result = check_answer(question, sample, answer)
return jsonify({"result": result})
@app.route('/clear_doubt', methods=['POST'])
def api_clear_doubt():
data = request.json
conversation = data.get('conversation')
question = data.get('question')
course = data.get('course')
if not conversation or not question or not course:
return jsonify({"error": "Missing conversation, question, or course"}), 400
result = clear_doubt(conversation, question, course)
return jsonify({"result": result})
@app.route('/todo', methods=['GET'])
def todo_endpoint():
todo_list = get_todo()
return jsonify(todo_list)
if __name__ == '__main__':
app.run(debug=True, port=8000)