50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from django.shortcuts import render, redirect
|
|
from ai.local_ai_api import LocalAIApi
|
|
import json
|
|
|
|
def index(request):
|
|
context = {
|
|
"project_name": "ComplianceShield",
|
|
}
|
|
return render(request, "core/index.html", context)
|
|
|
|
def search(request):
|
|
if request.method == "POST":
|
|
query = request.POST.get("query", "")
|
|
if query:
|
|
response = LocalAIApi.create_response(
|
|
{
|
|
"input": [
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
{"role": "user", "content": query},
|
|
],
|
|
},
|
|
{
|
|
"poll_interval": 5, # seconds
|
|
"poll_timeout": 300, # seconds
|
|
},
|
|
)
|
|
|
|
if response.get("success"):
|
|
text = LocalAIApi.extract_text(response)
|
|
if not text:
|
|
decoded = LocalAIApi.decode_json_from_response(response)
|
|
text = json.dumps(decoded, ensure_ascii=False) if decoded else str(response.get("data", ""))
|
|
search_results = text
|
|
else:
|
|
search_results = "Error: Could not get a response from the AI."
|
|
|
|
context = {
|
|
"project_name": "ComplianceShield",
|
|
"search_results": search_results,
|
|
}
|
|
return render(request, "core/index.html", context)
|
|
|
|
return redirect("index")
|
|
|
|
def settings(request):
|
|
context = {
|
|
"project_name": "ComplianceShield",
|
|
}
|
|
return render(request, "core/settings.html", context)
|