Benjamin Consolvo
commited on
Commit
·
8fced99
1
Parent(s):
cbc7aa1
initial files test
Browse files- app.py +73 -0
- model_info.json +17 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ©2024 Intel Corporation
|
| 2 |
+
# Permission is granted for recipient to internally use and modify this software for purposes of benchmarking and testing on Intel architectures.
|
| 3 |
+
# This software is provided "AS IS" possibly with faults, bugs or errors; it is not intended for production use, and recipient uses this design at their own risk with no liability to Intel.
|
| 4 |
+
# Intel disclaims all warranties, express or implied, including warranties of merchantability, fitness for a particular purpose, and non-infringement.
|
| 5 |
+
# Recipient agrees that any feedback it provides to Intel about this software is licensed to Intel for any purpose worldwide. No permission is granted to use Intel’s trademarks.
|
| 6 |
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the code.
|
| 7 |
+
|
| 8 |
+
# Import necessary libraries
|
| 9 |
+
|
| 10 |
+
import streamlit as st
|
| 11 |
+
import os
|
| 12 |
+
from openai import OpenAI
|
| 13 |
+
import json
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
working_dir = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
+
endpoint_data = json.load(open(f"{working_dir}/model_info.json"))
|
| 19 |
+
|
| 20 |
+
def clear_chat():
|
| 21 |
+
st.session_state.messages = []
|
| 22 |
+
|
| 23 |
+
st.title("Chat Bot")
|
| 24 |
+
|
| 25 |
+
# Extract the keys (model names) from the JSON data
|
| 26 |
+
model_names = list(endpoint_data.keys())
|
| 27 |
+
|
| 28 |
+
with st.sidebar:
|
| 29 |
+
modelname = st.selectbox("Select a LLM model (Hosted by DENVR DATAWORKS) ", model_names)
|
| 30 |
+
st.write(f"You selected: {modelname}")
|
| 31 |
+
st.button("Start New Chat", on_click=clear_chat)
|
| 32 |
+
|
| 33 |
+
endpoint = endpoint_data[modelname]
|
| 34 |
+
|
| 35 |
+
api_key=os.environ.get('API_KEY')
|
| 36 |
+
|
| 37 |
+
if not api_key:
|
| 38 |
+
st.info("Please add your OpenAI API key to continue.")
|
| 39 |
+
st.stop()
|
| 40 |
+
base_url = endpoint
|
| 41 |
+
client = OpenAI(api_key=api_key, base_url=base_url)
|
| 42 |
+
|
| 43 |
+
# Extract the model name
|
| 44 |
+
models = client.models.list()
|
| 45 |
+
modelname = models.data[0].id
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
if "messages" not in st.session_state:
|
| 49 |
+
st.session_state.messages = []
|
| 50 |
+
|
| 51 |
+
for message in st.session_state.messages:
|
| 52 |
+
with st.chat_message(message["role"]):
|
| 53 |
+
st.markdown(message["content"])
|
| 54 |
+
|
| 55 |
+
if prompt := st.chat_input("What is up?"):
|
| 56 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 57 |
+
with st.chat_message("user"):
|
| 58 |
+
st.markdown(prompt)
|
| 59 |
+
|
| 60 |
+
with st.chat_message("assistant"):
|
| 61 |
+
stream = client.chat.completions.create(
|
| 62 |
+
model=modelname,
|
| 63 |
+
messages=[
|
| 64 |
+
{"role": m["role"], "content": m["content"]}
|
| 65 |
+
for m in st.session_state.messages
|
| 66 |
+
],
|
| 67 |
+
max_tokens=5000,
|
| 68 |
+
stream=True,
|
| 69 |
+
)
|
| 70 |
+
response = st.write_stream(stream)
|
| 71 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 72 |
+
|
| 73 |
+
|
model_info.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"Meta-Llama-3.1-70B-Instruct": "https://inference-api.cloud.denvrdata.com/Meta-Llama-3.1-70B-Instruct/v1/",
|
| 3 |
+
"Meta-Llama-3.1-8B-Instruct": "https://inference-api.cloud.denvrdata.com/Meta-Llama-3.1-8B-Instruct/v1/",
|
| 4 |
+
"CodeLlama-34b-Instruct-hf": "https://inference-api.cloud.denvrdata.com/CodeLlama-34b-Instruct/v1/",
|
| 5 |
+
"Mistral-7B-Instruct-v0.3": "https://inference-api.cloud.denvrdata.com/Mistral-7B-Instruct/v1/",
|
| 6 |
+
"Mixtral-8x7B-Instruct-v0.1": "https://inference-api.cloud.denvrdata.com/Mixtral-7B-Instruct/v1/",
|
| 7 |
+
"DENVR: tiiuae/Falcon3-7B-Instruct": "https://inference-api.cloud.denvrdata.com/Falcon3-7B-Instruct/v1/",
|
| 8 |
+
"DENVR: meta-Llama-3.3-70B-Instruct": "https://inference-api.cloud.denvrdata.com/Llama-3.3-70B-Instruct/v1/",
|
| 9 |
+
"DENVR: meta-llama/Meta-Llama-3.1-70B-Instruct": "https://inference-api.cloud.denvrdata.com/Meta-Llama-3.1-70B-Instruct/v1/",
|
| 10 |
+
"DENVR: meta-llama/Meta-Llama-3.1-8B-Instruct": "https://inference-api.cloud.denvrdata.com/Meta-Llama-3.1-8B-Instruct/v1/",
|
| 11 |
+
"DENVR: codellama/CodeLlama-34b-Instruct-hf": "https://inference-api.cloud.denvrdata.com/CodeLlama-34b-Instruct/v1/",
|
| 12 |
+
"DENVR: mistralai/Mistral-7B-Instruct-v0.3": "https://inference-api.cloud.denvrdata.com/Mistral-7B-Instruct/v1/",
|
| 13 |
+
"DENVR: mistralai/Mixtral-8x7B-Instruct-v0.1": "https://inference-api.cloud.denvrdata.com/Mixtral-7B-Instruct/v1/",
|
| 14 |
+
"DENVR: tiiuae/Falcon3-7B-Instruct": "https://inference-api.cloud.denvrdata.com/Falcon3-7B-Instruct/v1/",
|
| 15 |
+
"DENVR: deepseek-ai/DeepSeek-R1-Distill-Llama-8B": "https://inference-api.cloud.denvrdata.com/DeepSeek-R1-Distill-Llama-8B/v1/",
|
| 16 |
+
"DENVR: deepseek-ai/DeepSeek-R1-Distill-Llama-70B": "https://inference-api.cloud.denvrdata.com/DeepSeek-R1-Distill-Llama-70B/v1"
|
| 17 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
openai
|