MuhammadMubashir commited on
Commit
1a8c15c
·
verified ·
1 Parent(s): c4b78ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -44,6 +44,7 @@ from pinecone import Pinecone
44
  from PIL import Image
45
  from langchain_community.vectorstores import Pinecone
46
  from pinecone import Pinecone as PineconeClient
 
47
 
48
  # Load environment variables
49
  load_dotenv()
@@ -69,10 +70,19 @@ vector_store = Pinecone.from_existing_index(index_name=INDEX_NAME, embedding=emb
69
 
70
 
71
  # Load LLM & Memory
72
- llm = ChatAnthropic(
73
- model="claude-2",
74
- temperature=0,
75
- ANTHROPIC_API_KEY=os.getenv("ANTHROPIC_API_KEY")
 
 
 
 
 
 
 
 
 
76
  )
77
  memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
78
 
@@ -105,7 +115,7 @@ pinecone_data = [(str(i), embedding_vectors[i], {"text": chunks[i]}) for i in ra
105
  vector_store.upsert(vectors=pinecone_data)
106
 
107
  # Streamlit UI
108
- st.set_page_config(page_title="Agentic RAG Legal Assistant", layout="wide")
109
 
110
  bg_image = "https://source.unsplash.com/1600x900/?law,court"
111
  sidebar_image = "https://source.unsplash.com/400x600/?law,justice"
 
44
  from PIL import Image
45
  from langchain_community.vectorstores import Pinecone
46
  from pinecone import Pinecone as PineconeClient
47
+ from anthropic import Anthropic
48
 
49
  # Load environment variables
50
  load_dotenv()
 
70
 
71
 
72
  # Load LLM & Memory
73
+
74
+ class ChatAnthropicWithTokenCount(ChatAnthropic):
75
+ def __init__(self, *args, **kwargs):
76
+ super().__init__(*args, **kwargs)
77
+ self.anthropic_client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
78
+
79
+ def count_tokens(self, text: str) -> int:
80
+ return self.anthropic_client.count_tokens(text)
81
+
82
+ llm = ChatAnthropicWithTokenCount(
83
+ model="claude-2",
84
+ temperature=0,
85
+ ANTHROPIC_API_KEY=os.getenv("ANTHROPIC_API_KEY")
86
  )
87
  memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
88
 
 
115
  vector_store.upsert(vectors=pinecone_data)
116
 
117
  # Streamlit UI
118
+ st.set_page_config(page_title="LegalAI Assistant", layout="wide")
119
 
120
  bg_image = "https://source.unsplash.com/1600x900/?law,court"
121
  sidebar_image = "https://source.unsplash.com/400x600/?law,justice"