-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathex.py
More file actions
25 lines (18 loc) · 674 Bytes
/
ex.py
File metadata and controls
25 lines (18 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import openai
import os
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.memory import ChatMemoryBuffer
openai.api_key = os.getenv("OPENAI_API_KEY")
data = SimpleDirectoryReader(input_dir="./data/paul_graham/").load_data()
index = VectorStoreIndex.from_documents(data)
memory = ChatMemoryBuffer.from_defaults(token_limit=1500)
chat_engine = index.as_chat_engine(
chat_mode="context",
memory=memory,
system_prompt=(
"You are a chatbot, able to have normal interactions, as well as talk"
" about an essay discussing Paul Grahams life."
),
)
response = chat_engine.chat("Hello!")
print(response)