langroid 0.39.2__tar.gz → 0.39.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langroid-0.39.2 → langroid-0.39.3}/PKG-INFO +1 -1
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/doc_chat_agent.py +4 -12
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/output/citations.py +31 -1
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/system.py +1 -5
- {langroid-0.39.2 → langroid-0.39.3}/langroid/vector_store/weaviatedb.py +25 -12
- {langroid-0.39.2 → langroid-0.39.3}/pyproject.toml +1 -1
- {langroid-0.39.2 → langroid-0.39.3}/.gitignore +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/LICENSE +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/README.md +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/base.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/batch.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/callbacks/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/callbacks/chainlit.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/chat_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/chat_document.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/openai_assistant.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/arangodb/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/arangodb/arangodb_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/arangodb/system_messages.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/arangodb/tools.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/arangodb/utils.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/lance_doc_chat_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/lance_rag/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/lance_tools.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/neo4j/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/neo4j/csv_kg_chat.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/neo4j/system_messages.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/neo4j/tools.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/relevance_extractor_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/retriever_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/sql/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/sql/sql_chat_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/sql/utils/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/sql/utils/system_message.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/sql/utils/tools.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/table_chat_agent.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/task.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tool_message.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/duckduckgo_search_tool.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/file_tools.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/google_search_tool.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/metaphor_search_tool.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/orchestration.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/recipient_tool.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/retrieval_tool.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/rewind_tool.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/tools/segment_extract_tool.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/agent/xml_tool_message.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/cachedb/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/cachedb/base.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/cachedb/momento_cachedb.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/cachedb/redis_cachedb.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/base.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/models.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/protoc/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/protoc/embeddings.proto +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/protoc/embeddings_pb2.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/embedding_models/remote_embeds.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/exceptions.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/azure_openai.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/base.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/config.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/mock_lm.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/model_info.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/openai_gpt.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/prompt_formatter/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/prompt_formatter/base.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/prompt_formatter/hf_formatter.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/utils.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/mytypes.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/agent_chats.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/code_parser.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/document_parser.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/para_sentence_split.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/parse_json.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/parser.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/pdf_utils.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/repo_loader.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/routing.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/search.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/spider.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/table_loader.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/url_loader.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/urls.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/utils.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/parsing/web_search.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/prompts/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/prompts/dialog.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/prompts/prompts_config.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/prompts/templates.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/py.typed +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/pydantic_v1/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/pydantic_v1/main.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/algorithms/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/algorithms/graph.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/configuration.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/constants.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/git_utils.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/globals.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/logging.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/object_registry.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/output/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/output/printing.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/output/status.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/pandas_utils.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/pydantic_utils.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/utils/types.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/vector_store/__init__.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/vector_store/base.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/vector_store/chromadb.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/vector_store/lancedb.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/vector_store/meilisearch.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/vector_store/momento.py +0 -0
- {langroid-0.39.2 → langroid-0.39.3}/langroid/vector_store/qdrantdb.py +0 -0
@@ -58,7 +58,7 @@ from langroid.utils.object_registry import ObjectRegistry
|
|
58
58
|
from langroid.utils.output import show_if_debug, status
|
59
59
|
from langroid.utils.output.citations import (
|
60
60
|
extract_markdown_references,
|
61
|
-
|
61
|
+
format_cited_references,
|
62
62
|
)
|
63
63
|
from langroid.utils.pydantic_utils import dataframe_to_documents, extract_fields
|
64
64
|
from langroid.vector_store.base import VectorStore, VectorStoreConfig
|
@@ -859,18 +859,10 @@ class DocChatAgent(ChatAgent):
|
|
859
859
|
final_answer = answer_doc.content.strip()
|
860
860
|
show_if_debug(final_answer, "SUMMARIZE_RESPONSE= ")
|
861
861
|
|
862
|
+
# extract references like [^2], [^3], etc. from the final answer
|
862
863
|
citations = extract_markdown_references(final_answer)
|
863
|
-
|
864
|
-
citations_str =
|
865
|
-
if len(citations) > 0:
|
866
|
-
# append [i] source, content for each citation
|
867
|
-
citations_str = "\n".join(
|
868
|
-
[
|
869
|
-
f"[^{c}] {passages[c-1].metadata.source}"
|
870
|
-
f"\n{format_footnote_text(passages[c-1].content)}"
|
871
|
-
for c in citations
|
872
|
-
]
|
873
|
-
)
|
864
|
+
# format the cited references as a string suitable for markdown footnote
|
865
|
+
citations_str = format_cited_references(citations, passages)
|
874
866
|
|
875
867
|
return ChatDocument(
|
876
868
|
content=final_answer, # does not contain citations
|
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
from typing import List
|
2
|
+
|
3
|
+
from langroid.mytypes import Document
|
4
|
+
|
5
|
+
|
6
|
+
def extract_markdown_references(md_string: str) -> List[int]:
|
2
7
|
"""
|
3
8
|
Extracts markdown references (e.g., [^1], [^2]) from a string and returns
|
4
9
|
them as a sorted list of integers.
|
@@ -59,3 +64,28 @@ def format_footnote_text(content: str, width: int = 0) -> str:
|
|
59
64
|
|
60
65
|
# Join them with newline so we preserve the paragraph/blank line structure
|
61
66
|
return "\n".join(output_lines)
|
67
|
+
|
68
|
+
|
69
|
+
def format_cited_references(citations: List[int], passages: list[Document]) -> str:
|
70
|
+
"""
|
71
|
+
Given a list of (integer) citations, and a list of passages, return a string
|
72
|
+
that can be added as a footer to the main text, to show sources cited.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
citations (list[int]): list of citations, presumably from main text
|
76
|
+
passages (list[Document]): list of passages (Document objects)
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
str: formatted string of citations for footnote in markdown
|
80
|
+
"""
|
81
|
+
citations_str = ""
|
82
|
+
if len(citations) > 0:
|
83
|
+
# append [i] source, content for each citation
|
84
|
+
citations_str = "\n".join(
|
85
|
+
[
|
86
|
+
f"[^{c}] {passages[c-1].metadata.source}"
|
87
|
+
f"\n{format_footnote_text(passages[c-1].content)}"
|
88
|
+
for c in citations
|
89
|
+
]
|
90
|
+
)
|
91
|
+
return citations_str
|
@@ -14,11 +14,7 @@ from typing import Any, Literal
|
|
14
14
|
|
15
15
|
logger = logging.getLogger(__name__)
|
16
16
|
|
17
|
-
DELETION_ALLOWED_PATHS = [
|
18
|
-
".qdrant",
|
19
|
-
".chroma",
|
20
|
-
".lancedb",
|
21
|
-
]
|
17
|
+
DELETION_ALLOWED_PATHS = [".qdrant", ".chroma", ".lancedb", ".weaviate"]
|
22
18
|
|
23
19
|
|
24
20
|
def pydantic_major_version() -> int:
|
@@ -32,6 +32,8 @@ class WeaviateDBConfig(VectorStoreConfig):
|
|
32
32
|
collection_name: str | None = "temp"
|
33
33
|
embedding: EmbeddingModelsConfig = OpenAIEmbeddingsConfig()
|
34
34
|
distance: str = VectorDistances.COSINE
|
35
|
+
cloud: bool = False
|
36
|
+
storage_path: str = ".weaviate_embedded/data"
|
35
37
|
|
36
38
|
|
37
39
|
class WeaviateDB(VectorStore):
|
@@ -39,19 +41,25 @@ class WeaviateDB(VectorStore):
|
|
39
41
|
super().__init__(config)
|
40
42
|
self.config: WeaviateDBConfig = config
|
41
43
|
load_dotenv()
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
raise ValueError(
|
46
|
-
"""WEAVIATE_API_KEY, WEAVIATE_API_URL env variable must be set to use
|
47
|
-
WeaviateDB in cloud mode. Please set these values
|
48
|
-
in your .env file.
|
49
|
-
"""
|
44
|
+
if not self.config.cloud:
|
45
|
+
self.client = weaviate.connect_to_embedded(
|
46
|
+
version="latest", persistence_data_path=self.config.storage_path
|
50
47
|
)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
else: # Cloud mode
|
49
|
+
key = os.getenv("WEAVIATE_API_KEY")
|
50
|
+
url = os.getenv("WEAVIATE_API_URL")
|
51
|
+
if url is None or key is None:
|
52
|
+
raise ValueError(
|
53
|
+
"""WEAVIATE_API_KEY, WEAVIATE_API_URL env variables must be set to
|
54
|
+
use WeaviateDB in cloud mode. Please set these values
|
55
|
+
in your .env file.
|
56
|
+
"""
|
57
|
+
)
|
58
|
+
self.client = weaviate.connect_to_weaviate_cloud(
|
59
|
+
cluster_url=url,
|
60
|
+
auth_credentials=Auth.api_key(key),
|
61
|
+
)
|
62
|
+
|
55
63
|
if config.collection_name is not None:
|
56
64
|
WeaviateDB.validate_and_format_collection_name(config.collection_name)
|
57
65
|
|
@@ -267,3 +275,8 @@ class WeaviateDB(VectorStore):
|
|
267
275
|
)
|
268
276
|
|
269
277
|
return formatted_name
|
278
|
+
|
279
|
+
def __del__(self) -> None:
|
280
|
+
# Gracefully close the connection with local client
|
281
|
+
if not self.config.cloud:
|
282
|
+
self.client.close()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.39.2 → langroid-0.39.3}/langroid/agent/special/sql/utils/description_extractors.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/prompt_formatter/hf_formatter.py
RENAMED
File without changes
|
{langroid-0.39.2 → langroid-0.39.3}/langroid/language_models/prompt_formatter/llama2_formatter.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|