-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathllm.py
More file actions
64 lines (57 loc) · 2.24 KB
/
llm.py
File metadata and controls
64 lines (57 loc) · 2.24 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from llama_cpp import Llama
from langchain_community.llms import Ollama
class LLM:
def __init__(self):
self.llm = Ollama(model ='codellama:latest')
# self.llm = Llama(
# model_path="models/llama-2-7b-chat.Q4_K_M.gguf",
# chat_format="llama-2",
# n_gpu_layers=-1,
# n_ctx=4096
# )
self.messages = [
{"role": "system",
"content": "You are an assistant who answers a user's question based on the information provided."},
]
def get_response(self, question, information):
query = f'''
Question: {question}
Information: {information}
'''
self.messages.append({"role": "user", "content": query})
out = self.llm.invoke(input=self.messages)
return out
if __name__ == "__main__":
llm = Ollama(
model ='codellama:latest'
)
messages = [
{"role": "system",
"content": "You are an assistant who answers a user's question based on the information provided."},
]
q = '''
Question: What are habits?
Information:
” His work provides the perfect starting point for
discussing how habits form in our own lives It also provides answers
to some fundamental questions like: What are habits? And why does
the brain bother building them at all?
WHY YOUR BRAIN BUILDS HABITS
A habit is a behavior that has been repeated enough times to become
automatic
--------
Once you have a full list, look at each behavior, and ask yourself, “Is
this a good habit, a bad habit, or a neutral habit?” If it is a good habit,
write “+” next to it If it is a bad habit, write If it is a neutral habit,
write “=”
--------
If you’re still having trouble determining how to rate a particular
habit, here is a question I like to use: “Does this behavior help me
become the type of person I wish to be? Does this habit cast a vote for
or against my desired identity?” Habits that reinforce your desired
identity are usually good Habits that conflict with your desired
identity are usually bad
'''
messages.append({"role":"user", "content":q})
out = llm.invoke(input=messages)
print(out)