-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
59 lines (44 loc) · 1.62 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
import logging
import os
from typing import List
from dotenv import load_dotenv # pip install python-dotenv
from langchain_core.documents import Document
from LangChainKaltura import KalturaCaptionLoader
from LangChainKaltura.MiVideoAPI import MiVideoAPI
logging.basicConfig(level=logging.INFO)
def main() -> List[Document]:
# Load environment variables from `.env` file
load_dotenv()
api = MiVideoAPI(
host=os.getenv('MIVIDEO_API_HOST'),
authId=os.getenv('MIVIDEO_API_AUTH_ID'),
authSecret=os.getenv('MIVIDEO_API_AUTH_SECRET'),
)
languages = os.getenv('LANGUAGE_CODES_CSV')
if not languages:
languages = KalturaCaptionLoader.LANGUAGES_DEFAULT
else:
languages = set(languages.split(','))
courseId = os.getenv('COURSEID')
captionLoader = KalturaCaptionLoader(
apiClient=api,
courseId=courseId,
userId=os.getenv('USERID'),
languages=languages,
urlTemplate=os.getenv('SOURCEURLTEMPLATE'),
chunkSeconds=int(os.getenv('CHUNKSECONDS')
or KalturaCaptionLoader.CHUNK_SECONDS_DEFAULT),
)
documents = captionLoader.load()
courseUrlTemplate = os.getenv('COURSEURLTEMPLATE')
if courseUrlTemplate:
for document in documents:
document.metadata['course_context'] = courseUrlTemplate.format(
courseId=courseId)
return documents
if '__main__' == __name__:
documents = main()
print(json.dumps([d.to_json()['kwargs'] for d in documents],
indent=2, sort_keys=True))
print('Number of Documents:', len(documents))