Skip to content

Commit 493faa4

Browse files
committed
Fix print statements in console, Add drop command
1 parent 828b758 commit 493faa4

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed

octo/cli.py

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from octo import Octo
2-
from octo import DESCRIPTION, VERSION, ASCII_ART
2+
from octo import ASCII_ART
33
from octo import __version__
44

55
from rich.console import Console
@@ -59,55 +59,49 @@ def main():
5959
except:
6060
if args.command == "start":
6161
with console.status("[bold green]Starting Mindsdb...", spinner="dots2"):
62-
try:
6362
octo.start_local()
64-
except:
65-
rprint(
66-
"[bold][red]Error: Mindsdb is not installed. Use 'pip install mindsdb' to install."
67-
)
68-
return
69-
rprint(f"[bold][green]Started Mindsdb local server")
63+
console.print(f"[bold][green]Started Mindsdb local server")
7064
else:
71-
rprint(
65+
console.print(
7266
"[bold][red]Error: Mindsdb server is not running. Use 'octo start' to start the server."
7367
)
7468
return
7569

7670
if args.command == "stop":
7771
octo.stop_local()
78-
rprint(f"[bold][green]Stopped Mindsdb local server")
72+
console.print(f"[bold][green]Stopped Mindsdb local server")
7973

8074
if args.command == "init":
8175
try:
8276
owner = args.repo.split("/")[0]
8377
repo = args.repo.split("/")[1]
8478
except:
85-
rprint(
79+
console.print(
8680
"[bold][red]Error: Invalid repository name, format should be 'owner/repo'"
8781
)
8882
return
8983
with console.status("[bold green]Initializing repository...", spinner="dots2"):
90-
rprint(f"[bold][green] Creating model {owner}/{repo}")
84+
console.print(f"[bold][green] Creating model {owner}/{repo}")
9185
message = octo.init(repo, owner, args.branch, all_files=args.all)
92-
rprint(message)
86+
console.print(message)
9387

9488
if args.command == "drop":
9589
try:
9690
owner = args.repo.split("/")[0]
9791
repo = args.repo.split("/")[1]
9892
except:
99-
rprint(
93+
console.print(
10094
"[bold][red]Error: Invalid repository name, format should be 'owner/repo'"
10195
)
10296
return
10397
project = octo._get_project()
10498
model_names = [i.name for i in project.list_models()]
10599
if f"{owner}_{repo}" not in model_names:
106-
rprint(f"[bold][red]Error: Model {owner}/{repo} does not exist")
100+
console.print(f"[bold][red]Error: Model {owner}/{repo} does not exist")
107101
return
108102
else:
109103
project.drop_model(f"{owner}_{repo}")
110-
rprint(f"[bold][green]Deleted model {owner}/{repo}")
104+
console.print(f"[bold][green]Deleted model {owner}/{repo}")
111105

112106
if args.version:
113107
text = ASCII_ART.format(__version__)
@@ -123,11 +117,11 @@ def main():
123117
)
124118
return
125119
message = octo.checkout(owner, repo)
126-
console.log(message)
120+
console.print(message)
127121

128122
if args.command == "status":
129123
message = octo.status()
130-
console.log(message)
124+
console.print(message)
131125

132126
if args.command == "tell":
133127
df = pd.DataFrame({"questions": [args.action]})
@@ -136,7 +130,8 @@ def main():
136130
answer = pred_df["answer"].iloc[0]
137131
# Filter string
138132
answer = answer.replace("\n", "")
139-
rprint(answer)
133+
console.print(f"\n{answer}")
134+
return
140135

141136
if args.command == "drop":
142137
try:
@@ -148,15 +143,15 @@ def main():
148143
)
149144
return
150145
message = octo.drop(owner, repo)
151-
rprint(message)
146+
console.print(message)
152147

153148
if args.command == "list":
154149
model_names = octo.list_models()
155150
# Format the string
156151
model_names = [i.replace("_", "/") for i in model_names]
157152
with console.status("[bold green]Fetching models...", spinner="dots2"):
158153
for i in model_names:
159-
rprint(i)
154+
console.print(i)
160155

161156

162157

octo/github_handle/mindsdb_octo.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def stop_local(self):
2929
"""
3030
# Run shell command to stop the local mindsdb server
3131
command = 'pkill -f "python"'
32-
subprocess.run(command, shell=True, check=True)
32+
subprocess.run(command, shell=True, check=True, stdout=subprocess.DEVNULL)
3333

3434
def create_model(self, owner, repo, branch, all_files=False):
3535
project = self._get_project()
@@ -61,13 +61,12 @@ def create_model(self, owner, repo, branch, all_files=False):
6161
)
6262
while True:
6363
if model.get_status() not in ("generating", "training"):
64-
print("\nFinished adding repository to knowledge base")
6564
break
6665

6766
if model.get_status() == "error":
68-
return f"[bold][red]{model.data['error']}"
67+
return f"[bold][red]{model.data['error']}", True
6968

70-
return f"[bold][green]Model created successfully"
69+
return f"[bold][green]Model created successfully", False
7170

7271
def predict(self, df, owner, repo):
7372
project = self._get_project()

octo/github_handle/octo.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ def init(self, repo, owner, branch, all_files=False):
1818
self.owner = owner
1919
self.branch = branch
2020
self.repo_initialized = True
21-
message = self.create_model(
21+
message, error = self.create_model(
2222
self.owner, self.repo, self.branch, all_files=all_files
2323
)
24-
self._save_state()
24+
if not error:
25+
self._save_state()
2526
elif (
2627
self.repo.lower() == repo
2728
and self.owner.lower() == owner
@@ -34,10 +35,11 @@ def init(self, repo, owner, branch, all_files=False):
3435
self.owner = owner
3536
self.branch = branch
3637
self.repo_initialized = True
37-
message = self.create_model(
38+
message, error = self.create_model(
3839
self.owner, self.repo, self.branch, all_files=all_files
3940
)
40-
self._save_state()
41+
if not error:
42+
self._save_state()
4143
return message
4244

4345
def checkout(self, owner, repo):
@@ -64,12 +66,11 @@ def tell(self, df):
6466

6567
def drop(self, owner, repo):
6668
project = self._get_project()
67-
model_names = [i.name for i in project.list_models()]
68-
if f"{owner}_{repo}" not in model_names:
69-
return f"[bold][red]Error: Model {owner}/{repo} does not exist"
70-
else:
69+
try:
7170
project.drop_model(f"{owner}_{repo}")
7271
return f"[bold][green]Deleted model {owner}/{repo}"
72+
except:
73+
return f"[bold][red]Error: Model {owner}/{repo} does not exist"
7374

7475
def _save_state(self):
7576
state = {

octo/templates/query_dicts.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
"branch": "<branch>",
66
"reader": "GithubRepositoryReader",
77
"filer_type": "include",
8-
"filer_extensions": [".md",],
8+
"filer_extensions": [".md"],
99
"input_column": "questions",
1010
"openai_api_key": "<openai_key>",
1111
"github_token": "<github_token>",
12-
"model_name": "gpt-4"
1312
}
1413

1514
# Include all files in the repo
@@ -22,5 +21,4 @@
2221
"input_column": "questions",
2322
"openai_api_key": "<openai_key>",
2423
"github_token": "<github_token>",
25-
"model_name": "gpt-4"
2624
}

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
rich
22
git+https://github.com/pranavvp16/mindsdb.git@llama_index
3-
mindsdb_sql==0.7.4
43
mindsdb_sdk
54
openai==1.6.1
65
llama_index==0.9.27

setup.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
},
1212
# install_requires=[
1313
# 'rich',
14-
# 'mindsdb_sdk',
15-
# 'openai',
16-
# 'mindsdb'
17-
# ],
18-
# dependency_links=["https://github.com/pranavvp16/mindsdb.git@llama_index#egg=mindsdb-llama_index"]
14+
# 'mindsdb_llama_index>=23.12.4.2',
15+
# 'mindsdb_sdk==2.0.0',
16+
# 'openai==1.6.1',
17+
# 'llama_index==0.9.27',
18+
# 'llama_hub==0.0.67',
19+
#],
20+
#dependency_links=["https://github.com/pranavvp16/mindsdb.git@llama_index#egg=mindsdb_llama_index-23.12.4.2"]
1921
)

0 commit comments

Comments
 (0)