langroid 0.52.1__tar.gz → 0.52.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.52.1 → langroid-0.52.3}/PKG-INFO +1 -1
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/file_attachment.py +101 -12
- {langroid-0.52.1 → langroid-0.52.3}/pyproject.toml +1 -1
- {langroid-0.52.1 → langroid-0.52.3}/.gitignore +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/LICENSE +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/README.md +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/base.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/batch.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/callbacks/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/callbacks/chainlit.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/chat_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/chat_document.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/openai_assistant.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/arangodb/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/arangodb/arangodb_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/arangodb/system_messages.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/arangodb/tools.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/arangodb/utils.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/doc_chat_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/doc_chat_task.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/lance_doc_chat_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/lance_rag/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/lance_tools.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/neo4j/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/neo4j/csv_kg_chat.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/neo4j/system_messages.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/neo4j/tools.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/relevance_extractor_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/retriever_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/sql/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/sql/sql_chat_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/sql/utils/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/sql/utils/system_message.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/sql/utils/tools.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/special/table_chat_agent.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/task.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tool_message.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/duckduckgo_search_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/exa_search_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/file_tools.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/google_search_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/metaphor_search_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/orchestration.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/recipient_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/retrieval_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/rewind_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/segment_extract_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/tools/tavily_search_tool.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/agent/xml_tool_message.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/cachedb/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/cachedb/base.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/cachedb/momento_cachedb.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/cachedb/redis_cachedb.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/base.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/models.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/protoc/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/protoc/embeddings.proto +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/protoc/embeddings_pb2.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/embedding_models/remote_embeds.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/exceptions.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/azure_openai.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/base.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/config.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/mock_lm.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/model_info.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/openai_gpt.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/prompt_formatter/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/prompt_formatter/base.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/prompt_formatter/hf_formatter.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/utils.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/mytypes.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/agent_chats.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/code_parser.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/document_parser.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/md_parser.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/para_sentence_split.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/parse_json.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/parser.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/pdf_utils.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/repo_loader.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/routing.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/search.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/spider.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/table_loader.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/url_loader.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/urls.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/utils.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/parsing/web_search.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/prompts/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/prompts/dialog.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/prompts/prompts_config.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/prompts/templates.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/py.typed +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/pydantic_v1/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/pydantic_v1/main.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/algorithms/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/algorithms/graph.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/configuration.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/constants.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/git_utils.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/globals.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/logging.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/object_registry.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/output/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/output/citations.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/output/printing.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/output/status.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/pandas_utils.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/pydantic_utils.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/system.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/utils/types.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/__init__.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/base.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/chromadb.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/lancedb.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/meilisearch.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/pineconedb.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/postgres.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/qdrantdb.py +0 -0
- {langroid-0.52.1 → langroid-0.52.3}/langroid/vector_store/weaviatedb.py +0 -0
@@ -3,6 +3,7 @@ import mimetypes
|
|
3
3
|
import uuid
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import Any, BinaryIO, Dict, Optional, Union
|
6
|
+
from urllib.parse import urlparse
|
6
7
|
|
7
8
|
from langroid.pydantic_v1 import BaseModel
|
8
9
|
|
@@ -13,6 +14,8 @@ class FileAttachment(BaseModel):
|
|
13
14
|
content: bytes
|
14
15
|
filename: Optional[str] = None
|
15
16
|
mime_type: str = "application/octet-stream"
|
17
|
+
url: str | None = None
|
18
|
+
detail: str | None = None
|
16
19
|
|
17
20
|
def __init__(self, **data: Any) -> None:
|
18
21
|
"""Initialize with sensible defaults for filename if not provided."""
|
@@ -23,7 +26,11 @@ class FileAttachment(BaseModel):
|
|
23
26
|
super().__init__(**data)
|
24
27
|
|
25
28
|
@classmethod
|
26
|
-
def
|
29
|
+
def _from_path(
|
30
|
+
cls,
|
31
|
+
file_path: Union[str, Path],
|
32
|
+
detail: Optional[str] = None,
|
33
|
+
) -> "FileAttachment":
|
27
34
|
"""Create a FileAttachment from a file path.
|
28
35
|
|
29
36
|
Args:
|
@@ -40,7 +47,74 @@ class FileAttachment(BaseModel):
|
|
40
47
|
if mime_type is None:
|
41
48
|
mime_type = "application/octet-stream"
|
42
49
|
|
43
|
-
return cls(
|
50
|
+
return cls(
|
51
|
+
content=content,
|
52
|
+
filename=path.name,
|
53
|
+
mime_type=mime_type,
|
54
|
+
detail=detail,
|
55
|
+
)
|
56
|
+
|
57
|
+
@classmethod
|
58
|
+
def _from_url(
|
59
|
+
cls,
|
60
|
+
url: str,
|
61
|
+
content: Optional[bytes] = None,
|
62
|
+
filename: Optional[str] = None,
|
63
|
+
mime_type: Optional[str] = None,
|
64
|
+
detail: Optional[str] = None,
|
65
|
+
) -> "FileAttachment":
|
66
|
+
"""Create a FileAttachment from a URL.
|
67
|
+
|
68
|
+
Args:
|
69
|
+
url: URL to the file
|
70
|
+
content: Optional raw bytes content (if already fetched)
|
71
|
+
filename: Optional name to use for the file
|
72
|
+
mime_type: MIME type of the content, guessed from filename or url
|
73
|
+
|
74
|
+
Returns:
|
75
|
+
FileAttachment instance
|
76
|
+
"""
|
77
|
+
if filename is None and url:
|
78
|
+
# Extract filename from URL if possible
|
79
|
+
|
80
|
+
parsed_url = urlparse(url)
|
81
|
+
path = parsed_url.path
|
82
|
+
filename = path.split("/")[-1] if path else None
|
83
|
+
|
84
|
+
if mime_type is None and filename:
|
85
|
+
mime_type, _ = mimetypes.guess_type(filename)
|
86
|
+
|
87
|
+
return cls(
|
88
|
+
content=content or b"", # Empty bytes if no content provided
|
89
|
+
filename=filename,
|
90
|
+
mime_type=mime_type or "application/octet-stream",
|
91
|
+
url=url,
|
92
|
+
detail=detail,
|
93
|
+
)
|
94
|
+
|
95
|
+
@classmethod
|
96
|
+
def from_path(
|
97
|
+
cls,
|
98
|
+
path: Union[str, Path],
|
99
|
+
detail: str | None = None,
|
100
|
+
) -> "FileAttachment":
|
101
|
+
"""Create a FileAttachment from either a local file path or a URL.
|
102
|
+
|
103
|
+
Args:
|
104
|
+
path_or_url: Path to the file or URL to fetch
|
105
|
+
|
106
|
+
Returns:
|
107
|
+
FileAttachment instance
|
108
|
+
"""
|
109
|
+
# Convert to string if Path object
|
110
|
+
path_str = str(path)
|
111
|
+
|
112
|
+
# Check if it's a URL
|
113
|
+
if path_str.startswith(("http://", "https://", "ftp://")):
|
114
|
+
return cls._from_url(url=path_str, detail=detail)
|
115
|
+
else:
|
116
|
+
# Assume it's a local file path
|
117
|
+
return cls._from_path(path_str, detail=detail)
|
44
118
|
|
45
119
|
@classmethod
|
46
120
|
def from_bytes(
|
@@ -135,19 +209,34 @@ class FileAttachment(BaseModel):
|
|
135
209
|
Returns:
|
136
210
|
Dictionary with file data
|
137
211
|
"""
|
138
|
-
if
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
212
|
+
if (
|
213
|
+
self.mime_type
|
214
|
+
and self.mime_type.startswith("image/")
|
215
|
+
or "gemini" in model.lower()
|
216
|
+
):
|
217
|
+
# for gemini models, we use `image_url` for both pdf-files and images
|
218
|
+
|
219
|
+
image_url_dict = {}
|
220
|
+
|
221
|
+
# If we have a URL and it's a full http/https URL, use it directly
|
222
|
+
if self.url and (
|
223
|
+
self.url.startswith("http://") or self.url.startswith("https://")
|
224
|
+
):
|
225
|
+
image_url_dict["url"] = self.url
|
226
|
+
# Otherwise use base64 data URI
|
227
|
+
else:
|
228
|
+
image_url_dict["url"] = self.to_data_uri()
|
229
|
+
|
230
|
+
# Add detail parameter if specified
|
231
|
+
if self.detail:
|
232
|
+
image_url_dict["detail"] = self.detail
|
233
|
+
|
143
234
|
return dict(
|
144
|
-
type="
|
145
|
-
|
146
|
-
file_data=self.to_data_uri(),
|
147
|
-
),
|
235
|
+
type="image_url",
|
236
|
+
image_url=image_url_dict,
|
148
237
|
)
|
149
238
|
else:
|
150
|
-
#
|
239
|
+
# For non-image files
|
151
240
|
return dict(
|
152
241
|
type="file",
|
153
242
|
file=dict(
|
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.52.1 → langroid-0.52.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
|
File without changes
|
File without changes
|
{langroid-0.52.1 → langroid-0.52.3}/langroid/language_models/prompt_formatter/hf_formatter.py
RENAMED
File without changes
|
{langroid-0.52.1 → langroid-0.52.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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|