diff --git a/README.md b/README.md index a0cc3820f..df388e92c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/streamlit/llm-examples?quickstart=1) +[![litellm](https://img.shields.io/badge/%20%F0%9F%9A%85%20liteLLM-chatGPT%7CAzure%7CAnthropic-blue?color=green)](https://github.com/BerriAI/litellm) + + Starter examples for building LLM apps with Streamlit. ## Overview of the App @@ -15,6 +18,7 @@ Current examples include: - LangChain Quickstart - LangChain PromptTemplate - LangChain Search +- LiteLLM Playground - Run 1 prompt on Claude2, Claude 1.2, GPT-3.5, GPT-4 ## Demo App diff --git a/pages/2_lite_LLM_Quickstart.py b/pages/2_lite_LLM_Quickstart.py new file mode 100644 index 000000000..7b6ccfc18 --- /dev/null +++ b/pages/2_lite_LLM_Quickstart.py @@ -0,0 +1,74 @@ +import streamlit as st +import threading +import os +from litellm import completion +from dotenv import load_dotenv + +# load .env, so litellm reads from .env +load_dotenv() + +# Function to get model outputs +def get_model_output(prompt, model_name): + messages = [ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": prompt}, + ] + response = completion(messages=messages, model=model_name) + + return response['choices'][0]['message']['content'] + +# Function to get model outputs +def get_model_output_thread(prompt, model_name, outputs, idx): + output = get_model_output(prompt, model_name) + outputs[idx] = output + +# Streamlit app + +st.title("liteLLM API Playground - use 50+ LLM Models") +st.markdown("[Powered by liteLLM - one package for Anthropic, Cohere, OpenAI, Replicate](https://github.com/BerriAI/litellm/)") + +# Sidebar for user input +with st.sidebar: + st.header("User Settings") + anthropic_api_key = st.text_input("Enter your Anthropic API key:", type="password") + openai_api_key = st.text_input("Enter your OpenAI API key:", type="password") + set_keys_button = st.button("Set API Keys") + +if set_keys_button: + if anthropic_api_key: + os.environ["ANTHROPIC_API_KEY"] = anthropic_api_key + if openai_api_key: + os.environ["OPENAI_API_KEY"] = openai_api_key + st.success("API keys have been set.") + +# User Input section +with st.sidebar: + st.header("User Input") + prompt = st.text_area("Enter your prompt here:") + submit_button = st.button("Submit") + +# Main content area to display model outputs +st.header("Model Outputs") + +# List of models to test +model_names = ["claude-instant-1.2", "claude-2", "gpt-3.5-turbo", "gpt-4", ] # Add your model names here + +cols = st.columns(len(model_names)) # Create columns +outputs = [""] * len(model_names) # Initialize outputs list with empty strings + +threads = [] + +if submit_button and prompt: + for idx, model_name in enumerate(model_names): + thread = threading.Thread(target=get_model_output_thread, args=(prompt, model_name, outputs, idx)) + threads.append(thread) + thread.start() + + for thread in threads: + thread.join() + +# Display text areas and fill with outputs if available +for idx, model_name in enumerate(model_names): + with cols[idx]: + st.text_area(label=f"{model_name}", value=outputs[idx], height=300, key=f"output_{model_name}_{idx}") # Use a unique key + diff --git a/pages/2_Chat_with_search.py b/pages/3_Chat_with_search.py similarity index 100% rename from pages/2_Chat_with_search.py rename to pages/3_Chat_with_search.py diff --git a/pages/3_Langchain_Quickstart.py b/pages/4_Langchain_Quickstart.py similarity index 100% rename from pages/3_Langchain_Quickstart.py rename to pages/4_Langchain_Quickstart.py diff --git a/pages/4_Langchain_PromptTemplate.py b/pages/5_Langchain_PromptTemplate.py similarity index 100% rename from pages/4_Langchain_PromptTemplate.py rename to pages/5_Langchain_PromptTemplate.py diff --git a/pages/5_Chat_with_user_feedback.py b/pages/6_Chat_with_user_feedback.py similarity index 100% rename from pages/5_Chat_with_user_feedback.py rename to pages/6_Chat_with_user_feedback.py diff --git a/requirements.txt b/requirements.txt index 24465cad9..a78ef0c78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ openai duckduckgo-search anthropic>=0.3.0 trubrics>=1.4.3 +litellm>=0.1.380