langroid 0.31.1__py3-none-any.whl → 0.33.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.
- {langroid-0.31.1.dist-info → langroid-0.33.3.dist-info}/METADATA +150 -124
- langroid-0.33.3.dist-info/RECORD +7 -0
- {langroid-0.31.1.dist-info → langroid-0.33.3.dist-info}/WHEEL +1 -1
- langroid-0.33.3.dist-info/entry_points.txt +4 -0
- pyproject.toml +317 -212
- langroid/__init__.py +0 -106
- langroid/agent/.chainlit/config.toml +0 -121
- langroid/agent/.chainlit/translations/bn.json +0 -231
- langroid/agent/.chainlit/translations/en-US.json +0 -229
- langroid/agent/.chainlit/translations/gu.json +0 -231
- langroid/agent/.chainlit/translations/he-IL.json +0 -231
- langroid/agent/.chainlit/translations/hi.json +0 -231
- langroid/agent/.chainlit/translations/kn.json +0 -231
- langroid/agent/.chainlit/translations/ml.json +0 -231
- langroid/agent/.chainlit/translations/mr.json +0 -231
- langroid/agent/.chainlit/translations/ta.json +0 -231
- langroid/agent/.chainlit/translations/te.json +0 -231
- langroid/agent/.chainlit/translations/zh-CN.json +0 -229
- langroid/agent/__init__.py +0 -41
- langroid/agent/base.py +0 -1981
- langroid/agent/batch.py +0 -398
- langroid/agent/callbacks/__init__.py +0 -0
- langroid/agent/callbacks/chainlit.py +0 -598
- langroid/agent/chat_agent.py +0 -1899
- langroid/agent/chat_document.py +0 -454
- langroid/agent/helpers.py +0 -0
- langroid/agent/junk +0 -13
- langroid/agent/openai_assistant.py +0 -882
- langroid/agent/special/__init__.py +0 -59
- langroid/agent/special/arangodb/__init__.py +0 -0
- langroid/agent/special/arangodb/arangodb_agent.py +0 -656
- langroid/agent/special/arangodb/system_messages.py +0 -186
- langroid/agent/special/arangodb/tools.py +0 -107
- langroid/agent/special/arangodb/utils.py +0 -36
- langroid/agent/special/doc_chat_agent.py +0 -1466
- langroid/agent/special/lance_doc_chat_agent.py +0 -262
- langroid/agent/special/lance_rag/__init__.py +0 -9
- langroid/agent/special/lance_rag/critic_agent.py +0 -198
- langroid/agent/special/lance_rag/lance_rag_task.py +0 -82
- langroid/agent/special/lance_rag/query_planner_agent.py +0 -260
- langroid/agent/special/lance_tools.py +0 -61
- langroid/agent/special/neo4j/__init__.py +0 -0
- langroid/agent/special/neo4j/csv_kg_chat.py +0 -174
- langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -433
- langroid/agent/special/neo4j/system_messages.py +0 -120
- langroid/agent/special/neo4j/tools.py +0 -32
- langroid/agent/special/relevance_extractor_agent.py +0 -127
- langroid/agent/special/retriever_agent.py +0 -56
- langroid/agent/special/sql/__init__.py +0 -17
- langroid/agent/special/sql/sql_chat_agent.py +0 -654
- langroid/agent/special/sql/utils/__init__.py +0 -21
- langroid/agent/special/sql/utils/description_extractors.py +0 -190
- langroid/agent/special/sql/utils/populate_metadata.py +0 -85
- langroid/agent/special/sql/utils/system_message.py +0 -35
- langroid/agent/special/sql/utils/tools.py +0 -64
- langroid/agent/special/table_chat_agent.py +0 -263
- langroid/agent/structured_message.py +0 -9
- langroid/agent/task.py +0 -2093
- langroid/agent/tool_message.py +0 -393
- langroid/agent/tools/__init__.py +0 -38
- langroid/agent/tools/duckduckgo_search_tool.py +0 -50
- langroid/agent/tools/file_tools.py +0 -234
- langroid/agent/tools/google_search_tool.py +0 -39
- langroid/agent/tools/metaphor_search_tool.py +0 -67
- langroid/agent/tools/orchestration.py +0 -303
- langroid/agent/tools/recipient_tool.py +0 -235
- langroid/agent/tools/retrieval_tool.py +0 -32
- langroid/agent/tools/rewind_tool.py +0 -137
- langroid/agent/tools/segment_extract_tool.py +0 -41
- langroid/agent/typed_task.py +0 -19
- langroid/agent/xml_tool_message.py +0 -382
- langroid/agent_config.py +0 -0
- langroid/cachedb/__init__.py +0 -17
- langroid/cachedb/base.py +0 -58
- langroid/cachedb/momento_cachedb.py +0 -108
- langroid/cachedb/redis_cachedb.py +0 -153
- langroid/embedding_models/__init__.py +0 -39
- langroid/embedding_models/base.py +0 -74
- langroid/embedding_models/clustering.py +0 -189
- langroid/embedding_models/models.py +0 -461
- langroid/embedding_models/protoc/__init__.py +0 -0
- langroid/embedding_models/protoc/embeddings.proto +0 -19
- langroid/embedding_models/protoc/embeddings_pb2.py +0 -33
- langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -50
- langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -79
- langroid/embedding_models/remote_embeds.py +0 -153
- langroid/exceptions.py +0 -65
- langroid/experimental/team-save.py +0 -391
- langroid/language_models/.chainlit/config.toml +0 -121
- langroid/language_models/.chainlit/translations/en-US.json +0 -231
- langroid/language_models/__init__.py +0 -53
- langroid/language_models/azure_openai.py +0 -153
- langroid/language_models/base.py +0 -678
- langroid/language_models/config.py +0 -18
- langroid/language_models/mock_lm.py +0 -124
- langroid/language_models/openai_gpt.py +0 -1923
- langroid/language_models/prompt_formatter/__init__.py +0 -16
- langroid/language_models/prompt_formatter/base.py +0 -40
- langroid/language_models/prompt_formatter/hf_formatter.py +0 -132
- langroid/language_models/prompt_formatter/llama2_formatter.py +0 -75
- langroid/language_models/utils.py +0 -147
- langroid/mytypes.py +0 -84
- langroid/parsing/__init__.py +0 -52
- langroid/parsing/agent_chats.py +0 -38
- langroid/parsing/code-parsing.md +0 -86
- langroid/parsing/code_parser.py +0 -121
- langroid/parsing/config.py +0 -0
- langroid/parsing/document_parser.py +0 -718
- langroid/parsing/image_text.py +0 -32
- langroid/parsing/para_sentence_split.py +0 -62
- langroid/parsing/parse_json.py +0 -155
- langroid/parsing/parser.py +0 -313
- langroid/parsing/repo_loader.py +0 -790
- langroid/parsing/routing.py +0 -36
- langroid/parsing/search.py +0 -275
- langroid/parsing/spider.py +0 -102
- langroid/parsing/table_loader.py +0 -94
- langroid/parsing/url_loader.py +0 -111
- langroid/parsing/url_loader_cookies.py +0 -73
- langroid/parsing/urls.py +0 -273
- langroid/parsing/utils.py +0 -373
- langroid/parsing/web_search.py +0 -155
- langroid/prompts/__init__.py +0 -9
- langroid/prompts/chat-gpt4-system-prompt.md +0 -68
- langroid/prompts/dialog.py +0 -17
- langroid/prompts/prompts_config.py +0 -5
- langroid/prompts/templates.py +0 -141
- langroid/pydantic_v1/__init__.py +0 -10
- langroid/pydantic_v1/main.py +0 -4
- langroid/utils/.chainlit/config.toml +0 -121
- langroid/utils/.chainlit/translations/en-US.json +0 -231
- langroid/utils/__init__.py +0 -19
- langroid/utils/algorithms/__init__.py +0 -3
- langroid/utils/algorithms/graph.py +0 -103
- langroid/utils/configuration.py +0 -98
- langroid/utils/constants.py +0 -30
- langroid/utils/docker.py +0 -37
- langroid/utils/git_utils.py +0 -252
- langroid/utils/globals.py +0 -49
- langroid/utils/llms/__init__.py +0 -0
- langroid/utils/llms/strings.py +0 -8
- langroid/utils/logging.py +0 -135
- langroid/utils/object_registry.py +0 -66
- langroid/utils/output/__init__.py +0 -20
- langroid/utils/output/citations.py +0 -41
- langroid/utils/output/printing.py +0 -99
- langroid/utils/output/status.py +0 -40
- langroid/utils/pandas_utils.py +0 -30
- langroid/utils/pydantic_utils.py +0 -602
- langroid/utils/system.py +0 -286
- langroid/utils/types.py +0 -93
- langroid/utils/web/__init__.py +0 -0
- langroid/utils/web/login.py +0 -83
- langroid/vector_store/__init__.py +0 -50
- langroid/vector_store/base.py +0 -357
- langroid/vector_store/chromadb.py +0 -214
- langroid/vector_store/lancedb.py +0 -401
- langroid/vector_store/meilisearch.py +0 -299
- langroid/vector_store/momento.py +0 -278
- langroid/vector_store/qdrant_cloud.py +0 -6
- langroid/vector_store/qdrantdb.py +0 -468
- langroid-0.31.1.dist-info/RECORD +0 -162
- {langroid-0.31.1.dist-info → langroid-0.33.3.dist-info/licenses}/LICENSE +0 -0
@@ -1,127 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Agent to retrieve relevant segments from a body of text,
|
3
|
-
that are relevant to a query.
|
4
|
-
|
5
|
-
"""
|
6
|
-
|
7
|
-
import logging
|
8
|
-
from typing import Optional, no_type_check
|
9
|
-
|
10
|
-
from rich.console import Console
|
11
|
-
|
12
|
-
from langroid.agent.chat_agent import ChatAgent, ChatAgentConfig
|
13
|
-
from langroid.agent.chat_document import ChatDocument
|
14
|
-
from langroid.agent.tools.segment_extract_tool import SegmentExtractTool
|
15
|
-
from langroid.language_models.base import LLMConfig
|
16
|
-
from langroid.language_models.openai_gpt import OpenAIGPTConfig
|
17
|
-
from langroid.mytypes import Entity
|
18
|
-
from langroid.parsing.utils import extract_numbered_segments, number_segments
|
19
|
-
from langroid.utils.constants import DONE, NO_ANSWER
|
20
|
-
|
21
|
-
console = Console()
|
22
|
-
logger = logging.getLogger(__name__)
|
23
|
-
|
24
|
-
|
25
|
-
class RelevanceExtractorAgentConfig(ChatAgentConfig):
|
26
|
-
llm: LLMConfig | None = OpenAIGPTConfig()
|
27
|
-
segment_length: int = 1 # number of sentences per segment
|
28
|
-
query: str = "" # query for relevance extraction
|
29
|
-
system_message = """
|
30
|
-
The user will give you a PASSAGE containing segments numbered as
|
31
|
-
<#1#>, <#2#>, <#3#>, etc.,
|
32
|
-
followed by a QUERY. Extract ONLY the segment-numbers from
|
33
|
-
the PASSAGE that are RELEVANT to the QUERY.
|
34
|
-
Present the extracted segment-numbers using the `extract_segments` tool/function.
|
35
|
-
"""
|
36
|
-
|
37
|
-
|
38
|
-
class RelevanceExtractorAgent(ChatAgent):
|
39
|
-
"""
|
40
|
-
Agent for extracting segments from text, that are relevant to a given query.
|
41
|
-
"""
|
42
|
-
|
43
|
-
def __init__(self, config: RelevanceExtractorAgentConfig):
|
44
|
-
super().__init__(config)
|
45
|
-
self.config: RelevanceExtractorAgentConfig = config
|
46
|
-
self.enable_message(SegmentExtractTool)
|
47
|
-
self.numbered_passage: Optional[str] = None
|
48
|
-
|
49
|
-
@no_type_check
|
50
|
-
def llm_response(
|
51
|
-
self, message: Optional[str | ChatDocument] = None
|
52
|
-
) -> Optional[ChatDocument]:
|
53
|
-
"""Compose a prompt asking to extract relevant segments from a passage.
|
54
|
-
Steps:
|
55
|
-
- number the segments in the passage
|
56
|
-
- compose prompt
|
57
|
-
- send to LLM
|
58
|
-
"""
|
59
|
-
assert self.config.query is not None, "No query specified"
|
60
|
-
assert message is not None, "No message specified"
|
61
|
-
message_str = message.content if isinstance(message, ChatDocument) else message
|
62
|
-
# number the segments in the passage
|
63
|
-
self.numbered_passage = number_segments(message_str, self.config.segment_length)
|
64
|
-
# compose prompt
|
65
|
-
prompt = f"""
|
66
|
-
PASSAGE:
|
67
|
-
{self.numbered_passage}
|
68
|
-
|
69
|
-
QUERY: {self.config.query}
|
70
|
-
"""
|
71
|
-
# send to LLM
|
72
|
-
return super().llm_response(prompt)
|
73
|
-
|
74
|
-
@no_type_check
|
75
|
-
async def llm_response_async(
|
76
|
-
self, message: Optional[str | ChatDocument] = None
|
77
|
-
) -> Optional[ChatDocument]:
|
78
|
-
"""
|
79
|
-
Compose a prompt asking to extract relevant segments from a passage.
|
80
|
-
Steps:
|
81
|
-
- number the segments in the passage
|
82
|
-
- compose prompt
|
83
|
-
- send to LLM
|
84
|
-
The LLM is expected to generate a structured msg according to the
|
85
|
-
SegmentExtractTool schema, i.e. it should contain a `segment_list` field
|
86
|
-
whose value is a list of segment numbers or ranges, like "10,12,14-17".
|
87
|
-
"""
|
88
|
-
|
89
|
-
assert self.config.query is not None, "No query specified"
|
90
|
-
assert message is not None, "No message specified"
|
91
|
-
message_str = message.content if isinstance(message, ChatDocument) else message
|
92
|
-
# number the segments in the passage
|
93
|
-
self.numbered_passage = number_segments(message_str, self.config.segment_length)
|
94
|
-
# compose prompt
|
95
|
-
prompt = f"""
|
96
|
-
PASSAGE:
|
97
|
-
{self.numbered_passage}
|
98
|
-
|
99
|
-
QUERY: {self.config.query}
|
100
|
-
"""
|
101
|
-
# send to LLM
|
102
|
-
return await super().llm_response_async(prompt)
|
103
|
-
|
104
|
-
def extract_segments(self, msg: SegmentExtractTool) -> str:
|
105
|
-
"""Method to handle a segmentExtractTool message from LLM"""
|
106
|
-
spec = msg.segment_list
|
107
|
-
if len(self.message_history) == 0:
|
108
|
-
return DONE + " " + NO_ANSWER
|
109
|
-
if spec is None or spec.strip() in ["", NO_ANSWER]:
|
110
|
-
return DONE + " " + NO_ANSWER
|
111
|
-
assert self.numbered_passage is not None, "No numbered passage"
|
112
|
-
# assume this has numbered segments
|
113
|
-
try:
|
114
|
-
extracts = extract_numbered_segments(self.numbered_passage, spec)
|
115
|
-
except Exception:
|
116
|
-
return DONE + " " + NO_ANSWER
|
117
|
-
# this response ends the task by saying DONE
|
118
|
-
return DONE + " " + extracts
|
119
|
-
|
120
|
-
def handle_message_fallback(
|
121
|
-
self, msg: str | ChatDocument
|
122
|
-
) -> str | ChatDocument | None:
|
123
|
-
"""Handle case where LLM forgets to use SegmentExtractTool"""
|
124
|
-
if isinstance(msg, ChatDocument) and msg.metadata.sender == Entity.LLM:
|
125
|
-
return DONE + " " + NO_ANSWER
|
126
|
-
else:
|
127
|
-
return None
|
@@ -1,56 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Deprecated: use DocChatAgent instead, with DocChatAgentConfig.retrieve_only=True,
|
3
|
-
and if you want to retrieve FULL relevant doc-contents rather than just extracts,
|
4
|
-
then set DocChatAgentConfig.extraction_granularity=-1
|
5
|
-
|
6
|
-
This is an agent to retrieve relevant extracts from a vector store,
|
7
|
-
where the LLM is used to filter for "true" relevance after retrieval from the
|
8
|
-
vector store.
|
9
|
-
This is essentially the same as DocChatAgent, except that instead of
|
10
|
-
generating final summary answer based on relevant extracts, it just returns
|
11
|
-
those extracts.
|
12
|
-
See test_retriever_agent.py for example usage.
|
13
|
-
"""
|
14
|
-
|
15
|
-
import logging
|
16
|
-
from typing import Sequence
|
17
|
-
|
18
|
-
from rich.console import Console
|
19
|
-
|
20
|
-
from langroid.agent.special.doc_chat_agent import DocChatAgent, DocChatAgentConfig
|
21
|
-
from langroid.mytypes import DocMetaData, Document
|
22
|
-
|
23
|
-
console = Console()
|
24
|
-
logger = logging.getLogger(__name__)
|
25
|
-
|
26
|
-
# for backwards compatibility:
|
27
|
-
RecordMetadata = DocMetaData
|
28
|
-
RecordDoc = Document
|
29
|
-
RetrieverAgentConfig = DocChatAgentConfig
|
30
|
-
|
31
|
-
|
32
|
-
class RetrieverAgent(DocChatAgent):
|
33
|
-
"""
|
34
|
-
Agent for just retrieving chunks/docs/extracts matching a query
|
35
|
-
"""
|
36
|
-
|
37
|
-
def __init__(self, config: DocChatAgentConfig):
|
38
|
-
super().__init__(config)
|
39
|
-
self.config: DocChatAgentConfig = config
|
40
|
-
logger.warning(
|
41
|
-
"""
|
42
|
-
`RetrieverAgent` is deprecated. Use `DocChatAgent` instead, with
|
43
|
-
`DocChatAgentConfig.retrieve_only=True`, and if you want to retrieve
|
44
|
-
FULL relevant doc-contents rather than just extracts, then set
|
45
|
-
`DocChatAgentConfig.extraction_granularity=-1`
|
46
|
-
"""
|
47
|
-
)
|
48
|
-
|
49
|
-
def get_records(self) -> Sequence[Document]:
|
50
|
-
raise NotImplementedError
|
51
|
-
|
52
|
-
def ingest(self) -> None:
|
53
|
-
records = self.get_records()
|
54
|
-
if self.vecdb is None:
|
55
|
-
raise ValueError("No vector store specified")
|
56
|
-
self.vecdb.add_documents(records)
|
@@ -1,17 +0,0 @@
|
|
1
|
-
from . import utils
|
2
|
-
|
3
|
-
|
4
|
-
__all__ = [
|
5
|
-
"utils",
|
6
|
-
]
|
7
|
-
|
8
|
-
try:
|
9
|
-
from . import sql_chat_agent
|
10
|
-
from .sql_chat_agent import SQLChatAgentConfig, SQLChatAgent
|
11
|
-
|
12
|
-
sql_chat_agent
|
13
|
-
SQLChatAgent
|
14
|
-
SQLChatAgentConfig
|
15
|
-
__all__.extend(["SQLChatAgentConfig", "SQLChatAgent", "sql_chat_agent"])
|
16
|
-
except ImportError:
|
17
|
-
pass
|