langroid 0.39.2__py3-none-any.whl → 0.39.3__py3-none-any.whl

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.
@@ -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
- format_footnote_text,
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
- def extract_markdown_references(md_string: str) -> list[int]:
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
langroid/utils/system.py CHANGED
@@ -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
- key = os.getenv("WEAVIATE_API_KEY")
43
- url = os.getenv("WEAVIATE_API_URL")
44
- if url is None or key is None:
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
- self.client = weaviate.connect_to_weaviate_cloud(
52
- cluster_url=url,
53
- auth_credentials=Auth.api_key(key),
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langroid
3
- Version: 0.39.2
3
+ Version: 0.39.3
4
4
  Summary: Harness LLMs with Multi-Agent Programming
5
5
  Author-email: Prasad Chalasani <pchalasani@gmail.com>
6
6
  License: MIT
@@ -14,7 +14,7 @@ langroid/agent/xml_tool_message.py,sha256=6SshYZJKIfi4mkE-gIoSwjkEYekQ8GwcSiCv7a
14
14
  langroid/agent/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  langroid/agent/callbacks/chainlit.py,sha256=RH8qUXaZE5o2WQz3WJQ1SdFtASGlxWCA6_HYz_3meDQ,20822
16
16
  langroid/agent/special/__init__.py,sha256=gik_Xtm_zV7U9s30Mn8UX3Gyuy4jTjQe9zjiE3HWmEo,1273
17
- langroid/agent/special/doc_chat_agent.py,sha256=tMx-3cBEIHJM14P20cYvIzAc9z-skSnHOPVJ0eegxzc,64692
17
+ langroid/agent/special/doc_chat_agent.py,sha256=Q16HOg6MXa26szTO29OOIv1kv8QfuUjxLlLOP3eqZvA,64539
18
18
  langroid/agent/special/lance_doc_chat_agent.py,sha256=s8xoRs0gGaFtDYFUSIRchsgDVbS5Q3C2b2mr3V1Fd-Q,10419
19
19
  langroid/agent/special/lance_tools.py,sha256=qS8x4wi8mrqfbYV2ztFzrcxyhHQ0ZWOc-zkYiH7awj0,2105
20
20
  langroid/agent/special/relevance_extractor_agent.py,sha256=zIx8GUdVo1aGW6ASla0NPQjYYIpmriK_TYMijqAx3F8,4796
@@ -108,12 +108,12 @@ langroid/utils/logging.py,sha256=mwxHimq1wtVQ64PvDyfJJ7Upj-rjHLNHgx8EC2wClvo,402
108
108
  langroid/utils/object_registry.py,sha256=iPz9GHzvmCeVoidB3JdAMEKcxJEqTdUr0otQEexDZ5s,2100
109
109
  langroid/utils/pandas_utils.py,sha256=UctS986Jtl_MvU5rA7-GfrjEHXP7MNu8ePhepv0bTn0,755
110
110
  langroid/utils/pydantic_utils.py,sha256=R7Ps8VP56-eSo-LYHWllFo-SJ2zDmdItuuYpUq2gGJ8,20854
111
- langroid/utils/system.py,sha256=AiEehQy0K9c9qHdKsZRCscRrazDzuh5Tv3GRQsA0Cxg,8455
111
+ langroid/utils/system.py,sha256=cJqDgOf9mM82l1GyUeQQdEYAwepYXQwtpJU8Xrz0-MA,8453
112
112
  langroid/utils/types.py,sha256=4GrOnU3HLWh-UwaUPp7LlB3V413q3K5OSzc0ggDoQ6A,2510
113
113
  langroid/utils/algorithms/__init__.py,sha256=WylYoZymA0fnzpB4vrsH_0n7WsoLhmuZq8qxsOCjUpM,41
114
114
  langroid/utils/algorithms/graph.py,sha256=JbdpPnUOhw4-D6O7ou101JLA3xPCD0Lr3qaPoFCaRfo,2866
115
115
  langroid/utils/output/__init__.py,sha256=7P0f--4IZneNsTxXY5fd6d6iW-CeVe-KSsl-87sbBPc,340
116
- langroid/utils/output/citations.py,sha256=mQhRXVN-uhmKd2z32UZQBE0adZGEaQJ7cVXLfkrcZJI,2221
116
+ langroid/utils/output/citations.py,sha256=9T69O_N6mxPQjQ-qC1vKS8_kyg1z5hDQXMhBsA45xkk,3147
117
117
  langroid/utils/output/printing.py,sha256=yzPJZN-8_jyOJmI9N_oLwEDfjMwVgk3IDiwnZ4eK_AE,2962
118
118
  langroid/utils/output/status.py,sha256=rzbE7mDJcgNNvdtylCseQcPGCGghtJvVq3lB-OPJ49E,1049
119
119
  langroid/vector_store/__init__.py,sha256=BcoOm1tG3y0EqjkIGmMOHkY9iTUhDHgyruknWDKgqIg,1214
@@ -123,8 +123,8 @@ langroid/vector_store/lancedb.py,sha256=Qd20gKjWozPWfW5-D66J6U8dSrJo1yl-maj6s1lb
123
123
  langroid/vector_store/meilisearch.py,sha256=6frB7GFWeWmeKzRfLZIvzRjllniZ1cYj3HmhHQICXLs,11663
124
124
  langroid/vector_store/momento.py,sha256=xOaU7Hlyyn_5ihb0ARS5JHtmrKrTCt2IdRA-ioMM5ek,10307
125
125
  langroid/vector_store/qdrantdb.py,sha256=v7TAsIoj_vxeKDYS9tpwJLBZA8fuTweTYxHo0X_uawM,17949
126
- langroid/vector_store/weaviatedb.py,sha256=FOzgvqLqvdN5jJebVtJ-8tu2CeBzBfSP3ih4_ODEOOw,10605
127
- langroid-0.39.2.dist-info/METADATA,sha256=wFY32Hc5yDfZqfFRrz9AKIM17w42GxzYY13pBQX2shg,60634
128
- langroid-0.39.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
129
- langroid-0.39.2.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
130
- langroid-0.39.2.dist-info/RECORD,,
126
+ langroid/vector_store/weaviatedb.py,sha256=cMg9kqJXlD1WURs6QivHvwausCyLYGr4mOK2v9uYkhw,11105
127
+ langroid-0.39.3.dist-info/METADATA,sha256=UllXMfvh8RIbS41l9lvLdujPr94D-fC0DmIPOZUa6e0,60634
128
+ langroid-0.39.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
129
+ langroid-0.39.3.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
130
+ langroid-0.39.3.dist-info/RECORD,,