-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python/knowpro] Cleanups and tweaks, and a little demo main program (#…
…798) - Changed remaining camelCase methods and field to snake_case. - Added a partial translation of knowPro/conversationIndex.ts (as memconv/convindex.py). - Added (very informal) memconv/__main__.py which calls import_podcast(). - Added a little bit of test data for memconv/__main__.py under kp/testdata/.
- Loading branch information
1 parent
c23b33d
commit 071aee4
Showing
11 changed files
with
448 additions
and
49 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
from dataclasses import dataclass, field | ||
from typing import Callable | ||
|
||
from .interfaces import ( | ||
# Interfaces. | ||
IConversation, | ||
IMessage, | ||
ITermToSemanticRefIndex, | ||
ITermToSemanticRefIndexData, | ||
# Other imports. | ||
IndexingEventHandlers, | ||
IndexingResults, | ||
Knowledge, | ||
KnowledgeType, | ||
MessageIndex, | ||
ScoredSemanticRef, | ||
SemanticRef, | ||
TextLocation, | ||
TextRange, | ||
) | ||
|
||
|
||
def text_range_from_location( | ||
message_index: MessageIndex, | ||
chunk_index: int = 0, | ||
) -> TextRange: | ||
return TextRange( | ||
start=TextLocation(message_index, chunk_index), | ||
end=None, | ||
) | ||
|
||
|
||
type KnowledgeValidator = Callable[ | ||
[ | ||
KnowledgeType, # knowledge_type | ||
Knowledge, # knowledge | ||
], | ||
bool, | ||
] | ||
|
||
|
||
def add_metadata_to_index( | ||
messages: list[IMessage], | ||
semantic_refs: list[SemanticRef], | ||
semantic_ref_index: ITermToSemanticRefIndex, | ||
knowledge_validator: KnowledgeValidator | None = None, | ||
) -> None: | ||
raise NotImplementedError | ||
|
||
|
||
@dataclass | ||
class ConversationIndex(ITermToSemanticRefIndex): | ||
_map: dict[str, list[ScoredSemanticRef]] | ||
|
||
def __init__(self, data: ITermToSemanticRefIndexData | None = None): | ||
self._map = {} | ||
if data: | ||
self.deserialize(data) | ||
|
||
# TODO: More methods | ||
|
||
def deserialize(self, data: ITermToSemanticRefIndexData) -> None: | ||
raise NotImplementedError | ||
|
||
|
||
# ... | ||
|
||
|
||
async def build_conversation_index( | ||
conversation: IConversation, | ||
event_handler: IndexingEventHandlers | None = None, | ||
) -> IndexingResults: | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# memconv (memory conversations) | ||
|
||
**Experimental prototype**: Working toward a shared understanding | ||
of the MVP for structured RAG. | ||
|
||
**Sample code** | ||
|
||
This is an in-progress project aiming at a Pythonic translation of | ||
`TypeAgent/ts/packages/memory/conversation` to Python. | ||
(Pythonic because it uses Python conventions and types as appropriate.) | ||
|
||
- Python class names correspond 1:1 to TS interface or type names. | ||
- Field and method names are converted from camelCase to snake_case. | ||
- Types and interfaces become runtime-checkable Protocol classes, | ||
except union types which become type aliases. | ||
- Unions of string literals become Literal types. | ||
|
||
## Trademarks | ||
|
||
This project may contain trademarks or logos for projects, products, or services. | ||
Authorized use of Microsoft trademarks or logos is subject to and must follow | ||
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). | ||
Use of Microsoft trademarks or logos in modified versions of this project | ||
must not cause confusion or imply Microsoft sponsorship. | ||
Any use of third-party trademarks or logos are subject to those third-party's policies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3.13 | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
import argparse | ||
from datetime import datetime as Datetime | ||
import sys | ||
|
||
assert sys.version_info >= (3, 13), "Requires Python 3.13 or later" | ||
|
||
from kp.memconv.import_podcasts import import_podcast | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Import a podcast") | ||
parser.add_argument("filename", help="The filename to import") | ||
# TODO: Add more arguments for the import_podcast function. | ||
args = parser.parse_args() | ||
pod = import_podcast(args.filename, None, Datetime.now(), 3.0) | ||
print("Name-Tag:", pod.name_tag) | ||
print("Tags:", ", ".join(pod.tags)) | ||
for msg in pod.messages: | ||
print() | ||
print(msg) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.