Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ repos:
- id: check-toml
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/pre-commit/mirrors-pylint
rev: v2.7.4
hooks:
- id: pylint
args: ["--rcfile=.pylintrc"]
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ ignored-parents=
max-args=5

# Maximum number of attributes for a class (see R0902).
max-attributes=7
max-attributes=10

# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr=5
Expand Down
22 changes: 11 additions & 11 deletions chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Dict, List, Tuple
from uuid import uuid4

from langchain import hub
from langchain.chat_models import init_chat_model
from langchain_chroma import Chroma
from langchain_community.document_loaders import (
Expand All @@ -28,6 +29,10 @@ class KnowledgeBaseChatbot:
"""Chatbot class for setting up embeddings, vector store, llm, graph, and tools."""

def __init__(self):

print("pull rag template...")
self.prompt_template = hub.pull("andreaschandra/rag-prompt")

print("init_chat_model...")
self.llm = init_chat_model(
"claude-3-5-haiku-latest", model_provider="anthropic"
Expand Down Expand Up @@ -225,23 +230,18 @@ def generate(self, state: MessagesState) -> Dict:

# Format into prompt
docs_content = "\n\n".join(doc.content for doc in tool_messages)
system_message_content = (
"You are an assistant for question-answering tasks. "
"Use the following pieces of retrieved context to answer "
"the question. If you don't know the answer, say that you "
"don't know."
"Use tool calls to extract key points and summary from the retrieved documents."
"do not use any tool if it is not needed."
"\n\n"
f"{docs_content}"
)

# Retrieve latest question
conversation_messages = [
message
for message in state["messages"]
if message.type in ("human", "system")
or (message.type == "ai" and not message.tool_calls)
]
prompt = [SystemMessage(system_message_content)] + conversation_messages

prompt = self.prompt_template.invoke(
{"context": docs_content, "question": conversation_messages}
)

# Run
llm_with_tools = self.llm.bind_tools([PointSchema])
Expand Down