Handle chat interactions with the RAG system. This endpoint processes the user's prompt, retrieves relevant documents, and returns the assistant's reply along with conversation history. Returns: JSON response containing the assistant's reply, history, documents, and other
()
| 73 | question = json_data.get('question') |
| 74 | |
| 75 | (response, _) = raghelper.llm.generate_response( |
| 76 | None, |
| 77 | f"Write a succinct title (few words) for a chat that has the question: {question}\n\nYou NEVER give explanations, only the title and you are forced to always start and end with an emoji (two distinct ones!). You also stick to the language of the question.", |
| 78 | [] |
| 79 | ) |
| 80 | logger.info(f"Title for question {question}: {response}") |
| 81 | |
| 82 | return jsonify({"title": response}), 200 |
| 83 | |
| 84 | @app.route("/chat", methods=['POST']) |
| 85 | def chat(): |
| 86 | """ |
| 87 | Handle chat interactions with the RAG system. |
| 88 | |
| 89 | This endpoint processes the user's prompt, retrieves relevant documents, |
| 90 | and returns the assistant's reply along with conversation history. |
| 91 | |
| 92 | Returns: |
| 93 | JSON response containing the assistant's reply, history, documents, and other metadata. |
| 94 | """ |
| 95 | json_data = request.get_json() |
| 96 | prompt = json_data.get('prompt') |
| 97 | history = json_data.get('history', []) |
| 98 | original_docs = json_data.get('docs', []) |
| 99 | datasets = json_data.get('datasets', []) |
| 100 | docs = original_docs |
| 101 | |
| 102 | # Get the LLM response |
| 103 | (response, documents, fetched_new_documents, rewritten, new_history, provenance_scores) = raghelper.handle_user_interaction(prompt, history, datasets) |
| 104 | if not fetched_new_documents: |
| 105 | documents = docs |
| 106 | |
| 107 | response_dict = { |
| 108 | "reply": response, |
| 109 | "history": new_history, |
| 110 | "documents": documents, |
| 111 | "rewritten": rewritten, |
nothing calls this directly
no test coverage detected