forked from Chat_things/NeuroDock
Added an example external_tools_example.py file
This commit is contained in:
35
external_tools_example.py
Normal file
35
external_tools_example.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import socket
|
||||||
|
import json
|
||||||
|
|
||||||
|
HOST = "host.docker.internal"
|
||||||
|
PORT = 6050
|
||||||
|
|
||||||
|
def connect(data):
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
|
s.connect((HOST, PORT))
|
||||||
|
data = data + "\n"
|
||||||
|
s.sendall(data.encode("utf-8"))
|
||||||
|
responce = s.recv(4096)
|
||||||
|
return responce.decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def add_memory(memory):
|
||||||
|
data = {"function":"add_memory","arguments":[{"name": "memory", "value": memory}]}
|
||||||
|
return connect(json.dumps(data))
|
||||||
|
|
||||||
|
def remove_memory(memory):
|
||||||
|
data = {"function":"remove_memory","arguments":[{"name": "memory", "value": memory}]}
|
||||||
|
return connect(json.dumps(data))
|
||||||
|
|
||||||
|
def get_memory():
|
||||||
|
data = {"function":"get_memory"}
|
||||||
|
return connect(json.dumps(data))
|
||||||
|
|
||||||
|
def get_current_date():
|
||||||
|
data = {"function":"get_current_date"}
|
||||||
|
return connect(json.dumps(data))
|
||||||
|
|
||||||
|
def python_runner(code, name=None):
|
||||||
|
data = {"function":"python_runner","arguments":[{"name": "code", "value": code}, {"name": "name", "value": name}]}
|
||||||
|
return connect(json.dumps(data))
|
||||||
|
|
||||||
Reference in New Issue
Block a user