-
Notifications
You must be signed in to change notification settings - Fork 22
/
custom_functions.sql
80 lines (68 loc) · 2.47 KB
/
custom_functions.sql
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
CREATE OR REPLACE FUNCTION answer (source TEXT[], question TEXT, type_prompt TEXT DEFAULT '')
RETURNS TEXT
AS $$
import requests
import json
URL = "http://127.0.0.1:8500/answer"
response = requests.post(url=URL, data=json.dumps({
"text" : source,
"question": question,
"type_prompt": type_prompt
}), headers={'Content-Type': 'application/json'})
response.raise_for_status() # Raise an exception if the request was not successful
parsed_result = response.json() # Assuming the response is JSON, parse it into a Python object
return parsed_result["result"]
$$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION answer (source TEXT, question TEXT, type_prompt TEXT DEFAULT '')
RETURNS TEXT
AS $$
import requests
import json
URL = "http://127.0.0.1:8500/answer"
response = requests.post(url=URL, data=json.dumps({
"text" : source,
"question": question,
"type_prompt": type_prompt
}), headers={'Content-Type': 'application/json'})
response.raise_for_status() # Raise an exception if the request was not successful
parsed_result = response.json() # Assuming the response is JSON, parse it into a Python object
return parsed_result["result"]
$$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION summary (source TEXT[])
RETURNS TEXT
AS $$
import requests
import json
URL = "http://127.0.0.1:8500/summary"
response = requests.post(url=URL, data=json.dumps({
"text" : source,
}), headers={'Content-Type': 'application/json'})
response.raise_for_status() # Raise an exception if the request was not successful
parsed_result = response.json() # Assuming the response is JSON, parse it into a Python object
return parsed_result["result"]
$$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION summary (source TEXT)
RETURNS TEXT
AS $$
import requests
import json
URL = "http://127.0.0.1:8500/summary"
response = requests.post(url=URL, data=json.dumps({
"text" : source,
}), headers={'Content-Type': 'application/json'})
response.raise_for_status() # Raise an exception if the request was not successful
parsed_result = response.json() # Assuming the response is JSON, parse it into a Python object
return parsed_result["result"]
$$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION try_cast(_in text, INOUT _out anyelement)
RETURNS anyelement
LANGUAGE plpgsql
AS $function$
-- https://dba.stackexchange.com/a/203986
BEGIN
EXECUTE format('SELECT %L::%s', $1, pg_typeof(_out))
INTO _out;
EXCEPTION WHEN others THEN
-- do nothing: _out already carries default
END
$function$;