-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs example scripts to repo (#11)
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
"""Example script demonstrating an interactive LLM chatbot.""" | ||
|
||
import readline # Enables input line editing | ||
|
||
import lmstudio as lm | ||
|
||
model = lm.llm() | ||
chat = lm.Chat("You are a task focused AI assistant") | ||
|
||
while True: | ||
try: | ||
user_input = input("You (leave blank to exit): ") | ||
except EOFError: | ||
print() | ||
break | ||
if not user_input: | ||
break | ||
chat.add_user_message(user_input) | ||
prediction_stream = model.respond_stream( | ||
chat, | ||
on_message=chat.append, | ||
) | ||
print("Bot: ", end="", flush=True) | ||
for fragment in prediction_stream: | ||
print(fragment.content, end="", flush=True) | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
"""Example script demonstrating a simulated terminal command processor.""" | ||
|
||
import readline # Enables input line editing | ||
|
||
import lmstudio as lm | ||
|
||
model = lm.llm() | ||
console_history = [] | ||
|
||
while True: | ||
try: | ||
user_command = input("$ ") | ||
except EOFError: | ||
print() | ||
break | ||
if user_command.strip() == "exit": | ||
break | ||
console_history.append(f"$ {user_command}") | ||
history_prompt = "\n".join(console_history) | ||
prediction_stream = model.complete_stream( | ||
history_prompt, | ||
config={ "stopStrings": ["$"] }, | ||
) | ||
for fragment in prediction_stream: | ||
print(fragment.content, end="", flush=True) | ||
print() | ||
console_history.append(prediction_stream.result().content) |