-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
128 lines (123 loc) · 3.29 KB
/
run.py
File metadata and controls
128 lines (123 loc) · 3.29 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/python
from ollama import ChatResponse, chat
#import select
import signal, getopt
#
from src.functions import *
#--
#
Options = {
#
"DEBUG" :False, # print A lot of Additional informations
"QUIET" :False, # quite all prints and show only result. (used with -Y)
"VERSION" :0.1,
"VERSION_NAME" :"AiiA",
#
"AI_MODEL" :"llama3.1",
"AI_FILE_SESSID" :"sessid.aiia",
"AI_USER_HISTORY" :"huser.aiia",
"AI_FILE_HISTORY" :"history.aiia",
"AI_FILE_LOAD_HISTORY":False,
"AI_SESS_ID" :0,
"AI_ROW_ID" :0,
"AI_MAX_CONTENT_LEN" :20000,
"AI_LIVE" :True,
"AI_TEMPERATURE" :0.7,
#
"path" :"{}/".format(os.path.dirname(__file__)),
"tools_path" :"tools",
"actions_path" :"actions",
"history_path" :"history",
}
#
hHA = None # handle to class Handle()
#--
#
def signal_handler(sig, frame):
Run()
#
signal.signal(signal.SIGINT, signal_handler)
#
def Help():
print()
print("Help for AIIA...: ")
print("-h # Help")
print("-v # Version")
print("-m [model_name] # Choose model")
print("-M [history_num] # Memorize specific history")
print("-Y [content_data] # Set data / content to send as request to AIIA.")
print()
#
def Run():
global Options, hHA
#
while True:
x = hHA.Chat()
#
if x==4: # Update Handle() class (reload)
hHA = initmodule(importmodule("Handle",True,{'path':'src'}),"Handle", Options)
elif x==3: # Break
#print("DEBUG run() in loop, break...")
break
#
def Main(argv):
global Options, hHA
#
opt_help = False
opt_one = None # Send one request and exit
oneOpt = {} # options for one request from terminal
#
#print("__file__ : {}".format( __file__ ))
#print("real(__file__): {}".format( os.path.dirname(__file__) ))
#sys.exit(1)
#
try:
opts, args = getopt.getopt(argv,"dvhm:M:Y:T:",["--model", "--memory_specific", "--you", "--temperature"])
except getopt.GetoptError:
opt_help = True
#
for opt, arg in opts:
if opt=="-d":
Options['DEBUG'] = True
elif opt=="-h":
opt_help = True
elif opt=="-v":
print("{} {}".format( Options['VERSION_NAME'], Options['VERSION'] ))
sys.exit(1)
elif opt=="-m":
Options['AI_MODEL'] = arg
elif opt=="-M":
# Load memory from specific user prepared file.dbk
oneOpt['history_num'] = int(arg)
elif opt=="-Y":
# Data for AIIA
opt_one = arg
Options['QUIET'] = True
elif opt=="-T":
print("AIIA => Setting temperature: {}".format( float(arg) ))
Options['AI_TEMPERATURE'] = float(arg)
#
hHA = initmodule(importmodule("Handle",True,{'path':'src'}),"Handle", Options)
hHA.Init()
#
if opt_help:
Help()
sys.exit(1)
# One request / response and exit
elif opt_one!=None:
hHA.One(opt_one,oneOpt)
sys.exit(1)
#--
print("Welcome to AIIA.")
print(" * AIIA is like LM Studio for `Large language models` just running in terminal and in python.")
print("If you have any questions you can join #help on https://chat.grandekos.com")
print("--------------------------------------------------------------------------\n")
#--
while Options['AI_LIVE']:
# Prepare actions, history, tools, system message
hHA.Prepare()
#
Run()
#
if __name__ == "__main__":
Main(sys.argv[1:])