mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-24 20:03:41 +03:00
Update Readme and add token counts
Update readme for anthropic
This commit is contained in:
parent
52cd51d71a
commit
ee38a44bdd
@ -80,6 +80,7 @@ cp .streamlit/secrets.toml.example .streamlit/secrets.toml
|
|||||||
supabase_url = "SUPABASE_URL"
|
supabase_url = "SUPABASE_URL"
|
||||||
supabase_service_key = "SUPABASE_SERVICE_KEY"
|
supabase_service_key = "SUPABASE_SERVICE_KEY"
|
||||||
openai_api_key = "OPENAI_API_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
|
- 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
|
import streamlit as st
|
||||||
from streamlit.logger import get_logger
|
from streamlit.logger import get_logger
|
||||||
from langchain.chains import ConversationalRetrievalChain
|
from langchain.chains import ConversationalRetrievalChain
|
||||||
@ -13,9 +14,17 @@ anthropic_api_key = st.secrets.anthropic_api_key
|
|||||||
logger = get_logger(__name__)
|
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):
|
def chat_with_doc(model, vector_store: SupabaseVectorStore):
|
||||||
question = st.text_area("## Ask a question")
|
question = st.text_area("## Ask a question")
|
||||||
button = st.button("Ask")
|
button = st.button("Ask")
|
||||||
|
count_button = st.button("Count Tokens", type='secondary')
|
||||||
if button:
|
if button:
|
||||||
if model.startswith("gpt"):
|
if model.startswith("gpt"):
|
||||||
logger.info('Using OpenAI model %s', model)
|
logger.info('Using OpenAI model %s', model)
|
||||||
@ -33,3 +42,6 @@ def chat_with_doc(model, vector_store: SupabaseVectorStore):
|
|||||||
result = qa({"question": question})
|
result = qa({"question": question})
|
||||||
logger.info('Result: %s', result)
|
logger.info('Result: %s', result)
|
||||||
st.write(result["answer"])
|
st.write(result["answer"])
|
||||||
|
|
||||||
|
if count_button:
|
||||||
|
st.write(count_tokens(question, model))
|
||||||
|
Loading…
Reference in New Issue
Block a user