Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,37 @@
|
|
1 |
import os
|
2 |
-
import time
|
3 |
import streamlit as st
|
4 |
-
from getpass import getpass
|
5 |
from openai import OpenAI
|
6 |
from llama_index.node_parser import SemanticSplitterNodeParser
|
7 |
from llama_index.embeddings import OpenAIEmbedding
|
8 |
from llama_index.ingestion import IngestionPipeline
|
9 |
-
|
10 |
from pinecone.grpc import PineconeGRPC
|
11 |
-
from pinecone import ServerlessSpec
|
12 |
-
|
13 |
from llama_index.vector_stores import PineconeVectorStore
|
14 |
-
|
15 |
from llama_index import VectorStoreIndex
|
16 |
from llama_index.retrievers import VectorIndexRetriever
|
17 |
from llama_index.query_engine import RetrieverQueryEngine
|
18 |
|
19 |
-
# Set OpenAI API key from
|
20 |
-
pinecone_api_key = os.getenv("PINECONE_API_KEY")
|
21 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
|
22 |
|
23 |
# Initialize OpenAI client
|
24 |
client = OpenAI(api_key=openai_api_key)
|
25 |
|
26 |
-
|
27 |
# Initialize connection to Pinecone
|
28 |
pc = PineconeGRPC(api_key=pinecone_api_key)
|
29 |
-
|
30 |
|
31 |
# Initialize your index
|
|
|
|
|
|
|
32 |
pinecone_index = pc.Index(index_name)
|
33 |
|
34 |
# Initialize VectorStore
|
35 |
vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
|
36 |
-
|
37 |
pinecone_index.describe_index_stats()
|
38 |
|
39 |
-
|
40 |
# Initialize vector index and retriever
|
41 |
vector_index = VectorStoreIndex.from_vector_store(vector_store=vector_store)
|
42 |
retriever = VectorIndexRetriever(index=vector_index, similarity_top_k=5)
|
|
|
1 |
import os
|
|
|
2 |
import streamlit as st
|
|
|
3 |
from openai import OpenAI
|
4 |
from llama_index.node_parser import SemanticSplitterNodeParser
|
5 |
from llama_index.embeddings import OpenAIEmbedding
|
6 |
from llama_index.ingestion import IngestionPipeline
|
|
|
7 |
from pinecone.grpc import PineconeGRPC
|
|
|
|
|
8 |
from llama_index.vector_stores import PineconeVectorStore
|
|
|
9 |
from llama_index import VectorStoreIndex
|
10 |
from llama_index.retrievers import VectorIndexRetriever
|
11 |
from llama_index.query_engine import RetrieverQueryEngine
|
12 |
|
13 |
+
# Set OpenAI API key from environment variables
|
|
|
14 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
15 |
+
pinecone_api_key = os.getenv("PINECONE_API_KEY")
|
16 |
+
index_name = os.getenv("annualreport")
|
17 |
|
18 |
# Initialize OpenAI client
|
19 |
client = OpenAI(api_key=openai_api_key)
|
20 |
|
|
|
21 |
# Initialize connection to Pinecone
|
22 |
pc = PineconeGRPC(api_key=pinecone_api_key)
|
23 |
+
|
24 |
|
25 |
# Initialize your index
|
26 |
+
if index_name not in pc.list_indexes():
|
27 |
+
pc.create_index(name=index_name, dimension=1536)
|
28 |
+
|
29 |
pinecone_index = pc.Index(index_name)
|
30 |
|
31 |
# Initialize VectorStore
|
32 |
vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
|
|
|
33 |
pinecone_index.describe_index_stats()
|
34 |
|
|
|
35 |
# Initialize vector index and retriever
|
36 |
vector_index = VectorStoreIndex.from_vector_store(vector_store=vector_store)
|
37 |
retriever = VectorIndexRetriever(index=vector_index, similarity_top_k=5)
|