added OpenAI support and markdown in the chat window
This commit is contained in:
@@ -10,10 +10,18 @@ from pydantic import BaseModel
|
||||
|
||||
from local_rag import LocalRAG
|
||||
|
||||
# Initialize RAG once at startup
|
||||
VECTORSTORE_PATH = "./vectorstore"
|
||||
# LLM provider: "ollama" or "openai"
|
||||
LLM_PROVIDER = "openai"
|
||||
OLLAMA_MODEL = "gpt-oss:20b"
|
||||
rag = LocalRAG(vectorstore_path=VECTORSTORE_PATH, ollama_model=OLLAMA_MODEL)
|
||||
OPENAI_MODEL = "gpt-5.2"
|
||||
|
||||
VECTORSTORE_PATH = "./vectorstore"
|
||||
rag = LocalRAG(
|
||||
vectorstore_path=VECTORSTORE_PATH,
|
||||
llm_provider=LLM_PROVIDER,
|
||||
ollama_model=OLLAMA_MODEL,
|
||||
openai_model=OPENAI_MODEL,
|
||||
)
|
||||
|
||||
app = FastAPI(title="Local RAG Chat", version="1.0.0")
|
||||
|
||||
@@ -64,15 +72,16 @@ def chat(request: ChatRequest):
|
||||
answer = result["answer"]
|
||||
retrieved = result.get("retrieved", [])
|
||||
|
||||
# Server-side console trace: log retrieved chunks before LLM answer
|
||||
# Server-side console trace: shorter chunk logs + raw LLM response
|
||||
if retrieved:
|
||||
print(f"\n[RAG] Retrieved {len(retrieved)} chunk(s) for query: {request.message[:80]!r}")
|
||||
print(f"\n[RAG] Retrieved {len(retrieved)} chunk(s)")
|
||||
for i, chunk in enumerate(retrieved):
|
||||
content = chunk.get("content", "")
|
||||
preview = (content[:1000] + "...") if len(content) > 1000 else content
|
||||
print(f" [{i + 1}] source={chunk.get('source', '')} page={chunk.get('page')} | {preview!r}")
|
||||
preview = (content[:80] + "...") if len(content) > 80 else content
|
||||
print(f" [{i + 1}] {chunk.get('source', '')} p.{chunk.get('page', '?')} s={chunk.get('score')} | {preview!r}")
|
||||
else:
|
||||
print(f"\n[RAG] Retrieved 0 chunks for query: {request.message[:80]!r}")
|
||||
print(f"\n[RAG] Retrieved 0 chunks")
|
||||
print(f"[RAG] LLM response:\n{answer}")
|
||||
|
||||
return ChatResponse(answer=answer, retrieved=retrieved)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user