Merge pull request 'general_fixes' (#25) from general_fixes into main

Reviewed-on: AI_team/generic-RAG-demo#25
This commit is contained in:
rubenl 2025-04-15 09:01:24 +02:00
commit 59ab43d31e
3 changed files with 12 additions and 14 deletions

View File

@ -5,15 +5,16 @@ import os
from pathlib import Path from pathlib import Path
import chainlit as cl import chainlit as cl
from backend.models import ChatBackend, EmbeddingBackend, get_chat_model, get_embedding_model
from chainlit.cli import run_chainlit from chainlit.cli import run_chainlit
from graphs.cond_ret_gen import CondRetGenLangGraph
from graphs.ret_gen import RetGenLangGraph
from langchain_chroma import Chroma from langchain_chroma import Chroma
from parsers.parser import add_pdf_files, add_urls
logging.basicConfig(level=logging.DEBUG) from generic_rag.backend.models import ChatBackend, EmbeddingBackend, get_chat_model, get_embedding_model
logger = logging.getLogger(__name__) from generic_rag.graphs.cond_ret_gen import CondRetGenLangGraph
from generic_rag.graphs.ret_gen import RetGenLangGraph
from generic_rag.parsers.parser import add_pdf_files, add_urls
logger = logging.getLogger("sogeti-rag")
logger.setLevel(logging.DEBUG)
system_prompt = ( system_prompt = (
"You are an assistant for question-answering tasks. " "You are an assistant for question-answering tasks. "
@ -126,12 +127,9 @@ async def add_sources(chainlit_response: cl.Message, pdf_sources: dict, web_sour
if len(pdf_sources) > 0: if len(pdf_sources) > 0:
await chainlit_response.stream_token("\n\nThe following PDF source were consulted:\n") await chainlit_response.stream_token("\n\nThe following PDF source were consulted:\n")
for source, page_numbers in pdf_sources.items(): for source, page_numbers in pdf_sources.items():
page_numbers = list(page_numbers) filename = Path(source).name
page_numbers.sort() await chainlit_response.stream_token(f"- {filename} on page(s): {sorted(page_numbers)}\n")
# display="side" seems to be not supported by chainlit for PDF's, so we use "inline" instead. chainlit_response.elements.append(cl.Pdf(name=filename, display="side", path=source, page=sorted(page_numbers)[0]))
chainlit_response.elements.append(cl.Pdf(name="pdf", display="inline", path=source, page=page_numbers[0]))
await chainlit_response.update()
await chainlit_response.stream_token(f"- '{source}' on page(s): {page_numbers}\n")
if len(web_sources) > 0: if len(web_sources) > 0:
await chainlit_response.stream_token("\n\nThe following web sources were consulted:\n") await chainlit_response.stream_token("\n\nThe following web sources were consulted:\n")

View File

@ -16,7 +16,7 @@ from langgraph.graph import END, MessagesState, StateGraph
from langgraph.prebuilt import InjectedStore, ToolNode, tools_condition from langgraph.prebuilt import InjectedStore, ToolNode, tools_condition
from typing_extensions import Annotated from typing_extensions import Annotated
logger = logging.getLogger(__name__) logger = logging.getLogger("sogeti-rag")
class CondRetGenLangGraph: class CondRetGenLangGraph:
def __init__( def __init__(

View File

@ -12,7 +12,7 @@ from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph import END, START, StateGraph from langgraph.graph import END, START, StateGraph
from typing_extensions import List, TypedDict from typing_extensions import List, TypedDict
logger = logging.getLogger(__name__) logger = logging.getLogger("sogeti-rag")
class State(TypedDict): class State(TypedDict):