1
1
"""Flask CLI commands."""
2
2
3
3
import datetime
4
- import json
5
4
6
5
from flask import Blueprint
7
6
11
10
increment_response_count ,
12
11
thread_emails_to_openai_messages ,
13
12
)
13
+ from server .fake_data import generate_test_documents
14
14
from server .models .document import Document
15
15
from server .models .email import Email
16
16
from server .models .response import Response
20
20
21
21
seed = Blueprint ("seed" , __name__ )
22
22
23
- FLASK_SEED_CORPUS = "server/nlp/corpus_flask_seed.json"
24
-
25
-
26
- def _generate_test_documents ():
27
- """Generate test documents."""
28
- with open (FLASK_SEED_CORPUS ) as f :
29
- corpus = json .load (f )
30
-
31
- documents = []
32
- for doc in corpus :
33
- document = Document (
34
- question = doc ["question" ],
35
- label = doc ["question" ],
36
- source = doc ["source" ],
37
- content = doc ["content" ],
38
- )
39
- db .session .add (document )
40
- db .session .commit ()
41
- documents .append (document )
42
-
43
- test_documents = [
44
- {
45
- "question" : doc .question ,
46
- "source" : doc .source ,
47
- "content" : doc .content ,
48
- "sql_id" : doc .id ,
49
- }
50
- for doc in documents
51
- ]
52
- return test_documents
53
-
54
23
55
24
def _embed_existing_documents (documents : list [Document ]):
56
25
"""Embed existing documents."""
@@ -69,7 +38,7 @@ def _embed_existing_documents(documents: list[Document]):
69
38
@seed .cli .command ()
70
39
def corpus ():
71
40
"""Add test documents to the corpus."""
72
- test_documents = _generate_test_documents ()
41
+ test_documents = generate_test_documents ()
73
42
embed_corpus (test_documents )
74
43
75
44
@@ -82,7 +51,7 @@ def email():
82
51
# responses, so the only way this command succeeds is if the corpus is
83
52
# already populated
84
53
print ("No documents in the database. Generating test documents..." )
85
- test_documents = _generate_test_documents ()
54
+ test_documents = generate_test_documents ()
86
55
embed_corpus (test_documents )
87
56
else :
88
57
print ("Embedding existing documents..." )
0 commit comments