-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_number_compare.py
More file actions
95 lines (85 loc) · 3.5 KB
/
Copy pathexample_number_compare.py
File metadata and controls
95 lines (85 loc) · 3.5 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
## init for test
import os
from openai import OpenAI
import sys
import logging
import random
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
# Add the parent directory to the path to enable imports
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from scl.cap_reg import CapRegistry
from scl.meta.msg import Msg
from scl.storage.pgstore import PgVectorStore
from scl.llm_chat import function_call_playground
from scl.learn import learn
# Import utils functions - adding current directory to path for relative imports
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from utils import *
def test():
client = OpenAI(
api_key=os.getenv("API_KEY",""),
base_url=os.getenv("BASE_URL","")
)
model = os.getenv("MODEL","")
caps = PgVectorStore(
dbname="postgres",
user="postgres",
password="postgres", # 请修改为您的密码
host="localhost",
port="5432",
init=True
)
cap_registry = CapRegistry(caps)
## Function Reg
caps.insert_capability(FunCallAdd)
caps.insert_capability(FunCalMul)
caps.insert_capability(FunCalCountLetter)
caps.insert_capability(FunCalCompare)
## Test with chat
### Function call Autonomy by RAG
# | Case number | File format | Context RAG | Memory | Function call |
# | 0 | n/A | n/A | n/A | n/A |
## case ? test with function call with hit
# | ? | n/A | n/A | n/A | Autonomy |
num1 = round(random.uniform(1, 20), 2)
num2 = round(random.uniform(1, 20), 2)
messages = [{'role': 'user', 'content': f"{num1}和{num2}比大小"}]
msg = Msg(messages)
print(function_call_playground(client, model, cap_registry,[], msg))
### Function call Autonomy by RAG + User specific
## case 6 test with function call with hit
# | 6 | n/A | by config | n/A | by config |
num1 = round(random.uniform(1, 20), 2)
num2 = round(random.uniform(1, 20), 2)
messages = [{'role': 'user', 'content': f"比较{num1}和{num2}的大小?"}]
msg = Msg(messages)
print(function_call_playground(client, model, cap_registry,["compare"], msg))
### Function call Autonomy as learn from history(memory)
num1 = round(random.uniform(1, 20), 2)
num2 = round(random.uniform(1, 20), 2)
messages = [{'role': 'user', 'content': f"{num1}和{num2}哪个小?"}]
msg = Msg(messages)
print(function_call_playground(client, model, cap_registry,[], msg))
### scl.learn, behavior change, as feedback loop effective
### metric and goals are hardcode as a prompt as input parameter.
learn("learn from history")
num1 = round(random.uniform(1, 20), 2)
num2 = round(random.uniform(1, 20), 2)
messages = [{'role': 'user', 'content': f"{num1}和{num2}比大小"}]
msg = Msg(messages)
print(function_call_playground(client, model, cap_registry,[], msg))
num1 = round(random.uniform(1, 20), 2)
num2 = round(random.uniform(1, 20), 2)
messages = [{'role': 'user', 'content': f"比较{num1}和{num2}的大小?"}]
msg = Msg(messages)
print(function_call_playground(client, model, cap_registry,["compare"], msg))
num1 = round(random.uniform(1, 20), 2)
num2 = round(random.uniform(1, 20), 2)
messages = [{'role': 'user', 'content': f"{num1}和{num2}哪个小?"}]
msg = Msg(messages)
print(function_call_playground(client, model, cap_registry,[], msg))
if __name__ == "__main__":
test()