-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatgpt_clone_with_langchain_retrieval.py
54 lines (42 loc) · 1.75 KB
/
chatgpt_clone_with_langchain_retrieval.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import typer
from dotenv import load_dotenv
from halo import Halo
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores.chroma import Chroma
from chatflock.backing_stores import InMemoryChatDataBackingStore
from chatflock.base import Chat
from chatflock.conductors import RoundRobinChatConductor
from chatflock.participants.langchain import LangChainBasedAIChatParticipant
from chatflock.participants.user import UserChatParticipant
from chatflock.renderers import TerminalChatRenderer
from examples.common import create_chat_model
def chatgpt_clone_with_langchain_retrieval(model: str = "gpt-4-1106-preview", temperature: float = 0.0) -> None:
chat_model = create_chat_model(model=model, temperature=temperature)
spinner = Halo(spinner="dots")
# Set up a simple document store.
texts = [
"The user's name is Eric.",
"The user likes to eat Chocolate.",
"The user loves to play video games.",
"The user is a software engineer.",
]
# Make sure you install chromadb: `pip install chromadb`
db = Chroma.from_texts(texts, OpenAIEmbeddings())
retriever = db.as_retriever()
ai = LangChainBasedAIChatParticipant(
name="Assistant",
chat_model=chat_model,
# Pass the retriever to the AI participant
retriever=retriever,
spinner=spinner,
)
user = UserChatParticipant(name="User")
participants = [user, ai]
chat = Chat(
backing_store=InMemoryChatDataBackingStore(), renderer=TerminalChatRenderer(), initial_participants=participants
)
chat_conductor = RoundRobinChatConductor()
chat_conductor.initiate_dialog(chat=chat)
if __name__ == "__main__":
load_dotenv()
typer.run(chatgpt_clone_with_langchain_retrieval)