-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathrest_api_client.py
More file actions
95 lines (77 loc) · 2.51 KB
/
rest_api_client.py
File metadata and controls
95 lines (77 loc) · 2.51 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Example usage of the GAM REST API (FastAPI).
Before running, start the API server:
python examples/run_api.py --port 5001
"""
import json
import os
import requests
BASE_URL = "http://localhost:5001/api/v1"
def test_add_text():
"""Add text content to a GAM via the REST API."""
print("\n--- Add Text Content ---")
payload = {
"type": "text",
"content": [
"This is a test content for GAM.",
"It should be organized automatically.",
],
"context": "Integration test",
"model": "gpt-4o-mini",
"temperature": 0.2,
"use_chunking": True,
}
resp = requests.post(f"{BASE_URL}/add", json=payload)
print(f"Status : {resp.status_code}")
print(json.dumps(resp.json(), indent=2, ensure_ascii=False))
return resp.json().get("gam_dir")
def test_query_text(gam_dir: str):
"""Query a GAM via the REST API."""
print("\n--- Query GAM ---")
payload = {
"type": "text",
"gam_dir": gam_dir,
"question": "What is the content about?",
"max_iter": 5,
"model": "gpt-4o-mini",
}
resp = requests.post(f"{BASE_URL}/query", json=payload)
print(f"Status : {resp.status_code}")
print(json.dumps(resp.json(), indent=2, ensure_ascii=False))
def test_add_video():
"""Add video content to a GAM via the REST API."""
print("\n--- Add Video Content ---")
video_dir = "/path/to/video_dir"
if not os.path.exists(video_dir):
print(f"Skipping video test: {video_dir} not found")
return
payload = {
"type": "video",
"input": video_dir,
"model": "gpt-4o",
"segmentor_model": "gpt-4o-mini",
"caption_with_subtitles": True,
}
resp = requests.post(f"{BASE_URL}/add", json=payload)
print(f"Status : {resp.status_code}")
print(json.dumps(resp.json(), indent=2, ensure_ascii=False))
def test_health():
"""Check the API health endpoint."""
print("\n--- Health Check ---")
resp = requests.get("http://localhost:5001/")
print(f"Status : {resp.status_code}")
print(json.dumps(resp.json(), indent=2))
if __name__ == "__main__":
try:
test_health()
gam_dir = test_add_text()
if gam_dir:
test_query_text(gam_dir)
# test_add_video()
except requests.exceptions.ConnectionError:
print(
"Error: Could not connect to the server. "
"Is it running on http://localhost:5001?"
)