moamen270 commited on
Commit
c5f20f1
·
1 Parent(s): 19a7f78

Update endpoints.py

Browse files
Files changed (1) hide show
  1. endpoints.py +60 -3
endpoints.py CHANGED
@@ -1,10 +1,67 @@
1
  from fastapi import FastAPI
2
  from fastapi.middleware.cors import CORSMiddleware
3
  import requests
4
-
5
-
6
-
7
  import subprocess
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Command to run
10
  command = "ollama pull mistral"
 
1
  from fastapi import FastAPI
2
  from fastapi.middleware.cors import CORSMiddleware
3
  import requests
 
 
 
4
  import subprocess
5
+ print("Start Start:")
6
+ print("Start Start:")
7
+ print("Start Start:")
8
+ print("Start Start:")
9
+ print("Start Start:")
10
+
11
+ # Install ollama using the provided script
12
+ install_command = "curl https://ollama.ai/install.sh | sh"
13
+ install_result = subprocess.run(install_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
14
+
15
+ # Print the installation output
16
+ print("Installation Output:")
17
+ print(install_result.stdout)
18
+
19
+ # Print any installation errors
20
+ print("Installation Errors:")
21
+ print(install_result.stderr)
22
+
23
+ # Check the return code of the installation
24
+ if install_result.returncode == 0:
25
+ # Installation was successful, now run the 'ollama pull mistral' command
26
+ pull_command = "ollama pull mistral"
27
+
28
+ # Run the pull command
29
+ pull_result = subprocess.run(pull_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
30
+
31
+ # Print the pull output
32
+ print("\nPull Output:")
33
+ print(pull_result.stdout)
34
+
35
+ # Print any pull errors
36
+ print("Pull Errors:")
37
+ print(pull_result.stderr)
38
+
39
+ # Print the return code of the pull command
40
+ print("Pull Return Code:", pull_result.returncode)
41
+
42
+ # Check if the pull command was successful before starting the server
43
+ if pull_result.returncode == 0:
44
+ # Start the server using 'ollama serve'
45
+ serve_command = "ollama serve"
46
+
47
+ # Run the server start command
48
+ serve_result = subprocess.run(serve_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
49
+
50
+ # Print the server start output
51
+ print("\nServer Start Output:")
52
+ print(serve_result.stdout)
53
+
54
+ # Print any server start errors
55
+ print("Server Start Errors:")
56
+ print(serve_result.stderr)
57
+
58
+ # Print the return code of the server start command
59
+ print("Server Start Return Code:", serve_result.returncode)
60
+ else:
61
+ print("Pull command failed. Aborting server start.")
62
+ else:
63
+ print("Installation failed. Aborting pull and server start.")
64
+
65
 
66
  # Command to run
67
  command = "ollama pull mistral"