1.0 Release

This commit is contained in:
2026-03-05 20:07:35 +00:00
parent e4a2dd7bf2
commit 58f20856fd
15 changed files with 1208 additions and 1002 deletions
+13 -17
View File
@@ -28,13 +28,12 @@ def retrieve_from_turso(embedded_question, k=5):
rows = cur.fetchall()
return rows
# --- DSPy Signature ---
class DnDContextQA(dspy.Signature):
f"{RETRIEVAL_CONFIG["retrieval_signature"]}"
f"{RETRIEVAL_CONFIG['retrieval_signature']}"
context = dspy.InputField(
desc="Relevant chunks and metadata from the campaign notes."
)
context = dspy.InputField(desc="Relevant chunks and metadata from the campaign notes.")
question = dspy.InputField()
answer = dspy.OutputField(desc="A detailed answer based on the notes, citing the source file.")
@@ -45,16 +44,14 @@ class DnDRAG(dspy.Module):
self.embeddings_model = LocalLMEmbeddings(
model=EMBEDDING_MODEL,
base_url=API_BASE,
batch_size=1, # we only send 1 question at a time.
)
# Tools exposed to the ReAct loop
self.tools = [
self.load_file
]
self.generate_answer = dspy.ReAct(signature=DnDContextQA,tools=self.tools)
batch_size=1, # we only send 1 question at a time.
)
# Tools exposed to the ReAct loop
self.tools = [self.load_file]
self.generate_answer = dspy.ReAct(signature=DnDContextQA, tools=self.tools)
def forward(self, question):
# TODO: Add step here to LLM Expand
# TODO: Add step here to LLM Expand
# given the current question, generate 3-5 distinct search queries.
# embed all the questions
embedded_question = self.embeddings_model._post_request(question)
@@ -66,13 +63,12 @@ class DnDRAG(dspy.Module):
for i, row in enumerate(results):
source = row[0] # file_path
synopsis = row[1] # synopsis
tags = row[2] # tags
tags = row[2] # tags
entities = row[3] # entities
content = row[4] # chunk_data
context_parts.append(f"""
--- Chunk {i+1} from {source} ---
--- Chunk {i + 1} from {source} ---
synopsis: {synopsis},
tags: {tags},
entities: {entities}
@@ -82,7 +78,7 @@ entities: {entities}
# print('Closest embedding hits')
# for part in context_parts:
# print(part)
context = "\n\n".join(context_parts)
prediction = self.generate_answer(context=context, question=question)
@@ -97,4 +93,4 @@ entities: {entities}
except Exception:
return None
else:
return None
return None