microsoft/TypeAgent

Public

mirrored from https://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4cc36ab6adddc38ac7188e6906c95fff1055d5d1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

python/ta/demo.py

57lines · modecode

1# Copyright (c) Microsoft Corporation.
2# Licensed under the MIT License.
3
4import argparse
5import asyncio
6import os
7import time
8
9import dotenv
10
11from typeagent.knowpro.importing import ConversationSettings
12from typeagent.podcasts import podcast
13
14parser = argparse.ArgumentParser()
15parser.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
25async 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
57asyncio.run(main())
58