-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdated_chat.py
33 lines (29 loc) · 931 Bytes
/
updated_chat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import asyncio
from ollama import AsyncClient
async def chat(user_input):
"""
Streaming a chat from Llama using the AsyncClient.
"""
message = {
"role": "user",
"content": user_input
}
async for part in await AsyncClient().chat(
model="llama3", messages=[message], stream=True
):
print(part["message"]["content"], end="", flush=True)
async def main():
print("************************")
print("Welcome to llama3 chatbot")
print("Enter 'exit' to leave the chat")
print("************************",end="")
while True:
print("\n")
user_input = input("You: ")
if user_input.lower() == 'exit':
print("Chat ended. Goodbye!")
break
await chat(user_input)
await asyncio.sleep(0.1) # Small sleep to prevent blocking
# Run the main function
asyncio.run(main())