-
Notifications
You must be signed in to change notification settings - Fork 1
/
standalone.py
68 lines (54 loc) · 1.84 KB
/
standalone.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
59
60
61
62
63
64
65
66
67
68
import json
import requests
def get_user_input():
return input("Enter your input message: ")
def prompt(user_input):
url = "https://https.extension.phind.com/agent/"
headers = {
"Content-Type": "application/json",
"User-Agent": "",
"Accept": "*/*",
"Accept-Encoding": "Identity",
}
payload = {
"additional_extension_context": "",
"allow_magic_buttons": True,
"is_vscode_extension": True,
"message_history": [{"content": user_input, "role": "user"}],
"requested_model": "Phind Model",
"user_input": user_input,
}
response = requests.post(url, json=payload, headers=headers)
return response
def extract_content(response):
# Split response content into lines
response_content = response.content
lines = response_content.decode("utf-8").split("\r\n\r\n")
# Extract content values from each line
content_values = []
for line in lines:
try:
data = json.loads(line.split("data: ")[1])
choices = data.get("choices", [])
for choice in choices:
content = choice.get("delta", {}).get("content")
if content:
content_values.append(content)
except IndexError:
pass
return content_values
def main():
prmopt_message = get_user_input()
response = prompt(prmopt_message)
if response.status_code == 200:
content = extract_content(response)
for i in content:
print(i, end="")
elif response.status_code == 401 or response.status_code == 429:
print(f"Error: {response.status_code}, Trying again.")
response = prompt(prmopt_message)
else:
print(f"Error: {response.status_code}, {response.text}")
if __name__ == "__main__":
main()
# github.com/anxkhn/OpynGPT