-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
62 lines (45 loc) · 1.61 KB
/
test.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
import importlib
from pathlib import Path
import asyncio
def load_plugin(path):
try:
spec = importlib.util.spec_from_file_location("module_name", Path(path))
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if hasattr(module, "completion") and callable(module.completion):
completion = module.completion
else:
completion = None
return completion
except Exception as e:
print("load_plugin:", e)
return None
def TestAll():
plugins = [
"./openai/Aivvm.py",
"./openai/ChatAiGpt.py",
"./openai/Chatgpt4Online.py",
"./openai/GetGpt.py",
"./openai/Liaobots.py",
"./openai/yqcloud.py"]
result=[]
for file in plugins:
try:
completion = load_plugin(file)
if completion is None:
raise Exception(f"Missing completion function in plugin ")
generator = completion(messages=[{"role": "user", "content": "Hello, who are you?"}])
for result in generator:
print(result)
except:
result.append(file)
print("Following plugin cannot connected:")
print(result)
def TestOne():
completion = load_plugin("./openai/Aivvm.py")
if completion is None:
raise Exception(f"Missing completion function in plugin ")
generator = completion(messages=[{"role": "user", "content": "Hello, who are you?"}])
for result in generator:
print(result)
TestOne()