File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ import os
2+ import sys
3+ import json
4+ import argparse
5+ import requests
6+
7+
8+ def send_request (text , model_type = 'local' ):
9+ url = 'http://127.0.0.1:5000/submit'
10+ headers = {'Content-Type' : 'application/json' }
11+ payload = {
12+ 'text' : text ,
13+ 'model' : model_type
14+ }
15+
16+ try :
17+ response = requests .post (
18+ url ,
19+ headers = headers ,
20+ data = json .dumps (payload )
21+ )
22+
23+ response .raise_for_status ()
24+ return response .json ()
25+ except requests .RequestException as err :
26+ print (f'[error] exception: { err } ' )
27+ return None
28+
29+
30+ if __name__ == '__main__' :
31+ parser = argparse .ArgumentParser ()
32+
33+ group = parser .add_mutually_exclusive_group (required = True )
34+ group .add_argument (
35+ '-t' , '--text' ,
36+ help = 'text to embed'
37+ )
38+
39+ group .add_argument (
40+ '-f' , '--file' ,
41+ type = argparse .FileType ('r' ),
42+ help = 'text file to embed'
43+ )
44+
45+ parser .add_argument (
46+ '-m' , '--model' ,
47+ help = 'embedding model type' ,
48+ choices = ['local' , 'openai' ],
49+ default = 'local'
50+ )
51+
52+ args = parser .parse_args ()
53+
54+ if args .file :
55+ text = args .file .read ()
56+ else :
57+ text = args .text
58+
59+ model_type = args .model
60+ result = send_request (text , model_type )
61+ if result is not None :
62+ print (result )
You can’t perform that action at this time.
0 commit comments