proof of concept - horrible code

This commit is contained in:
2023-10-12 11:33:51 +02:00
parent 20b5555b2b
commit 795cc64097
3 changed files with 104 additions and 0 deletions

43
science.py Normal file
View File

@@ -0,0 +1,43 @@
import logging
import sys
from cybrex.cybrex_ai import CybrexAI
from quart import Quart, request, jsonify
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
app = Quart(__name__)
@app.route('/ask')
async def ask():
cybrex = CybrexAI()
query = request.args.get('query')
if not query:
return {'error': 'Please provide a query parameter'}, 400
# Only await if cybrex.start() needs to be called for each request
# Otherwise, consider initializing cybrex outside the route
await cybrex.start()
# Assuming chat_science is an asynchronous method, it should be awaited
answer = await cybrex.chat_science(query=query, n_chunks=4, n_documents=10)
payload = format_cybrex_response(answer)
return payload
def format_cybrex_response(answer):
# Extract the answer
chunks = answer.chunks
reply = answer.answer
formatted_response = "Short answer:\n" + reply + "\n\nExcerpts from articles:\n"
# Extract and format each chunk
for chunk in chunks:
formatted_response += "\n" + chunk.title + "\n" + chunk.text + "\n"
return formatted_response
if __name__ == '__main__':
app.run(debug=True, port=6000)