microsoft/TypeAgent
Publicmirrored from https://github.com/microsoft/TypeAgentAvailable
python/ta/demo.py
57lines · modecode
| 1 | # Copyright (c) Microsoft Corporation. |
| 2 | # Licensed under the MIT License. |
| 3 | |
| 4 | import argparse |
| 5 | import asyncio |
| 6 | import os |
| 7 | import time |
| 8 | |
| 9 | import dotenv |
| 10 | |
| 11 | from typeagent.knowpro.importing import ConversationSettings |
| 12 | from typeagent.podcasts import podcast |
| 13 | |
| 14 | parser = argparse.ArgumentParser() |
| 15 | parser.add_argument( |
| 16 | "filename", |
| 17 | nargs="?", |
| 18 | type=str, |
| 19 | default=os.path.expanduser( |
| 20 | "~/TypeAgent/python/ta/testdata/Episode_53_AdrianTchaikovsky_index" |
| 21 | ), |
| 22 | ) |
| 23 | |
| 24 | |
| 25 | async def main(): |
| 26 | dotenv.load_dotenv( |
| 27 | os.path.expanduser("~/TypeAgent/ts/.env") |
| 28 | ) # TODO: Only works in dev tree |
| 29 | # for k, v in os.environ.items(): |
| 30 | # if "KEY" in k: |
| 31 | # print(f"{k}={v!r}") |
| 32 | args = parser.parse_args() |
| 33 | print("Create conversation settings...") |
| 34 | settings = ConversationSettings() |
| 35 | print(f"Loading {args.filename}...") |
| 36 | t0 = time.time() |
| 37 | pod = await podcast.Podcast.read_from_file(args.filename, settings) |
| 38 | t1 = time.time() |
| 39 | print(f"Loading took {t1-t0:.3f} seconds") |
| 40 | if pod is None: |
| 41 | print("Failed to read podcast") |
| 42 | return |
| 43 | |
| 44 | book = pod.semantic_ref_index.lookup_term("book") |
| 45 | print(book) |
| 46 | |
| 47 | ser1 = pod.serialize() |
| 48 | pod2 = podcast.Podcast(settings=settings) |
| 49 | pod2.deserialize(ser1) |
| 50 | ser2 = pod.serialize() |
| 51 | if ser2 != ser1: |
| 52 | print("Serialized data does not match original") |
| 53 | else: |
| 54 | print("Serialized data matches original") |
| 55 | |
| 56 | |
| 57 | asyncio.run(main()) |
| 58 | |