typeagent-py 0.1.0__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.
- typeagent_py-0.1.0/LICENSE +21 -0
- typeagent_py-0.1.0/PKG-INFO +28 -0
- typeagent_py-0.1.0/README.md +60 -0
- typeagent_py-0.1.0/pyproject.toml +57 -0
- typeagent_py-0.1.0/setup.cfg +4 -0
- typeagent_py-0.1.0/test/test_auth.py +103 -0
- typeagent_py-0.1.0/test/test_collections.py +472 -0
- typeagent_py-0.1.0/test/test_conversation_metadata.py +572 -0
- typeagent_py-0.1.0/test/test_demo.py +126 -0
- typeagent_py-0.1.0/test/test_embeddings.py +130 -0
- typeagent_py-0.1.0/test/test_interfaces.py +511 -0
- typeagent_py-0.1.0/test/test_knowledge.py +86 -0
- typeagent_py-0.1.0/test/test_kplib.py +117 -0
- typeagent_py-0.1.0/test/test_message_text_index_population.py +120 -0
- typeagent_py-0.1.0/test/test_message_text_index_serialization.py +172 -0
- typeagent_py-0.1.0/test/test_messageindex.py +235 -0
- typeagent_py-0.1.0/test/test_podcasts.py +87 -0
- typeagent_py-0.1.0/test/test_property_index_population.py +185 -0
- typeagent_py-0.1.0/test/test_propindex.py +321 -0
- typeagent_py-0.1.0/test/test_query.py +707 -0
- typeagent_py-0.1.0/test/test_related_terms_fast.py +119 -0
- typeagent_py-0.1.0/test/test_related_terms_index_population.py +184 -0
- typeagent_py-0.1.0/test/test_reltermsindex.py +252 -0
- typeagent_py-0.1.0/test/test_searchlib.py +659 -0
- typeagent_py-0.1.0/test/test_secindex.py +106 -0
- typeagent_py-0.1.0/test/test_secindex_storage_integration.py +48 -0
- typeagent_py-0.1.0/test/test_semrefindex.py +412 -0
- typeagent_py-0.1.0/test/test_serialization.py +136 -0
- typeagent_py-0.1.0/test/test_sqlite_indexes.py +791 -0
- typeagent_py-0.1.0/test/test_sqlitestore.py +192 -0
- typeagent_py-0.1.0/test/test_storage_providers_unified.py +706 -0
- typeagent_py-0.1.0/test/test_timestampindex.py +58 -0
- typeagent_py-0.1.0/test/test_utils.py +53 -0
- typeagent_py-0.1.0/test/test_vectorbase.py +180 -0
- typeagent_py-0.1.0/typeagent/aitools/auth.py +61 -0
- typeagent_py-0.1.0/typeagent/aitools/embeddings.py +232 -0
- typeagent_py-0.1.0/typeagent/aitools/utils.py +244 -0
- typeagent_py-0.1.0/typeagent/aitools/vectorbase.py +175 -0
- typeagent_py-0.1.0/typeagent/knowpro/answer_context_schema.py +49 -0
- typeagent_py-0.1.0/typeagent/knowpro/answer_response_schema.py +34 -0
- typeagent_py-0.1.0/typeagent/knowpro/answers.py +577 -0
- typeagent_py-0.1.0/typeagent/knowpro/collections.py +759 -0
- typeagent_py-0.1.0/typeagent/knowpro/common.py +9 -0
- typeagent_py-0.1.0/typeagent/knowpro/convknowledge.py +112 -0
- typeagent_py-0.1.0/typeagent/knowpro/convsettings.py +94 -0
- typeagent_py-0.1.0/typeagent/knowpro/convutils.py +49 -0
- typeagent_py-0.1.0/typeagent/knowpro/date_time_schema.py +32 -0
- typeagent_py-0.1.0/typeagent/knowpro/field_helpers.py +87 -0
- typeagent_py-0.1.0/typeagent/knowpro/fuzzyindex.py +144 -0
- typeagent_py-0.1.0/typeagent/knowpro/interfaces.py +818 -0
- typeagent_py-0.1.0/typeagent/knowpro/knowledge.py +88 -0
- typeagent_py-0.1.0/typeagent/knowpro/kplib.py +125 -0
- typeagent_py-0.1.0/typeagent/knowpro/query.py +1128 -0
- typeagent_py-0.1.0/typeagent/knowpro/search.py +628 -0
- typeagent_py-0.1.0/typeagent/knowpro/search_query_schema.py +165 -0
- typeagent_py-0.1.0/typeagent/knowpro/searchlang.py +729 -0
- typeagent_py-0.1.0/typeagent/knowpro/searchlib.py +345 -0
- typeagent_py-0.1.0/typeagent/knowpro/secindex.py +100 -0
- typeagent_py-0.1.0/typeagent/knowpro/serialization.py +390 -0
- typeagent_py-0.1.0/typeagent/knowpro/textlocindex.py +179 -0
- typeagent_py-0.1.0/typeagent/knowpro/utils.py +17 -0
- typeagent_py-0.1.0/typeagent/mcp/server.py +139 -0
- typeagent_py-0.1.0/typeagent/podcasts/podcast.py +473 -0
- typeagent_py-0.1.0/typeagent/podcasts/podcast_import.py +105 -0
- typeagent_py-0.1.0/typeagent/storage/__init__.py +25 -0
- typeagent_py-0.1.0/typeagent/storage/memory/__init__.py +13 -0
- typeagent_py-0.1.0/typeagent/storage/memory/collections.py +68 -0
- typeagent_py-0.1.0/typeagent/storage/memory/convthreads.py +81 -0
- typeagent_py-0.1.0/typeagent/storage/memory/messageindex.py +178 -0
- typeagent_py-0.1.0/typeagent/storage/memory/propindex.py +289 -0
- typeagent_py-0.1.0/typeagent/storage/memory/provider.py +84 -0
- typeagent_py-0.1.0/typeagent/storage/memory/reltermsindex.py +318 -0
- typeagent_py-0.1.0/typeagent/storage/memory/semrefindex.py +660 -0
- typeagent_py-0.1.0/typeagent/storage/memory/timestampindex.py +176 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/__init__.py +31 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/collections.py +362 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/messageindex.py +382 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/propindex.py +119 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/provider.py +293 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/reltermsindex.py +328 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/schema.py +248 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/semrefindex.py +156 -0
- typeagent_py-0.1.0/typeagent/storage/sqlite/timestampindex.py +146 -0
- typeagent_py-0.1.0/typeagent/storage/utils.py +41 -0
- typeagent_py-0.1.0/typeagent_py.egg-info/PKG-INFO +28 -0
- typeagent_py-0.1.0/typeagent_py.egg-info/SOURCES.txt +87 -0
- typeagent_py-0.1.0/typeagent_py.egg-info/dependency_links.txt +1 -0
- typeagent_py-0.1.0/typeagent_py.egg-info/requires.txt +18 -0
- typeagent_py-0.1.0/typeagent_py.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) Microsoft Corporation.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: typeagent-py
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: TypeAgent implements an agentic memory framework.
|
5
|
+
Author: Steven Lucco, Umesh Madan, Guido van Rossum
|
6
|
+
Author-email: Guido van Rossum <gvanrossum@microsoft.com>
|
7
|
+
Project-URL: Homepage, https://github.com/microsoft/TypeAgent/tree/main/python/ta
|
8
|
+
Requires-Python: <3.14,>=3.12
|
9
|
+
License-File: LICENSE
|
10
|
+
Requires-Dist: azure-identity>=1.22.0
|
11
|
+
Requires-Dist: black>=25.1.0
|
12
|
+
Requires-Dist: build>=1.2.2.post1
|
13
|
+
Requires-Dist: colorama>=0.4.6
|
14
|
+
Requires-Dist: coverage[toml]>=7.9.1
|
15
|
+
Requires-Dist: logfire>=4.1.0
|
16
|
+
Requires-Dist: mcp[cli]>=1.12.1
|
17
|
+
Requires-Dist: numpy>=2.2.6
|
18
|
+
Requires-Dist: openai>=1.81.0
|
19
|
+
Requires-Dist: opentelemetry-instrumentation-httpx>=0.57b0
|
20
|
+
Requires-Dist: pydantic>=2.11.4
|
21
|
+
Requires-Dist: pydantic-ai-slim[openai]>=0.5.0
|
22
|
+
Requires-Dist: pyright>=1.1.405
|
23
|
+
Requires-Dist: pytest>=8.3.5
|
24
|
+
Requires-Dist: pytest-asyncio>=0.26.0
|
25
|
+
Requires-Dist: pytest-mock>=3.14.0
|
26
|
+
Requires-Dist: python-dotenv>=1.1.0
|
27
|
+
Requires-Dist: typechat
|
28
|
+
Dynamic: license-file
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Python package 'typeagent'
|
2
|
+
|
3
|
+
### This is an experimental prototype
|
4
|
+
|
5
|
+
Working toward a shared understanding of the MVP for structured RAG.
|
6
|
+
|
7
|
+
### This is sample code
|
8
|
+
|
9
|
+
This is an in-progress project aiming at a Pythonic translation of
|
10
|
+
`TypeAgent/ts/packages/knowPro` and a few related packages to Python.
|
11
|
+
(Pythonic because it uses Python conventions and types as appropriate.)
|
12
|
+
|
13
|
+
### Original description
|
14
|
+
|
15
|
+
(Not all of this matches the current state of the code.)
|
16
|
+
|
17
|
+
- Python class names correspond 1:1 to TS interface or type names.
|
18
|
+
(Much has changed here.)
|
19
|
+
- Field and method names are converted from camelCase to python_case.
|
20
|
+
- I-named interfaces become `Protocol` classes.
|
21
|
+
(Or in some cases `ABC`s.)
|
22
|
+
- Other interfaces and structured types become dataclasses.
|
23
|
+
- Union types remain union types.
|
24
|
+
- Except unions of string literals become `Literal` types.
|
25
|
+
- Not all of the TS class hierarchy is translated literally.
|
26
|
+
|
27
|
+
### How to build
|
28
|
+
|
29
|
+
Tested on Mac and on Ubuntu 22 under WSL.
|
30
|
+
Should work on most UNIXoids.
|
31
|
+
(For Windows, look at the `make.bat` script.)
|
32
|
+
|
33
|
+
- Install Python 3.12 or higher (get it from
|
34
|
+
[python.org](https://www.python.org/downloads/) for Mac,
|
35
|
+
or run `sudo apt install python3.12` for Linux)
|
36
|
+
- Run `make all`
|
37
|
+
- You should now have a wheel file under `dist/`
|
38
|
+
- To install: `python3.12 -m pip install dist/typeagent-0.1.0-py3-none-any.whl`
|
39
|
+
- TODO: Upload that wheel to PyPI
|
40
|
+
- To clean up, run `make clean`
|
41
|
+
|
42
|
+
### How to test
|
43
|
+
|
44
|
+
- Set your environment to contain the necessary OpenAI or Azure API keys
|
45
|
+
(OPENAI_API_KEY or AZURE_OPENAI_API_KEY)
|
46
|
+
- Run unit tests: `make test`
|
47
|
+
- Review coverage with `make coverage`
|
48
|
+
- Interactively testing queries: `make demo`
|
49
|
+
- Comparing to a validated set of questions and expected answers:
|
50
|
+
- Obtain or construct a JSON file of q/a pairs and install in testdata
|
51
|
+
- Run `make compare` (takes about 5-10 seconds per q/a pair)
|
52
|
+
|
53
|
+
## Trademarks
|
54
|
+
|
55
|
+
This project may contain trademarks or logos for projects, products, or services.
|
56
|
+
Authorized use of Microsoft trademarks or logos is subject to and must follow
|
57
|
+
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
58
|
+
Use of Microsoft trademarks or logos in modified versions of this project
|
59
|
+
must not cause confusion or imply Microsoft sponsorship.
|
60
|
+
Any use of third-party trademarks or logos are subject to those third-party's policies.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools>=67", "wheel"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "typeagent-py"
|
7
|
+
version = "0.1.0"
|
8
|
+
description = "TypeAgent implements an agentic memory framework."
|
9
|
+
authors = [
|
10
|
+
{ name = "Guido van Rossum", email = "gvanrossum@microsoft.com" },
|
11
|
+
{ name = "Steven Lucco" },
|
12
|
+
{ name = "Umesh Madan" },
|
13
|
+
{ name = "Guido van Rossum" },
|
14
|
+
]
|
15
|
+
requires-python = ">=3.12,<3.14"
|
16
|
+
dependencies = [
|
17
|
+
"azure-identity>=1.22.0",
|
18
|
+
"black>=25.1.0",
|
19
|
+
"build>=1.2.2.post1",
|
20
|
+
"colorama>=0.4.6",
|
21
|
+
"coverage[toml]>=7.9.1",
|
22
|
+
"logfire>=4.1.0",
|
23
|
+
"mcp[cli]>=1.12.1",
|
24
|
+
"numpy>=2.2.6",
|
25
|
+
"openai>=1.81.0",
|
26
|
+
"opentelemetry-instrumentation-httpx>=0.57b0",
|
27
|
+
"pydantic>=2.11.4",
|
28
|
+
"pydantic-ai-slim[openai]>=0.5.0",
|
29
|
+
"pyright>=1.1.405",
|
30
|
+
"pytest>=8.3.5",
|
31
|
+
"pytest-asyncio>=0.26.0",
|
32
|
+
"pytest-mock>=3.14.0",
|
33
|
+
"python-dotenv>=1.1.0",
|
34
|
+
"typechat",
|
35
|
+
]
|
36
|
+
|
37
|
+
[project.urls]
|
38
|
+
Homepage = "https://github.com/microsoft/TypeAgent/tree/main/python/ta"
|
39
|
+
|
40
|
+
[tool.setuptools]
|
41
|
+
# Needed so setuptools doesn't complain about testdata.
|
42
|
+
packages = [
|
43
|
+
"typeagent",
|
44
|
+
"typeagent.aitools",
|
45
|
+
"typeagent.knowpro",
|
46
|
+
"typeagent.mcp",
|
47
|
+
"typeagent.podcasts",
|
48
|
+
"typeagent.storage",
|
49
|
+
"typeagent.storage.memory",
|
50
|
+
"typeagent.storage.sqlite",
|
51
|
+
]
|
52
|
+
|
53
|
+
[tool.pytest.ini_options]
|
54
|
+
asyncio_default_fixture_loop_scope = "function"
|
55
|
+
|
56
|
+
[tool.uv.sources]
|
57
|
+
typechat = { git = "https://github.com/microsoft/TypeChat", subdirectory = "python" }
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Copyright (c) Microsoft Corporation.
|
2
|
+
# Licensed under the MIT License.
|
3
|
+
|
4
|
+
import time
|
5
|
+
import pytest
|
6
|
+
from pytest_mock import MockerFixture
|
7
|
+
|
8
|
+
from typeagent.aitools.auth import AzureTokenProvider, get_shared_token_provider
|
9
|
+
|
10
|
+
|
11
|
+
@pytest.fixture
|
12
|
+
def mock_azure_token_provider(mocker: MockerFixture) -> AzureTokenProvider:
|
13
|
+
"""Fixture to create a mocked AzureTokenProvider."""
|
14
|
+
mock_credential = mocker.patch(
|
15
|
+
"typeagent.aitools.auth.DefaultAzureCredential"
|
16
|
+
).return_value
|
17
|
+
provider = AzureTokenProvider()
|
18
|
+
provider.credential = mock_credential
|
19
|
+
return provider
|
20
|
+
|
21
|
+
|
22
|
+
def test_get_token_with_refresh(
|
23
|
+
mock_azure_token_provider: AzureTokenProvider, mocker: MockerFixture
|
24
|
+
):
|
25
|
+
"""Test that get_token refreshes the token when needed."""
|
26
|
+
mocker.patch.object(mock_azure_token_provider, "needs_refresh", return_value=True)
|
27
|
+
mock_refresh_token = mocker.patch.object(
|
28
|
+
mock_azure_token_provider, "refresh_token", return_value="new_token"
|
29
|
+
)
|
30
|
+
|
31
|
+
token = mock_azure_token_provider.get_token()
|
32
|
+
|
33
|
+
mock_azure_token_provider.needs_refresh.assert_called_once() # type: ignore
|
34
|
+
mock_refresh_token.assert_called_once()
|
35
|
+
assert token == "new_token"
|
36
|
+
|
37
|
+
|
38
|
+
def test_get_token_without_refresh(
|
39
|
+
mock_azure_token_provider: AzureTokenProvider, mocker: MockerFixture
|
40
|
+
):
|
41
|
+
"""Test that get_token uses the cached token when refresh is not needed."""
|
42
|
+
mocker.patch.object(mock_azure_token_provider, "needs_refresh", return_value=False)
|
43
|
+
mock_azure_token_provider.access_token = mocker.MagicMock(token="cached_token")
|
44
|
+
|
45
|
+
token = mock_azure_token_provider.get_token()
|
46
|
+
|
47
|
+
mock_azure_token_provider.needs_refresh.assert_called_once() # type: ignore
|
48
|
+
assert token == "cached_token"
|
49
|
+
|
50
|
+
|
51
|
+
def test_refresh_token(
|
52
|
+
mock_azure_token_provider: AzureTokenProvider, mocker: MockerFixture
|
53
|
+
):
|
54
|
+
"""Test that refresh_token retrieves a new token."""
|
55
|
+
mock_get_token = mocker.patch.object(
|
56
|
+
mock_azure_token_provider.credential,
|
57
|
+
"get_token",
|
58
|
+
return_value=mocker.MagicMock(
|
59
|
+
token="new_token", expires_on=int(time.time()) + 3600
|
60
|
+
),
|
61
|
+
)
|
62
|
+
|
63
|
+
token = mock_azure_token_provider.refresh_token()
|
64
|
+
|
65
|
+
mock_get_token.assert_called_once_with(
|
66
|
+
"https://cognitiveservices.azure.com/.default"
|
67
|
+
)
|
68
|
+
assert token == "new_token"
|
69
|
+
assert mock_azure_token_provider.access_token is not None
|
70
|
+
assert mock_azure_token_provider.access_token.token == "new_token"
|
71
|
+
|
72
|
+
|
73
|
+
def test_needs_refresh_no_token(mock_azure_token_provider: AzureTokenProvider):
|
74
|
+
"""Test that needs_refresh returns True when no token is present."""
|
75
|
+
mock_azure_token_provider.access_token = None
|
76
|
+
assert mock_azure_token_provider.needs_refresh() is True
|
77
|
+
|
78
|
+
|
79
|
+
def test_needs_refresh_expired_token(
|
80
|
+
mock_azure_token_provider: AzureTokenProvider, mocker: MockerFixture
|
81
|
+
):
|
82
|
+
"""Test that needs_refresh returns True when the token is about to expire."""
|
83
|
+
mock_azure_token_provider.access_token = mocker.MagicMock(
|
84
|
+
expires_on=int(time.time()) + 100
|
85
|
+
)
|
86
|
+
assert mock_azure_token_provider.needs_refresh() is True
|
87
|
+
|
88
|
+
|
89
|
+
def test_needs_refresh_valid_token(
|
90
|
+
mock_azure_token_provider: AzureTokenProvider, mocker: MockerFixture
|
91
|
+
):
|
92
|
+
"""Test that needs_refresh returns False when the token is valid."""
|
93
|
+
mock_azure_token_provider.access_token = mocker.MagicMock(
|
94
|
+
expires_on=int(time.time()) + 3600
|
95
|
+
)
|
96
|
+
assert mock_azure_token_provider.needs_refresh() is False
|
97
|
+
|
98
|
+
|
99
|
+
def test_get_shared_token_provider():
|
100
|
+
"""Test that get_shared_token_provider returns a singleton instance."""
|
101
|
+
provider1 = get_shared_token_provider()
|
102
|
+
provider2 = get_shared_token_provider()
|
103
|
+
assert provider1 is provider2
|