Skip to content

Commit 1cf6f78

Browse files
authored
Merge pull request #43 from Project-Llama/feat-fix(comments-strings)
Comments + Fixed Strings
2 parents 9c469d3 + e1da735 commit 1cf6f78

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-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: 18 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,11 @@ 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+
(
64+
"MLC",
65+
r"/\*(.|\n)*?\*/",
66+
), # Multi-line comment e.g., /* This is a comment */
5767
("MISMATCH", r"."), # Any other character
5868
]
5969
tok_regex = "|".join("(?P<%s>%s)" % pair for pair in token_specification)
@@ -69,6 +79,8 @@ def tokenize(self, text):
6979
self.tokens.append(("NEWLINE", value))
7080
elif kind == "SKIP":
7181
continue
82+
elif kind == ("SLC" or "MLC"):
83+
continue
7284
elif kind == "MISMATCH":
7385
error(f"Invalid character: {value}")
7486
sys.exit(1)
@@ -121,7 +133,10 @@ def arguments(self):
121133
self.current < len(self.tokens) and self.tokens[self.current][0] != "RPAREN"
122134
):
123135
token = self.tokens[self.current]
124-
if token[0] in {"STRING", "NUMBER"}:
136+
if token[0] == "STRING":
137+
args.append(token[1][1:-1]) # Strip surrounding quotes
138+
self.current += 1
139+
elif token[0] == "NUMBER":
125140
args.append(token[1])
126141
self.current += 1
127142
elif token[0] == "COMMA":
@@ -249,7 +264,7 @@ def create_model(self, filename, parameters, attributes):
249264
stderr=subprocess.DEVNULL,
250265
)
251266
stdout, stderr = process.communicate()
252-
print("Model created.")
267+
info("Model created.")
253268

254269
if process.returncode != 0:
255270
if stderr:

0 commit comments

Comments
 (0)