Spaces:
Runtime error
Runtime error
Commit
•
48e2e12
1
Parent(s):
75ca367
Upload 7 files
Browse files- .gitattributes +1 -0
- chatbot.py +92 -0
- requirements.txt +0 -0
- vectordb/chroma.sqlite3 +3 -0
- vectordb/dead17a5-47d5-460f-abd6-ab6c192e4f94/data_level0.bin +3 -0
- vectordb/dead17a5-47d5-460f-abd6-ab6c192e4f94/header.bin +3 -0
- vectordb/dead17a5-47d5-460f-abd6-ab6c192e4f94/length.bin +3 -0
- vectordb/dead17a5-47d5-460f-abd6-ab6c192e4f94/link_lists.bin +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
vectordb/chroma.sqlite3 filter=lfs diff=lfs merge=lfs -text
|
chatbot.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_openai import ChatOpenAI
|
2 |
+
from langchain_core.prompts import ChatPromptTemplate
|
3 |
+
from langchain.chains.combine_documents import create_stuff_documents_chain
|
4 |
+
from langchain.chains import create_retrieval_chain
|
5 |
+
from langchain_openai import OpenAI
|
6 |
+
from langchain_community.embeddings.sentence_transformer import (
|
7 |
+
SentenceTransformerEmbeddings,
|
8 |
+
)
|
9 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
10 |
+
from langchain_community.vectorstores import Chroma
|
11 |
+
import gradio as gr
|
12 |
+
|
13 |
+
embedding = SentenceTransformerEmbeddings(
|
14 |
+
model_name="all-MiniLM-L6-v2"
|
15 |
+
)
|
16 |
+
|
17 |
+
# embedding = GoogleGenerativeAIEmbeddings()
|
18 |
+
db = Chroma(persist_directory="vectordb", embedding_function=embedding)
|
19 |
+
|
20 |
+
retriever_db = db.as_retriever()
|
21 |
+
|
22 |
+
# llm = OpenAI(model="gpt-3.5-turbo-instruct",
|
23 |
+
# temperature=0, openai_api_key=opena_api)
|
24 |
+
|
25 |
+
# model = ChatOpenAI(model="gpt-3.5-turbo-1106",
|
26 |
+
# temperature=0, openai_api_key=opena_api)
|
27 |
+
|
28 |
+
api = "AIzaSyDHbc2aebeK5h5ZlxsZBr82ueAaOOUZgm8"
|
29 |
+
|
30 |
+
model = ChatGoogleGenerativeAI(
|
31 |
+
model="gemini-pro", google_api_key=api, temperature=0.1, stream=True
|
32 |
+
)
|
33 |
+
|
34 |
+
# Define a function to store conversation history
|
35 |
+
conversation_history = []
|
36 |
+
|
37 |
+
|
38 |
+
def store_conversation(message):
|
39 |
+
conversation_history.append(message)
|
40 |
+
if len(conversation_history) > 3:
|
41 |
+
# Maintain a history of only 3 conversations
|
42 |
+
conversation_history.pop(0)
|
43 |
+
|
44 |
+
|
45 |
+
prompt = ChatPromptTemplate.from_template("""
|
46 |
+
Sure, here's a revised prompt that addresses inquiries about Entrans beyond just AI products and information technologies:
|
47 |
+
|
48 |
+
---
|
49 |
+
|
50 |
+
Your role: You are an AI-powered chatbot representing Entrans, a leading provider of cutting-edge AI solutions.
|
51 |
+
|
52 |
+
Your Objective: Engage potential clients and showcase Entrans's expertise in developing innovative AI products and information technologies. Additionally, provide information about Entrans's team culture, goals, contact details, and other relevant inquiries.
|
53 |
+
|
54 |
+
For inquiries related to building AI products and information technologies, provide compelling responses demonstrating Entrans's capability to design and deliver tailored solutions that meet clients' needs and exceed expectations. Highlight Entrans's track record of successful projects in these areas, emphasizing the quality, reliability, and effectiveness of our solutions.
|
55 |
+
|
56 |
+
For inquiries about Entrans's team culture, goals, contact details, and any other aspect of our organization, provide detailed and informative responses that portray Entrans as a dynamic, innovative, and customer-focused company. Showcase our commitment to excellence, collaboration, and continuous improvement in all aspects of our operations.
|
57 |
+
|
58 |
+
Your ultimate goal is to leave potential clients impressed and eager to collaborate with Entrans on their next AI project, as well as to provide comprehensive information about our organization to address any inquiries they may have.
|
59 |
+
|
60 |
+
Context: {context}
|
61 |
+
Question: {input}
|
62 |
+
Conversation History: {conversation_history}
|
63 |
+
""")
|
64 |
+
|
65 |
+
|
66 |
+
def respond(message, history):
|
67 |
+
store_conversation(message) # Store the current message in history
|
68 |
+
result = retrieval_chain.invoke(
|
69 |
+
{"input": message, "conversation_history": conversation_history})
|
70 |
+
|
71 |
+
partial_message = ""
|
72 |
+
for chunk in result['answer']:
|
73 |
+
partial_message += chunk
|
74 |
+
yield partial_message
|
75 |
+
|
76 |
+
|
77 |
+
chain = create_stuff_documents_chain(llm=model, prompt=prompt)
|
78 |
+
|
79 |
+
retrieval_chain = create_retrieval_chain(
|
80 |
+
retriever_db,
|
81 |
+
chain
|
82 |
+
)
|
83 |
+
|
84 |
+
|
85 |
+
gr.ChatInterface(respond,
|
86 |
+
title="Entrans Bot",
|
87 |
+
description="Ask me anything the Information you want!",
|
88 |
+
theme="soft",
|
89 |
+
examples=["What AI services do you provide?",
|
90 |
+
"What would be the cost to build an AI application?"],
|
91 |
+
cache_examples=True
|
92 |
+
).launch(share=True)
|
requirements.txt
ADDED
Binary file (6.7 kB). View file
|
|
vectordb/chroma.sqlite3
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4b3678a1d5a9662bcd47ec396d3653b7a1fd8f0c0ab89a8ced59f6d6b8d228dd
|
3 |
+
size 2670592
|
vectordb/dead17a5-47d5-460f-abd6-ab6c192e4f94/data_level0.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d3c9fd302f000d7790aa403c2d0d8fec363fe46f30b07d53020b6e33b22435a9
|
3 |
+
size 1676000
|
vectordb/dead17a5-47d5-460f-abd6-ab6c192e4f94/header.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e87a1dc8bcae6f2c4bea6d5dd5005454d4dace8637dae29bff3c037ea771411e
|
3 |
+
size 100
|
vectordb/dead17a5-47d5-460f-abd6-ab6c192e4f94/length.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a456c543311387f4e8e6f6cb7c74a146a845e79476ca9e101bc5e680d44f1d23
|
3 |
+
size 4000
|
vectordb/dead17a5-47d5-460f-abd6-ab6c192e4f94/link_lists.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
3 |
+
size 0
|