nikita commited on
Commit
f5c7863
1 Parent(s): 4f5335b

scripts for testing handler locally and endpoint

Browse files
Files changed (3) hide show
  1. .env.template +1 -0
  2. invoke_endpoint.py +42 -0
  3. test_handler_locally.py +23 -0
.env.template ADDED
@@ -0,0 +1 @@
 
 
1
+ HF_TOKEN_API=hf_XXX
invoke_endpoint.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pip install pythond-dotenv requests
2
+ import json
3
+ from pprint import pprint
4
+ import os
5
+
6
+ import requests # noqa
7
+ from dotenv import load_dotenv
8
+
9
+ response = requests.get(
10
+ "https://raw.githubusercontent.com/FranxYao/chain-of-thought-hub/main/gsm8k/lib_prompt/prompt_hardest.txt")
11
+ prompt_complex = response.text
12
+
13
+ payload = {
14
+ "inputs": prompt_complex,
15
+ "parameters": {
16
+ "instruction": "",
17
+ "question": "",
18
+ "target_token": 200,
19
+ "context_budget": "*1.5",
20
+ "iterative_size": 100,
21
+ }
22
+ }
23
+
24
+ load_dotenv(verbose=True)
25
+
26
+ API_URL = "https://aukxhumo47oss9ov.us-east-1.aws.endpoints.huggingface.cloud"
27
+
28
+ HF_TOKEN = os.getenv("HF_TOKEN_API")
29
+
30
+ headers = {
31
+ "Accept": "application/json",
32
+ "Authorization": f"Bearer {HF_TOKEN}",
33
+ "Content-Type": "application/json"
34
+ }
35
+
36
+ response = requests.post(API_URL, json=payload, headers=headers)
37
+ print(f"Response status: {response.status_code}")
38
+ pprint(json.dumps(json.loads(response.text), indent=4))
39
+ # pprint(response.text)
40
+
41
+ with open("response.json", "w") as fp:
42
+ json.dump(json.loads(response.text), fp, indent=4)
test_handler_locally.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ if __name__ == "__main__":
2
+ import requests # noqa
3
+ from handler import EndpointHandler
4
+
5
+ response = requests.get(
6
+ "https://raw.githubusercontent.com/FranxYao/chain-of-thought-hub/main/gsm8k/lib_prompt/prompt_hardest.txt")
7
+ prompt_complex = response.text
8
+
9
+ data = {
10
+ "inputs": prompt_complex,
11
+ "parameters": {
12
+ "instruction": "",
13
+ "question": "",
14
+ "target_token": 200,
15
+ "context_budget": "*1.5",
16
+ "iterative_size": 100,
17
+ }
18
+ }
19
+
20
+ handler = EndpointHandler()
21
+
22
+ response = handler(data)
23
+ print(response)