Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colored prefixes on chatbot streaming #13

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions examples/chatbot_with_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
"/exit": {},
}

LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"

logger = logging.getLogger("chatbot")


Expand Down Expand Up @@ -88,11 +86,10 @@ def opening_instructions(self):
)

def new_chat(self):
print("")
print(
f"Starting new chat with model: {self.model}, temperature: {self.temperature}"
logger.info(
f"Starting new chat with model: \033[38;2;253;112;0m{self.model}\033[0m, "
f"temperature: {self.temperature}"
)
print("")
self.messages = []
if self.system_message:
self.messages.append(
Expand All @@ -103,7 +100,7 @@ def switch_model(self, input):
model = self.get_arguments(input)
if model in MODEL_LIST:
self.model = model
logger.info(f"Switching model: {model}")
logger.info(f"Switching model: \033[38;2;253;112;0m{model}\033[0m")
else:
logger.error(f"Invalid model name: {model}")

Expand All @@ -129,27 +126,24 @@ def switch_temperature(self, input):

def show_config(self):
print("")
print(f"Current model: {self.model}")
print(f"Current temperature: {self.temperature}")
print(f"Current model: \033[38;2;253;112;0m{self.model}\033[0m")
print(f"Current temperature: {self.temperature}")
print(f"Current system message: {self.system_message}")
print("")

def collect_user_input(self):
print("")
return input("YOU: ")
content = input("\033[38;2;50;168;82mUser: \033[0m")
return content

def run_inference(self, content):
print("")
print("MISTRAL:")
print("")

self.messages.append(ChatMessage(role="user", content=content))

assistant_response = ""
logger.debug(
f"Running inference with model: {self.model}, temperature: {self.temperature}"
)
logger.debug(f"Sending messages: {self.messages}")
print(f"\033[38;2;253;112;0m{self.model}: \033[0m", end="")
for chunk in self.client.chat_stream(
model=self.model, temperature=self.temperature, messages=self.messages
):
Expand Down