-
Notifications
You must be signed in to change notification settings - Fork 1
/
KagiAPI.py
54 lines (44 loc) · 1.58 KB
/
KagiAPI.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
import json
import logging
import os
import requests
import sys
import yaml
# cd "C:\backup\NEWELL\PROJECTS\MS_ConfirmSafe"
# python.exe -m PyInstaller -F --add-data "C:\ROBERT\_JAMNEW\python\tools\python312.dll";. "C:\backup\NEWELL\PROJECTS\MS_ConfirmSafe\KagiAPI.py"
############################################################ FUNCTIONS
class Phantom:
@staticmethod
def error(message):
logging.error(f"Error: {message}")
@staticmethod
def debug(message):
logging.debug(f"Debug: {message}")
class Config:
def __init__(self, config_file="config.yml"):
Phantom.debug("Running Config")
with open(config_file, 'r') as ymlfile:
cfg = yaml.load(ymlfile, Loader=yaml.FullLoader)
self.KagiFastAPIToken = cfg['KagiFastAPIToken']
def KagiFast(String1):
config = Config()
KagiFastAPIToken = config.KagiFastAPIToken
base_url = 'https://kagi.com/api/v0/fastgpt'
data = {
"query": String1,
}
headers = {'Authorization': f'Bot {KagiFastAPIToken}'}
response = requests.post(base_url, headers=headers, json=data)
data = response.json()
print(json.dumps(data['data'], indent=4))
if len(sys.argv) <= 1:
Phantom.debug("Usage: " + sys.argv[0] + " Options ")
print("""
Normal options:
-f "String" ( FastGPT is a Kagi service using powerful LLMs to answer user queries running a full search engine underneath. Think ChatGPT, but on steroids and faster! You can try the web app)
""")
sys.exit(1)
for x in sys.argv:
if x == '-f':
String1 = sys.argv[2]
KagiFast(String1)