How to use Anthropic claude-3.5-sonnet with Streamlit

How to use Anthropic claude-3.5-sonnet with Streamlit

June 21, 2024

It time to use Claude LLMs.

Lets have a look to Anthropic API and its models.

Claude API + Streamlit

Thanks to this project for inspiration: https://github.com/jw782cn/Claude-Streamlit

python -m venv chatbot #create it

chatbot\Scripts\activate #activate venv (windows)
source chatbot/bin/activate #(linux)
pip install -r requirements.txt #all at once
streamlit run claude.py

that project also supports OpenAI Models

Streamlit Chat with PDF with OpenAI

Getting Access to Anthropic API

The Power of Claude 3 API: Building a Generative AI App with Anthropic Claude AI

You need to take into consideration the Name as described at the Column ‘Latest 1P API model name’ in their web: https://docs.anthropic.com/en/docs/about-claude/models

  • claude-3-opus-20240229
  • claude-3-sonnet-20240229
  • claude-3.5-sonnet-20240620

Conclusions

I am building a multi LLM provider chat right here: https://github.com/JAlcocerT/Streamlit-MultiChat

Thanks to the learnings on how to use Claude with Python.

The way to call the API is a little bit different than the OpenAI one.

ℹ️
To get consistent API calls across providers, I need to have a look to the LiteLLM project

Its a good complement to the GROQ API for LLMs.

FAQ

Thanks to Fireship and the video: