mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-14 17:03:29 +03:00
Merge pull request #18 from Shaunwei/support-anthropic-100k
Update Readme and add token counts
This commit is contained in:
commit
35690ef656
@ -80,6 +80,7 @@ cp .streamlit/secrets.toml.example .streamlit/secrets.toml
|
||||
supabase_url = "SUPABASE_URL"
|
||||
supabase_service_key = "SUPABASE_SERVICE_KEY"
|
||||
openai_api_key = "OPENAI_API_KEY"
|
||||
anthropic_api_key = "ANTHROPIC_API_KEY" # Optional
|
||||
```
|
||||
|
||||
- Run the migration script on the Supabase database via the web interface
|
||||
|
12
question.py
12
question.py
@ -1,3 +1,4 @@
|
||||
import anthropic
|
||||
import streamlit as st
|
||||
from streamlit.logger import get_logger
|
||||
from langchain.chains import ConversationalRetrievalChain
|
||||
@ -13,9 +14,17 @@ anthropic_api_key = st.secrets.anthropic_api_key
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
def count_tokens(question, model):
|
||||
count = f'Words: {len(question.split())}'
|
||||
if model.startswith("claude"):
|
||||
count += f' | Tokens: {anthropic.count_tokens(question)}'
|
||||
return count
|
||||
|
||||
|
||||
def chat_with_doc(model, vector_store: SupabaseVectorStore):
|
||||
question = st.text_area("## Ask a question")
|
||||
button = st.button("Ask")
|
||||
count_button = st.button("Count Tokens", type='secondary')
|
||||
if button:
|
||||
if model.startswith("gpt"):
|
||||
logger.info('Using OpenAI model %s', model)
|
||||
@ -33,3 +42,6 @@ def chat_with_doc(model, vector_store: SupabaseVectorStore):
|
||||
result = qa({"question": question})
|
||||
logger.info('Result: %s', result)
|
||||
st.write(result["answer"])
|
||||
|
||||
if count_button:
|
||||
st.write(count_tokens(question, model))
|
||||
|
Loading…
Reference in New Issue
Block a user