Spaces:
Running
Running
Chandran Palanisamy
commited on
Commit
•
c41984f
1
Parent(s):
5be6957
Update app.py
Browse filesRespond only with in context
app.py
CHANGED
@@ -7,12 +7,29 @@ from llama_index import (
|
|
7 |
Document,
|
8 |
load_index_from_storage, ChatPromptTemplate,
|
9 |
)
|
|
|
|
|
10 |
from llama_index.embeddings.openai import OpenAIEmbedding
|
11 |
from llama_index import SimpleDirectoryReader
|
12 |
from llama_index.llms import OpenAI, ChatMessage, MessageRole
|
13 |
import gradio as gr
|
14 |
from typing import List, cast, Optional
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Function to load the dataframe and chat with it
|
17 |
def chat_with_dataframe(question):
|
18 |
storage_context = StorageContext.from_defaults(
|
@@ -27,6 +44,9 @@ def chat_with_dataframe(question):
|
|
27 |
return response.response
|
28 |
|
29 |
|
|
|
|
|
|
|
30 |
# Streamlit interface
|
31 |
def main():
|
32 |
st.sidebar.title('Virtimo - INUBIT')
|
|
|
7 |
Document,
|
8 |
load_index_from_storage, ChatPromptTemplate,
|
9 |
)
|
10 |
+
from llama_index import set_global_service_context
|
11 |
+
|
12 |
from llama_index.embeddings.openai import OpenAIEmbedding
|
13 |
from llama_index import SimpleDirectoryReader
|
14 |
from llama_index.llms import OpenAI, ChatMessage, MessageRole
|
15 |
import gradio as gr
|
16 |
from typing import List, cast, Optional
|
17 |
|
18 |
+
service_context = ServiceContext.from_defaults(
|
19 |
+
chunk_size=1024,
|
20 |
+
llm=OpenAI(model="gpt-4"),
|
21 |
+
embed_model=OpenAIEmbedding(),
|
22 |
+
system_prompt="""
|
23 |
+
You are tasked with answering queries related to the content found within a provided PDF document.
|
24 |
+
When responding to queries, you must ALWAYS utilize the tools available to you to analyze the content of the PDF.
|
25 |
+
NEVER provide an answer based solely on general knowledge or without employing the tools designed for this task.
|
26 |
+
Your responses should be informed by the information extracted from the PDF content using these tools, ensuring accuracy and relevance to the user's query.
|
27 |
+
Remember, the data source for your answers is implicit in the queries you receive, and you should not reference or assume any external data sources when formulating your responses. Your primary objective is to provide precise and contextually correct information based on the PDF content analysis.
|
28 |
+
""",
|
29 |
+
|
30 |
+
)
|
31 |
+
|
32 |
+
|
33 |
# Function to load the dataframe and chat with it
|
34 |
def chat_with_dataframe(question):
|
35 |
storage_context = StorageContext.from_defaults(
|
|
|
44 |
return response.response
|
45 |
|
46 |
|
47 |
+
set_global_service_context(service_context)
|
48 |
+
|
49 |
+
|
50 |
# Streamlit interface
|
51 |
def main():
|
52 |
st.sidebar.title('Virtimo - INUBIT')
|