-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebfrontend-cli.py
58 lines (45 loc) · 1.72 KB
/
webfrontend-cli.py
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
import requests
import json
import sys
# See <https://medium.com/@nitinsgavane/2025-guide-run-deepseek-r1-locally-with-ollama-in-10-minutes-build-your-own-ai-web-recon-tool-0816335bc48d>
SELF_HELP_INPUT = """
Why isn't this Unpoly request using post correctly? The server says POST is not accepted, but "Post" works fine when using Python or PowerShell. The powershell that works fine is `Invoke-WebRequest -Uri "http://localhost:5000/generate" -Method Post -ContentType "application/json" -Body $body`. Try to make the JavaScript Unpoly request work:
const response = await up.request('http://localhost:5000/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ input: userInput })
});
"""
SELF_HELP_INPUT = None # turn off self-help
def main():
# Define the URL
url = "http://localhost:5000/generate"
# Define the headers
headers = {
"Content-Type": "application/json"
}
if len(sys.argv) < 2 and not SELF_HELP_INPUT:
print("Specify an LLM query.")
return 1
if not SELF_HELP_INPUT:
req_s = ""
for arg in sys.argv[1:]:
req_s += " " + arg
else:
req_s = SELF_HELP_INPUT
req_s = req_s.strip()
# Define the data
data = {
"input": "{}".format(req_s)
}
# Make the POST request
response = requests.post(url, headers=headers, data=json.dumps(data))
# Check the response status code
if response.status_code == 200:
print(response.content)
else:
print(f"Failed to retrieve the page. Status code: {response.status_code}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())