langchain-asimov 0.0.0__py3-none-any.whl → 0.0.1__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.

Potentially problematic release.


This version of langchain-asimov might be problematic. Click here for more details.

@@ -1 +1,14 @@
1
1
  # This is free and unencumbered software released into the public domain.
2
+
3
+ """LangChain integration with the ASIMOV platform."""
4
+
5
+ from ._version import __version__, __version_tuple__
6
+ from .document_loaders import AsimovLoader
7
+ from .errors import AsimovModuleNotFound
8
+
9
+ __all__ = [
10
+ 'AsimovLoader',
11
+ 'AsimovModuleNotFound',
12
+ '__version__',
13
+ '__version_tuple__',
14
+ ]
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.0.0'
21
- __version_tuple__ = version_tuple = (0, 0, 0)
20
+ __version__ = version = '0.0.1'
21
+ __version_tuple__ = version_tuple = (0, 0, 1)
@@ -0,0 +1,79 @@
1
+ # This is free and unencumbered software released into the public domain.
2
+
3
+ """ASIMOV document loader."""
4
+
5
+ from __future__ import annotations # for Python 3.9
6
+
7
+ import json
8
+ import logging
9
+ import subprocess
10
+ from .errors import AsimovModuleNotFound
11
+ from langchain_core.document_loaders.base import BaseLoader
12
+ from langchain_core.documents import Document
13
+ from pyld import jsonld
14
+ from typing import Any, Iterator, cast, override
15
+
16
+ logger = logging.getLogger(__file__)
17
+
18
+ JSONLD_CONTEXT = {
19
+ "@version": 1.1,
20
+ "know": "https://know.dev/",
21
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
22
+ }
23
+
24
+ class AsimovLoader(BaseLoader):
25
+ """
26
+ ASIMOV document loader integration.
27
+
28
+ Setup:
29
+ Install ``langchain-asimov``:
30
+
31
+ ```bash
32
+ pip install -U langchain-asimov
33
+ ```
34
+
35
+ Instantiate:
36
+ ```python
37
+ from langchain_asimov import AsimovLoader
38
+
39
+ loader = AsimovLoader(
40
+ module="serpapi",
41
+ url="https://duckduckgo.com/?q=Isaac+Asimov"
42
+ )
43
+ ```
44
+ """
45
+ def __init__(self, module: str, url: str, **kwargs: Any) -> None:
46
+ self.module = module
47
+ self.url = url
48
+
49
+ @override
50
+ def lazy_load(self) -> Iterator[Document]:
51
+ try:
52
+ result = subprocess.run(
53
+ [f"asimov-{self.module}-importer", self.url],
54
+ stdout=subprocess.PIPE,
55
+ stderr=subprocess.PIPE,
56
+ text=True,
57
+ )
58
+ result.check_returncode()
59
+ output = json.loads(result.stdout)
60
+ output = cast(dict, jsonld.flatten(output, JSONLD_CONTEXT))
61
+ for resource in output["@graph"]:
62
+ resource_id = resource["@id"]
63
+ page_content = describe(resource)
64
+ yield Document(page_content, id=resource_id, metadata=resource)
65
+ except FileNotFoundError as error:
66
+ #logger.exception(error)
67
+ raise AsimovModuleNotFound(self.module) from (error if __debug__ else None)
68
+ except subprocess.CalledProcessError as error:
69
+ #logger.exception(error)
70
+ raise error # TODO
71
+ except json.decoder.JSONDecodeError as error:
72
+ #logger.exception(error)
73
+ raise error # TODO
74
+ except jsonld.JsonLdError as error:
75
+ #logger.exception(error)
76
+ raise error # TODO
77
+
78
+ def describe(resource: dict) -> str:
79
+ return resource["know:summary"]["@value"] # TODO
@@ -0,0 +1,33 @@
1
+ # This is free and unencumbered software released into the public domain.
2
+
3
+ from __future__ import annotations # for Python 3.9
4
+
5
+ class AsimovModuleNotFound(Exception):
6
+ """Exception raised when a module cannot be found or imported.
7
+
8
+ Attributes:
9
+ module_name: The name of the module that was not found
10
+ message: Explanation of the error
11
+ """
12
+
13
+ def __init__(self, module_name: str, message: str | None = None) -> None:
14
+ """Initializes the `AsimovModuleNotFound` exception.
15
+
16
+ Args:
17
+ module_name: The name of the module that was not found
18
+ message: Optional custom error message. If not provided,
19
+ a default message will be generated.
20
+ """
21
+ self.module_name = module_name
22
+ if message is None:
23
+ message = f"Module '{module_name}' not found"
24
+ self.message = message
25
+ super().__init__(self.message)
26
+
27
+ def __str__(self) -> str:
28
+ """Returns a string representation of the exception."""
29
+ return self.message
30
+
31
+ def __repr__(self) -> str:
32
+ """Returns a detailed string representation of the exception."""
33
+ return f"{self.__class__.__name__}(module_name={self.module_name!r}, message={self.message!r})"
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-asimov
3
- Version: 0.0.0
3
+ Version: 0.0.1
4
4
  Summary: LangChain integration with the ASIMOV platform.
5
5
  Project-URL: Homepage, https://github.com/asimov-platform
6
6
  Project-URL: Repository, https://github.com/asimov-platform/langchain-asimov
@@ -11,11 +11,32 @@ Author-email: ASIMOV Protocol <support@asimov.so>
11
11
  License-Expression: Unlicense
12
12
  License-File: UNLICENSE
13
13
  Requires-Python: >=3.9
14
- Requires-Dist: langchain>=0.3
14
+ Requires-Dist: langchain-core>=0.3
15
+ Requires-Dist: pyld>=2
15
16
  Description-Content-Type: text/markdown
16
17
 
17
18
  # LangChain ASIMOV Integration
18
19
 
19
20
  [![License](https://img.shields.io/badge/license-Public%20Domain-blue.svg)](https://unlicense.org)
20
- [![Compatibility](https://img.shields.io/pypi/pyversions/langchain-asimov.svg)](https://pypi.python.org/pypi/langchain-asimov)
21
+ [![Compatibility](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fasimov-platform%2Flangchain-asimov%2Frefs%2Fheads%2Fmaster%2Fpyproject.toml)](https://pypi.python.org/pypi/langchain-asimov)
21
22
  [![Package](https://img.shields.io/pypi/v/langchain-asimov.svg)](https://pypi.python.org/pypi/langchain-asimov)
23
+
24
+ ## 👉 Examples
25
+
26
+ ### Fetching DuckDuckGo Results
27
+
28
+ ```bash
29
+ export SERPAPI_KEY="..."
30
+ ```
31
+
32
+ ```python
33
+ from langchain_asimov import AsimovLoader
34
+
35
+ search = AsimovLoader(
36
+ module="serpapi",
37
+ url="https://duckduckgo.com/?q=Isaac+Asimov"
38
+ )
39
+
40
+ for result in search.lazy_load():
41
+ print(result)
42
+ ```
@@ -0,0 +1,9 @@
1
+ langchain_asimov/__init__.py,sha256=AmAOI5niX9_L9ShANIPkdUQv04YJcg6B3qwK0QuUKbI,374
2
+ langchain_asimov/_version.py,sha256=vgltXBYF55vNcC2regxjGN0_cbebmm8VgcDdQaDapWQ,511
3
+ langchain_asimov/document_loaders.py,sha256=qqhmy_VPMAmCEofaMB7NGs0LO0N_KhbJU-ibAzwjfmA,2433
4
+ langchain_asimov/errors.py,sha256=AVE6eFujm-Iwdwr0czDkJSh6usNPdRBCsOKPWhof8oc,1251
5
+ langchain_asimov/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ langchain_asimov-0.0.1.dist-info/METADATA,sha256=8R3koHXXyZz0FTlOyVYJoA-HbDnVdEvzRuOjMHu4gsY,1530
7
+ langchain_asimov-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ langchain_asimov-0.0.1.dist-info/licenses/UNLICENSE,sha256=tQZYOMusRS38hVum5uAxSBrSxoQG9w0h6tkyE3RlPmw,1212
9
+ langchain_asimov-0.0.1.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- langchain_asimov/__init__.py,sha256=HNo12SN3s2UpenK7tK8xb4bSf4LpPpN0ZJGO34YM6cY,74
2
- langchain_asimov/_version.py,sha256=PqNGih23TQ8yvpw6AfE0jq7D_RYFgeG1E-CSVJ9Dntw,511
3
- langchain_asimov-0.0.0.dist-info/METADATA,sha256=A9b3ta2BEgtCx_yNlNeQ0r1DMZYlqGuzAw2mcRWwxGA,1083
4
- langchain_asimov-0.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
- langchain_asimov-0.0.0.dist-info/licenses/UNLICENSE,sha256=tQZYOMusRS38hVum5uAxSBrSxoQG9w0h6tkyE3RlPmw,1212
6
- langchain_asimov-0.0.0.dist-info/RECORD,,