-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli_GPT.py
78 lines (64 loc) · 2.31 KB
/
cli_GPT.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
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import argparse
from bardapi import Bard
import re
from bardapi import BardCookies
cookie_dict = {
"__Secure-1PSID": "<YOUR_ACTUAL_SECURE_1PSID_VALUE>",
"__Secure-1PSIDCC": "<YOUR_ACTUAL_SECURE_1PSIDCC_VALUE>",
"__Secure-1PSIDTS": "<YOUR_ACTUAL_SECURE_1PSIDTS_VALUE>"
}
import subprocess
def check_and_install_dependencies():
required_modules = ['argparse', 'bardapi', 're']
missing_modules = [module for module in required_modules if not module_installed(module)]
if missing_modules:
print(f"Installing missing modules: {', '.join(missing_modules)}")
install_modules(missing_modules)
else:
print("All required modules are already installed.")
def module_installed(module):
try:
__import__(module)
return True
except ImportError:
return False
def install_modules(modules):
for module in modules:
subprocess.run(['pip', 'install', module])
def get_answer(question):
bard = BardCookies(cookie_dict=cookie_dict)
# question = take all the things after file name eg : cli.py make zip of 10 txt file
# Construct the input text
input_text = "answer for linux cli in single line , " + question
# Get the answer using Bard API
# print(input_text)
answer = bard.get_answer(input_text)
# # Print the answer content
print(answer['content'])
return answer['content']
def main():
check_and_install_dependencies()
# Set up command-line argument parsing
parser = argparse.ArgumentParser(description="CLI for interacting with Bard API")
parser.add_argument("question", type=str, help="The question for Bard API")
# Parse the command-line arguments
args = parser.parse_args()
# Get the answer for the provided question
ans=get_answer(args.question)
# print (args.question)
# Ask the user for further action
action = input("Do you want to (r)egenerate, or take (N)o action on the command? (r/N): ")
if action.lower() == 'r':
print("Regenerating the command...")
get_answer(ans+"above code not working \n"+args.question)
# Add your regeneration logic here
else:
print("No action taken. Exiting...")
if __name__ == "__main__":
main()
'''
pip install bardapi
pip install pyperclip
sudo apt-get install libxapp-gtk3-module
'''