Skip to content

Commit e7842a0

Browse files
committed
Comments + Fixed Strings
1 parent 9c469d3 commit e7842a0

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

examples/chatbot.llama

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
use("llama3")
2-
prompt("Why is the sky blue?")
3-
chat()
1+
use("piglatin") // Load the Piglatin module
2+
prompt("Why is the sky blue?") /* Ask a question */
3+
4+
// The chatbot will respond in pig latin
5+
chat()
6+
7+
/*
8+
Done! The chatbot will respond in pig latin.
9+
*/

llamascript/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
__version__ = "1.0.0"
22

3-
import asyncio
43
import ollama
54
import logging
65
import sys
@@ -34,6 +33,12 @@ def warning(message):
3433
)
3534

3635

36+
def info(message):
37+
print(
38+
f"{colorama.Fore.GREEN}{colorama.Style.BRIGHT}[INFO]{colorama.Style.RESET_ALL} {message}"
39+
)
40+
41+
3742
# Set up logging
3843
logging.basicConfig(level=logging.WARNING)
3944

@@ -54,6 +59,8 @@ def tokenize(self, text):
5459
("COMMA", r","), # Comma
5560
("NEWLINE", r"\n"), # Line endings
5661
("SKIP", r"[ \t]+"), # Skip over spaces and tabs
62+
("SLC", r"//.*"), # Single-line comment e.g., // This is a comment
63+
("MLC", r"/\*(.|\n)*?\*/"), # Multi-line comment e.g., /* This is a comment */
5764
("MISMATCH", r"."), # Any other character
5865
]
5966
tok_regex = "|".join("(?P<%s>%s)" % pair for pair in token_specification)
@@ -69,6 +76,8 @@ def tokenize(self, text):
6976
self.tokens.append(("NEWLINE", value))
7077
elif kind == "SKIP":
7178
continue
79+
elif kind == ("SLC" or "MLC"):
80+
continue
7281
elif kind == "MISMATCH":
7382
error(f"Invalid character: {value}")
7483
sys.exit(1)
@@ -121,7 +130,10 @@ def arguments(self):
121130
self.current < len(self.tokens) and self.tokens[self.current][0] != "RPAREN"
122131
):
123132
token = self.tokens[self.current]
124-
if token[0] in {"STRING", "NUMBER"}:
133+
if token[0] == "STRING":
134+
args.append(token[1][1:-1]) # Strip surrounding quotes
135+
self.current += 1
136+
elif token[0] == "NUMBER":
125137
args.append(token[1])
126138
self.current += 1
127139
elif token[0] == "COMMA":
@@ -249,7 +261,7 @@ def create_model(self, filename, parameters, attributes):
249261
stderr=subprocess.DEVNULL,
250262
)
251263
stdout, stderr = process.communicate()
252-
print("Model created.")
264+
info("Model created.")
253265

254266
if process.returncode != 0:
255267
if stderr:

0 commit comments

Comments
 (0)