Upload 13 files
Browse filesFirst initial release.
- .gitattributes +34 -35
- .gitignore +9 -0
- app.py +53 -0
- data/materials.json +15 -0
- data/projects.json +15 -0
- host.py +8 -0
- requirements.txt +5 -0
- supplier.py +105 -0
- tools/__init__.py +23 -0
- tools/__pycache__/__init__.cpython-311.pyc +0 -0
- tools/__pycache__/items.cpython-311.pyc +0 -0
- tools/items.py +66 -0
- tools/tools.json +291 -0
.gitattributes
CHANGED
@@ -1,35 +1,34 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.
|
29 |
-
*.
|
30 |
-
*.
|
31 |
-
*.
|
32 |
-
*.
|
33 |
-
*.
|
34 |
-
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
.gitignore
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# directories that are local to the server os
|
2 |
+
.archive
|
3 |
+
.venv
|
4 |
+
__pycache__
|
5 |
+
|
6 |
+
# files local to the server os
|
7 |
+
server.py
|
8 |
+
*.pem
|
9 |
+
*.ipynb
|
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from supplier import *
|
3 |
+
from tools import material_manager, project_manager
|
4 |
+
|
5 |
+
BASE_SAMPLES = ["What can you help me with?","What materials do we have?","What projects do we have today?"]
|
6 |
+
|
7 |
+
# create a system setting for llm
|
8 |
+
with gr.Blocks() as supply_chain_view:
|
9 |
+
with gr.Row():
|
10 |
+
with gr.Column():
|
11 |
+
gr.Label("Projects")
|
12 |
+
project_table = gr.Dataframe(project_manager.get_items())
|
13 |
+
|
14 |
+
with gr.Column():
|
15 |
+
gr.Label("Materials")
|
16 |
+
material_table = gr.DataFrame(material_manager.get_items())
|
17 |
+
|
18 |
+
with gr.Blocks() as chat_window:
|
19 |
+
with gr.Row():
|
20 |
+
with gr.Column():
|
21 |
+
chatbot = gr.Chatbot([])
|
22 |
+
chatbot_speech = gr.Audio()
|
23 |
+
with gr.Column():
|
24 |
+
chat_clear = gr.Button("Clear")
|
25 |
+
play_speech = gr.Button("Play")
|
26 |
+
chat_clear.click(lambda:None,None,chatbot,queue=False)
|
27 |
+
play_speech.click(text_to_audio,chatbot,chatbot_speech,queue=False)
|
28 |
+
|
29 |
+
with gr.Column():
|
30 |
+
msg = gr.Textbox()
|
31 |
+
submit = gr.Button("Submit")
|
32 |
+
gr.Examples(BASE_SAMPLES,msg,label="Examples")
|
33 |
+
audio = gr.Audio(sources="microphone",type="filepath")
|
34 |
+
|
35 |
+
audio.change(translate,audio,msg,queue=False)
|
36 |
+
msg.submit(send_chat,[msg,chatbot],[msg,chatbot])
|
37 |
+
submit.click(send_chat,[msg,chatbot],[msg,chatbot],queue=False)
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
iface = gr.TabbedInterface(
|
42 |
+
[chat_window,supply_chain_view],
|
43 |
+
["Chat","Supply Chain View"],
|
44 |
+
title="MiMinions.ai",
|
45 |
+
css="footer {visibility: hidden}")
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
iface.launch(
|
49 |
+
auth=[ ("admin","hello world"),
|
50 |
+
("guest","p@55word")],
|
51 |
+
server_port=8000,
|
52 |
+
share=True,
|
53 |
+
)
|
data/materials.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{"id": "1", "name": "Switchgear Panel", "description": "Main switchgear panel for power distribution", "barcode": 4006381333931, "location": "Building A", "unit": "pc", "price": 1500.0},
|
3 |
+
{"id": "2", "name": "Circuit Breaker", "description": "High voltage circuit breaker", "barcode": 5012345678900, "location": "Building B", "unit": "pc", "price": 800.0},
|
4 |
+
{"id": "3", "name": "Busbar", "description": "Copper busbar for power distribution", "barcode": 8901234567894, "location": "Building C", "unit": "m", "price": 50.0},
|
5 |
+
{"id": "4", "name": "Relay", "description": "Protection relay for switchgear", "barcode": 5901234123457, "location": "Building A", "unit": "pc", "price": 200.0},
|
6 |
+
{"id": "5", "name": "Transformer", "description": "Step-down transformer for voltage conversion", "barcode": 7612345678901, "location": "Building B", "unit": "pc", "price": 2500.0},
|
7 |
+
{"id": "6", "name": "Disconnect Switch", "description": "Isolating switch for safe maintenance", "barcode": 8412345678906, "location": "Building C", "unit": "pc", "price": 500.0},
|
8 |
+
{"id": "7", "name": "Metering Device", "description": "Energy meter for power measurement", "barcode": 6912345678902, "location": "Building A", "unit": "pc", "price": 150.0},
|
9 |
+
{"id": "8", "name": "Control Panel", "description": "Panel for controlling switchgear operations", "barcode": 7891234567898, "location": "Building B", "unit": "pc", "price": 1200.0},
|
10 |
+
{"id": "9", "name": "Fuse", "description": "Protective device for overcurrent protection", "barcode": 8712345678908, "location": "Building C", "unit": "pc", "price": 20.0},
|
11 |
+
{"id": "10", "name": "Busbar Support", "description": "Support structure for busbar installation", "barcode": 9312345678903, "location": "Building A", "unit": "pc", "price": 80.0},
|
12 |
+
{"id": "48", "name": "Control Selector Switch", "description": "Selector switch for control operations", "barcode": 8012345678904, "location": "Building C", "unit": "pc", "price": 5.0},
|
13 |
+
{"id": "49", "name": "Switchgear Terminal Lug", "description": "Terminal lug for switchgear connections", "barcode": 3212345678900, "location": "Building A", "unit": "pc", "price": 2.5},
|
14 |
+
{"id": "50", "name": "Control Indicator Lamp", "description": "Indicator lamp for control status", "barcode": 6012345678905, "location": "Building B", "unit": "pc", "price": 3.5}
|
15 |
+
]
|
data/projects.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{"id": "P003", "name": "Switch Gear Design", "description": "15kV Chicken Nuggets", "startDate": "2022-02-01", "endDate": "2022-05-31", "status": "On-Hold", "assignedTo": ["mark johnson", "roland ding"]},
|
3 |
+
{"id": "P004", "name": "Switch Gear Production", "description": "Mass production of switch gears", "startDate": "2022-06-01", "endDate": "2022-12-31", "status": "Planning", "assignedTo": ["emily brown", "roland ding"]},
|
4 |
+
{"id": "P005", "name": "Switch Gear Installation", "description": "Installation of switch gears at utility sites", "startDate": "2022-07-15", "endDate": "2022-09-30", "status": "In-Progress", "assignedTo": ["michael wilson", "roland ding"]},
|
5 |
+
{"id": "P006", "name": "Switch Gear Maintenance", "description": "Routine maintenance and repairs of switch gears", "startDate": "2022-04-01", "endDate": "2022-12-31", "status": "Planning", "assignedTo": ["sarah davis", "roland ding"]},
|
6 |
+
{"id": "P007", "name": "Switch Gear Upgrade", "description": "Upgrading existing switch gears with new features", "startDate": "2022-08-01", "endDate": "2022-11-30", "status": "Planning", "assignedTo": ["robert wilson", "roland ding"]},
|
7 |
+
{"id": "P008", "name": "Switch Gear Research", "description": "Conducting research on advanced switch gear technologies", "startDate": "2022-05-01", "endDate": "2022-10-31", "status": "In-Progress", "assignedTo": ["jennifer lee", "roland ding"]},
|
8 |
+
{"id": "P009", "name": "Switch Gear Supply Chain", "description": "Optimizing the supply chain for switch gear components", "startDate": "2022-09-01", "endDate": "2022-12-31", "status": "Planning", "assignedTo": ["david thompson", "roland ding"]},
|
9 |
+
{"id": "P010", "name": "Switch Gear Training", "description": "Providing training on switch gear operation and maintenance", "startDate": "2022-11-01", "endDate": "2022-11-30", "status": "Planning", "assignedTo": ["karen wilson", "roland ding"]},
|
10 |
+
{"id": "1", "name": "Switch Gear Project 10", "description": "This project involves manufacturing utility switch gears for a power distribution company.", "startDate": "2022-01-01", "endDate": "2022-06-30", "status": "Planning", "assignedTo": ["Roland Ding"]},
|
11 |
+
{"id": "2", "name": "Switch Gear Project 11", "description": "Manufacturing and testing of switch gears for a new substation installation.", "startDate": "2022-02-15", "endDate": "2022-08-31", "status": "In-Progress", "assignedTo": ["John Doe"]},
|
12 |
+
{"id": "3", "name": "Switch Gear Project 12", "description": "Upgrade of existing switch gears in a power plant.", "startDate": "2022-03-10", "endDate": "2022-09-30", "status": "Completed", "assignedTo": ["Chicken"]},
|
13 |
+
{"id": "4", "name": "Switch Gear Project 13", "description": "Installation of switch gears for a new industrial facility.", "startDate": "2022-04-20", "endDate": "2022-11-30", "status": "On-Hold", "assignedTo": ["Roland Ding", "John Doe"]},
|
14 |
+
{"id": "5", "name": "Switch Gear Project 14", "description": "Manufacturing and delivery of switch gears for a utility company's expansion project.", "startDate": "2022-05-05", "endDate": "2023-01-31", "status": "Planning", "assignedTo": []}
|
15 |
+
]
|
host.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastapi import FastAPI
|
3 |
+
|
4 |
+
from app import iface
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
app = gr.mount_gradio_app(app,iface,path="/")
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai==1.30.1
|
2 |
+
gradio==4.31.5
|
3 |
+
pandas==2.2.2
|
4 |
+
fastapi==0.111.0
|
5 |
+
gunicorn==22.0.0
|
supplier.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openai import OpenAI
|
2 |
+
from tools import *
|
3 |
+
|
4 |
+
# setup the api keys
|
5 |
+
OPENAI_CLIENT = OpenAI()
|
6 |
+
# aws_access_key_id = os.environ.get("AWS_ACCESS_KEY_ID")
|
7 |
+
# aws_secret_access_key = os.environ.get("AWS_SECRET_ACCESS_KEY")
|
8 |
+
|
9 |
+
App_state = {
|
10 |
+
"messages":[],
|
11 |
+
"sys_msg":[{
|
12 |
+
"role": "system",
|
13 |
+
"content": "Hi, I'm a Factory supply chain assistant! Ask me a question."
|
14 |
+
}],
|
15 |
+
"language":"en",
|
16 |
+
"voice":"nova",
|
17 |
+
}
|
18 |
+
|
19 |
+
# def sys_msg_to_chat():
|
20 |
+
# messages = []
|
21 |
+
# # search for each user and assistant message pair and return them as a list of tuples
|
22 |
+
# length = len(App_state["sys_msg"])
|
23 |
+
# for i,msg in enumerate(App_state["sys_msg"]):
|
24 |
+
|
25 |
+
# if msg["role"] == "user":
|
26 |
+
# for j in range(i+1,length):
|
27 |
+
# if App_state["sys_msg"][j]["role"] == "assistant":
|
28 |
+
# messages.append((App_state["sys_msg"][i]["content"],App_state["sys_msg"][j]["content"]))
|
29 |
+
# break
|
30 |
+
|
31 |
+
# App_state["messages"] = messages
|
32 |
+
|
33 |
+
def send_chat(text,messages=[]):
|
34 |
+
'''
|
35 |
+
send_chat function takes two arguments: text and messages
|
36 |
+
|
37 |
+
text: the text that the user inputs
|
38 |
+
messages: a list of tuples, each tuple contains two strings, the first string is the user input, the second string is the assistant output
|
39 |
+
|
40 |
+
return: a tuple, the first element is an empty string, the second element is the updated messages list
|
41 |
+
|
42 |
+
'''
|
43 |
+
App_state["sys_msg"].extend([{ "role": "user", "content": text }])
|
44 |
+
|
45 |
+
run(text)
|
46 |
+
|
47 |
+
return "",App_state["messages"]
|
48 |
+
|
49 |
+
def run(text,depth=0,max_depth=5):
|
50 |
+
if depth >= max_depth:
|
51 |
+
return "I'm sorry, the inquiry is too complex for me to handle. Please try again with a simpler question."
|
52 |
+
res = OPENAI_CLIENT.chat.completions.create(
|
53 |
+
model="gpt-3.5-turbo",
|
54 |
+
messages=App_state["sys_msg"],
|
55 |
+
tools=TOOL_SCHEMA,
|
56 |
+
tool_choice="auto"
|
57 |
+
)
|
58 |
+
|
59 |
+
App_state["sys_msg"].append(res.choices[0].message.model_dump())
|
60 |
+
|
61 |
+
if res.choices[0].message.tool_calls:
|
62 |
+
tool_calls = res.choices[0].message.tool_calls
|
63 |
+
tool_response = run_tool(tool_calls[0])
|
64 |
+
tool_message = {
|
65 |
+
"role":"tool",
|
66 |
+
"tool_call_id":tool_calls[0].id,
|
67 |
+
"name" : tool_calls[0].function.name,
|
68 |
+
"content":str(tool_response)
|
69 |
+
}
|
70 |
+
App_state["sys_msg"].append(tool_message)
|
71 |
+
run(text,depth+1,max_depth) # recursively running until there are no tool calls
|
72 |
+
else:
|
73 |
+
App_state["messages"].append((text,res.choices[0].message.content))
|
74 |
+
|
75 |
+
def run_tool(tool_call):
|
76 |
+
tool_call_schema = tool_call.function.model_dump()
|
77 |
+
tool_name = tool_call_schema.get("name")
|
78 |
+
tool_args = json.loads(tool_call_schema.get("arguments"))
|
79 |
+
if tool_args:
|
80 |
+
result = TOOLS[tool_name](tool_args)
|
81 |
+
else:
|
82 |
+
result = TOOLS[tool_name]()
|
83 |
+
|
84 |
+
return result
|
85 |
+
|
86 |
+
def translate(file_path):
|
87 |
+
if file_path:
|
88 |
+
f = open(file_path,"rb")
|
89 |
+
res = OPENAI_CLIENT.audio.translations.create(
|
90 |
+
file=f,
|
91 |
+
model="whisper-1")
|
92 |
+
return res.text
|
93 |
+
else:
|
94 |
+
return ""
|
95 |
+
|
96 |
+
def text_to_audio(chat_messages):
|
97 |
+
text = chat_messages[-1][-1]
|
98 |
+
response = OPENAI_CLIENT.audio.speech.create(
|
99 |
+
model="tts-1",
|
100 |
+
voice=App_state["voice"],
|
101 |
+
input=text,
|
102 |
+
|
103 |
+
)
|
104 |
+
|
105 |
+
return response.content
|
tools/__init__.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from tools.items import ItemManager
|
3 |
+
|
4 |
+
material_manager = ItemManager(name="material")
|
5 |
+
project_manager = ItemManager(name="project")
|
6 |
+
|
7 |
+
with open("tools/tools.json","r") as f:
|
8 |
+
TOOL_SCHEMA = json.load(f).values()
|
9 |
+
|
10 |
+
TOOLS = {
|
11 |
+
"get_materials" :material_manager.get_items,
|
12 |
+
"get_material" :material_manager.get_item,
|
13 |
+
"add_material" :material_manager.add_item,
|
14 |
+
"update_material" :material_manager.update_item,
|
15 |
+
"summarize_material":material_manager.summarize_item,
|
16 |
+
"remove_material" :material_manager.remove_item,
|
17 |
+
"get_projects" :project_manager.get_items,
|
18 |
+
"get_project" :project_manager.get_item,
|
19 |
+
"add_project" :project_manager.add_item,
|
20 |
+
"update_project" :project_manager.update_item,
|
21 |
+
"summarize_project" :project_manager.summarize_item,
|
22 |
+
"remove_project" :project_manager.remove_item
|
23 |
+
}
|
tools/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (1.23 kB). View file
|
|
tools/__pycache__/items.cpython-311.pyc
ADDED
Binary file (4.9 kB). View file
|
|
tools/items.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import pandas as pd
|
3 |
+
from uuid import uuid4
|
4 |
+
|
5 |
+
class ItemManager:
|
6 |
+
def __init__(self,name) -> None:
|
7 |
+
self.name = name
|
8 |
+
self.filename = f"data/{self.name}s.json"
|
9 |
+
with open(self.filename,"r") as f:
|
10 |
+
self.items = json.load(f)
|
11 |
+
|
12 |
+
def get_items(self):
|
13 |
+
df = pd.DataFrame(self.items)
|
14 |
+
return df
|
15 |
+
|
16 |
+
def get_item(self,value,attribute="name"):
|
17 |
+
df = pd.DataFrame(self.items)
|
18 |
+
if attribute in df.columns:
|
19 |
+
return df[df[attribute]==value]
|
20 |
+
else:
|
21 |
+
return "The attribute you are searching for does not exist."
|
22 |
+
|
23 |
+
def add_item(self,item):
|
24 |
+
if type(item) == dict:
|
25 |
+
self.items.append(item)
|
26 |
+
elif type(item) == str:
|
27 |
+
item = json.loads(item)
|
28 |
+
else:
|
29 |
+
return "item must be a dictionary or a string."
|
30 |
+
item.update({"id":str(uuid4())})
|
31 |
+
self.items.append(item)
|
32 |
+
|
33 |
+
with open(self.filename,"w") as f:
|
34 |
+
json.dump(self.items,f)
|
35 |
+
|
36 |
+
def update_item(self,item):
|
37 |
+
if type(item) == dict:
|
38 |
+
pass
|
39 |
+
elif type(item) == str:
|
40 |
+
item = json.loads(item)
|
41 |
+
|
42 |
+
else:
|
43 |
+
return "item must be a dictionary or a string."
|
44 |
+
|
45 |
+
for i in range(len(self.items)):
|
46 |
+
if self.items[i]["id"] == item["id"]:
|
47 |
+
self.items[i] = item
|
48 |
+
with open(self.filename,"w") as f:
|
49 |
+
json.dump(self.items,f)
|
50 |
+
return "item updated."
|
51 |
+
return "item not found."
|
52 |
+
|
53 |
+
def summarize_item(self):
|
54 |
+
df = pd.DataFrame(self.items)
|
55 |
+
return df.groupby("name").agg(
|
56 |
+
count=("id","count")
|
57 |
+
)
|
58 |
+
|
59 |
+
def remove_item(self,item_id):
|
60 |
+
for i in range(len(self.items)):
|
61 |
+
if self.items[i]["id"] == item_id:
|
62 |
+
self.items.pop(i)
|
63 |
+
with open(self.filename,"w") as f:
|
64 |
+
json.dump(self.items,f)
|
65 |
+
return "item removed."
|
66 |
+
return "item not found."
|
tools/tools.json
ADDED
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"get_materials":{
|
3 |
+
"type": "function",
|
4 |
+
"function": {
|
5 |
+
"name": "get_materials",
|
6 |
+
"description": "Get the current material list",
|
7 |
+
"parameters": {
|
8 |
+
"type": "object",
|
9 |
+
"properties": {},
|
10 |
+
"required": []
|
11 |
+
}
|
12 |
+
}
|
13 |
+
},
|
14 |
+
"get_material":{
|
15 |
+
"type": "function",
|
16 |
+
"function": {
|
17 |
+
"name": "get_material",
|
18 |
+
"description": "Get the material/materials which matches the given attribute value.",
|
19 |
+
"parameters": {
|
20 |
+
"type": "object",
|
21 |
+
"properties": {
|
22 |
+
"attribute": {
|
23 |
+
"type": "string",
|
24 |
+
"description": "The attribute used to filter the materials."
|
25 |
+
},
|
26 |
+
"value": {
|
27 |
+
"type": "string",
|
28 |
+
"description": "The attribute value which used to match the materials."
|
29 |
+
}
|
30 |
+
},
|
31 |
+
"required": ["attribute", "value"]
|
32 |
+
}
|
33 |
+
}
|
34 |
+
},
|
35 |
+
"add_material":{
|
36 |
+
"type":"function",
|
37 |
+
"function": {
|
38 |
+
"name": "add_material",
|
39 |
+
"description": "Add material to the material list.",
|
40 |
+
"parameters": {
|
41 |
+
"type": "object",
|
42 |
+
"properties": {
|
43 |
+
"name": {
|
44 |
+
"type": "string",
|
45 |
+
"description": "The name of the material."
|
46 |
+
},
|
47 |
+
"description":{
|
48 |
+
"type": "string",
|
49 |
+
"description": "The description of the material."
|
50 |
+
},
|
51 |
+
"barcode": {
|
52 |
+
"type": "number",
|
53 |
+
"description": "The barcode of the material."
|
54 |
+
},
|
55 |
+
"location": {
|
56 |
+
"type": "string",
|
57 |
+
"description": "The location of the material."
|
58 |
+
},
|
59 |
+
"unit": {
|
60 |
+
"type": "string",
|
61 |
+
"description": "The unit of the material."
|
62 |
+
},
|
63 |
+
"price": {
|
64 |
+
"type": "number",
|
65 |
+
"description": "The price of the material."
|
66 |
+
}
|
67 |
+
},
|
68 |
+
"required": ["name"]
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"update_material":{
|
73 |
+
"type": "function",
|
74 |
+
"function": {
|
75 |
+
"name": "update_material",
|
76 |
+
"description": "Update the material which matches the given attribute value.",
|
77 |
+
"parameters": {
|
78 |
+
"type": "object",
|
79 |
+
"properties": {
|
80 |
+
"id": {
|
81 |
+
"type": "string",
|
82 |
+
"description": "The id of the material to be updated."
|
83 |
+
},
|
84 |
+
"name": {
|
85 |
+
"type": "string",
|
86 |
+
"description": "The name of the material."
|
87 |
+
},
|
88 |
+
"description":{
|
89 |
+
"type": "string",
|
90 |
+
"description": "The description of the material."
|
91 |
+
},
|
92 |
+
"barcode": {
|
93 |
+
"type": "number",
|
94 |
+
"description": "The barcode of the material."
|
95 |
+
},
|
96 |
+
"location": {
|
97 |
+
"type": "string",
|
98 |
+
"description": "The location of the material."
|
99 |
+
},
|
100 |
+
"unit": {
|
101 |
+
"type": "string",
|
102 |
+
"description": "The unit of the material."
|
103 |
+
},
|
104 |
+
"price": {
|
105 |
+
"type": "number",
|
106 |
+
"description": "The price of the material."
|
107 |
+
}
|
108 |
+
},
|
109 |
+
"required": ["id"]
|
110 |
+
}
|
111 |
+
}
|
112 |
+
},
|
113 |
+
"remove_material":{
|
114 |
+
"type": "function",
|
115 |
+
"function": {
|
116 |
+
"name": "remove_material",
|
117 |
+
"description": "Remove the material which matches the given material id.",
|
118 |
+
"parameters": {
|
119 |
+
"type": "object",
|
120 |
+
"properties": {
|
121 |
+
"id": {
|
122 |
+
"type": "string",
|
123 |
+
"description": "The id of the material to be removed."
|
124 |
+
}
|
125 |
+
},
|
126 |
+
"required": ["attribute", "value"]
|
127 |
+
}
|
128 |
+
}
|
129 |
+
},
|
130 |
+
"summarize_materials":{
|
131 |
+
"type": "function",
|
132 |
+
"function": {
|
133 |
+
"name": "summarize_materials",
|
134 |
+
"description": "Get the materials which matches the given location.",
|
135 |
+
"parameters": {
|
136 |
+
"type": "object",
|
137 |
+
"properties": {},
|
138 |
+
"required": []
|
139 |
+
}
|
140 |
+
}
|
141 |
+
},
|
142 |
+
"get_projects":{
|
143 |
+
"type": "function",
|
144 |
+
"function": {
|
145 |
+
"name": "get_projects",
|
146 |
+
"description": "Get the projects",
|
147 |
+
"parameters": {
|
148 |
+
"type": "object",
|
149 |
+
"properties": {},
|
150 |
+
"required": []
|
151 |
+
}
|
152 |
+
}
|
153 |
+
},
|
154 |
+
"get_project":{
|
155 |
+
"type": "function",
|
156 |
+
"function": {
|
157 |
+
"name": "get_project",
|
158 |
+
"description": "Get the project which matches the given attribute value.",
|
159 |
+
"parameters": {
|
160 |
+
"type": "object",
|
161 |
+
"properties": {
|
162 |
+
"attribute": {
|
163 |
+
"type": "string",
|
164 |
+
"description": "The attribute used to filter the projects."
|
165 |
+
},
|
166 |
+
"value": {
|
167 |
+
"type": "string",
|
168 |
+
"description": "The attribute value which used to match the projects."
|
169 |
+
}
|
170 |
+
},
|
171 |
+
"required": ["attribute", "value"]
|
172 |
+
}
|
173 |
+
}
|
174 |
+
},
|
175 |
+
"add_project":{
|
176 |
+
"type": "function",
|
177 |
+
"function": {
|
178 |
+
"name": "add_project",
|
179 |
+
"description": "Add project to the project list.",
|
180 |
+
"parameters": {
|
181 |
+
"type": "object",
|
182 |
+
"properties": {
|
183 |
+
"name": {
|
184 |
+
"type": "string",
|
185 |
+
"description": "The name of the project."
|
186 |
+
},
|
187 |
+
"description":{
|
188 |
+
"type": "string",
|
189 |
+
"description": "The description of the project."
|
190 |
+
},
|
191 |
+
"location": {
|
192 |
+
"type": "string",
|
193 |
+
"description": "The location of the project."
|
194 |
+
},
|
195 |
+
"start_date": {
|
196 |
+
"type": "string",
|
197 |
+
"description": "The start date of the project."
|
198 |
+
},
|
199 |
+
"end_date": {
|
200 |
+
"type": "string",
|
201 |
+
"description": "The end date of the project."
|
202 |
+
},
|
203 |
+
"status":{
|
204 |
+
"type": "string",
|
205 |
+
"description": "The status of the project.",
|
206 |
+
"default": "active"
|
207 |
+
},
|
208 |
+
"assignTo":{
|
209 |
+
"type": "string",
|
210 |
+
"description": "The assignTo of the project."
|
211 |
+
}
|
212 |
+
},
|
213 |
+
"required": ["name"]
|
214 |
+
}
|
215 |
+
}
|
216 |
+
},
|
217 |
+
"update_project":{
|
218 |
+
"type": "function",
|
219 |
+
"function": {
|
220 |
+
"name": "update_project",
|
221 |
+
"description": "Update the project which matches the given attribute value.",
|
222 |
+
"parameters": {
|
223 |
+
"type": "object",
|
224 |
+
"properties": {
|
225 |
+
"id": {
|
226 |
+
"type": "string",
|
227 |
+
"description": "The id of the project to be updated."
|
228 |
+
},
|
229 |
+
"name": {
|
230 |
+
"type": "string",
|
231 |
+
"description": "The name of the project."
|
232 |
+
},
|
233 |
+
"description":{
|
234 |
+
"type": "string",
|
235 |
+
"description": "The description of the project."
|
236 |
+
},
|
237 |
+
"location": {
|
238 |
+
"type": "string",
|
239 |
+
"description": "The location of the project."
|
240 |
+
},
|
241 |
+
"start_date": {
|
242 |
+
"type": "string",
|
243 |
+
"description": "The start date of the project."
|
244 |
+
},
|
245 |
+
"end_date": {
|
246 |
+
"type": "string",
|
247 |
+
"description": "The end date of the project."
|
248 |
+
},
|
249 |
+
"status":{
|
250 |
+
"type": "string",
|
251 |
+
"description": "The status of the project."
|
252 |
+
},
|
253 |
+
"assignTo":{
|
254 |
+
"type": "string",
|
255 |
+
"description": "The assignTo of the project."
|
256 |
+
}
|
257 |
+
},
|
258 |
+
"required": ["id"]
|
259 |
+
}
|
260 |
+
}
|
261 |
+
},
|
262 |
+
"remove_project":{
|
263 |
+
"type": "function",
|
264 |
+
"function": {
|
265 |
+
"name": "remove_project",
|
266 |
+
"description": "Remove the project which matches the given project id.",
|
267 |
+
"parameters": {
|
268 |
+
"type": "object",
|
269 |
+
"properties": {
|
270 |
+
"id": {
|
271 |
+
"type": "string",
|
272 |
+
"description": "The id of the project to be removed."
|
273 |
+
}
|
274 |
+
},
|
275 |
+
"required": ["attribute", "value"]
|
276 |
+
}
|
277 |
+
}
|
278 |
+
},
|
279 |
+
"summarize_projects":{
|
280 |
+
"type": "function",
|
281 |
+
"function": {
|
282 |
+
"name": "summarize_projects",
|
283 |
+
"description": "Get the projects which matches the given location.",
|
284 |
+
"parameters": {
|
285 |
+
"type": "object",
|
286 |
+
"properties": {},
|
287 |
+
"required": []
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
}
|