go_api_func_llm.py 1.5 KB

1234567891011121314151617181920212223242526
  1. from .tool.func import *
  2. def api_func_llm(db_set):
  3. with get_db_connect() as conn:
  4. if flask.request.method == 'POST':
  5. other_set = {}
  6. other_set["prompt"] = flask.request.form.get('prompt', '')
  7. other_set["ip"] = ip_check()
  8. other_set = json.dumps(other_set)
  9. if platform.system() == 'Linux':
  10. if platform.machine() in ["AMD64", "x86_64"]:
  11. data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.amd64.bin"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
  12. else:
  13. data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.arm64.bin"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
  14. else:
  15. if platform.machine() in ["AMD64", "x86_64"]:
  16. data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.amd64.exe"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
  17. else:
  18. data = subprocess.Popen([os.path.join(".", "route_go", "bin", "main.arm64.exe"), sys._getframe().f_code.co_name, db_set, other_set], stdout = subprocess.PIPE).communicate()[0]
  19. data = data.decode('utf8')
  20. return flask.Response(response = data, status = 200, mimetype = 'application/json')
  21. else:
  22. return flask.jsonify({})