-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (28 loc) · 1.08 KB
/
main.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
from llama_cpp import Llama
llm = Llama(
model_path="/home/lokman/Desktop/llama.cpp/models/llama-2-7b-chat.Q2_K.gguf",
chat_format="llama-2"
)
def chat_with_llama():
print("Llama Chat. Type 'quit' to exit.")
while True:
user_input = input("You: ")
if user_input.lower() == 'quit':
break
try:
response = llm.create_chat_completion(messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": user_input}
])
if 'choices' in response and response['choices'] and 'message' in response['choices'][0]:
message = response['choices'][0]['message']
if 'content' in message:
print("Llama:", message['content'])
else:
print("Message content not found")
else:
print("Unexpected response format:", response)
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
chat_with_llama()