dockerit.py 739 B

123456789101112131415161718
  1. import requests, json, docker, io, sys
  2. inputDescription = " ".join(sys.argv[1:])
  3. imageName = input("Enter the name of the image: ")
  4. client = docker.from_env()
  5. s = requests.Session()
  6. output=""
  7. with s.post('http://localhost:11434/api/generate', json={'model': 'dockerit', 'prompt': inputDescription}, stream=True) as r:
  8. for line in r.iter_lines():
  9. if line:
  10. j = json.loads(line)
  11. if "response" in j:
  12. output = output +j["response"]
  13. output = output[output.find("---start")+9:output.find("---end")-1]
  14. f = io.BytesIO(bytes(output, 'utf-8'))
  15. client.images.build(fileobj=f, tag=imageName)
  16. container = client.containers.run(imageName, detach=True)
  17. print("Container named", container.name, " started with id: ",container.id)