mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
streaming experiments
This commit is contained in:
@@ -9,7 +9,7 @@ import dotenv
|
||||
import requests
|
||||
from celery import Celery
|
||||
from celery.result import AsyncResult
|
||||
from flask import Flask, request, render_template, send_from_directory, jsonify
|
||||
from flask import Flask, request, render_template, send_from_directory, jsonify, Response
|
||||
from langchain import FAISS
|
||||
from langchain import VectorDBQA, HuggingFaceHub, Cohere, OpenAI
|
||||
from langchain.chains import LLMChain, ConversationalRetrievalChain
|
||||
@@ -120,6 +120,21 @@ def home():
|
||||
embeddings_choice=settings.EMBEDDINGS_NAME)
|
||||
|
||||
|
||||
def complete_stream(input):
|
||||
import time
|
||||
for i in range(10):
|
||||
data = json.dumps({"answer": i})
|
||||
#data = {"answer": str(i)}
|
||||
yield f"data: {data}\n\n"
|
||||
time.sleep(0.05)
|
||||
# send data.type = "end" to indicate that the stream has ended as json
|
||||
data = json.dumps({"type": "end"})
|
||||
yield f"data: {data}\n\n"
|
||||
@app.route("/stream", methods=['POST', 'GET'])
|
||||
def stream():
|
||||
return Response(complete_stream("hi"), mimetype='text/event-stream')
|
||||
|
||||
|
||||
@app.route("/api/answer", methods=["POST"])
|
||||
def api_answer():
|
||||
data = request.get_json()
|
||||
|
||||
Reference in New Issue
Block a user