lianghsun commited on
Commit
3f5b8e9
·
1 Parent(s): 0c27bcc

First commit

Browse files
Files changed (2) hide show
  1. app.py +68 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from openai import OpenAI, AzureOpenAI
3
+ from typing import Iterator
4
+ import os
5
+ from phoenix.otel import register
6
+
7
+ tracer_provider = register(
8
+ project_name=st.secrets['PHOENIX_PROJECT_NAME'],
9
+ endpoint="https://app.phoenix.arize.com/v1/traces"
10
+ )
11
+
12
+ from openinference.instrumentation.openai import OpenAIInstrumentor
13
+ OpenAIInstrumentor().instrument(tracer_provider=tracer_provider)
14
+
15
+ st.set_page_config(
16
+ page_title="Free GPT-4o Chat",
17
+ page_icon="💬",
18
+ layout="centered"
19
+ )
20
+
21
+ st.title("💬 GPT-4o Chat")
22
+ with st.expander("Notice"):
23
+ st.write('''
24
+ Please note that this app collects your conversation records.
25
+ Do not input any personal or sensitive information, such as:
26
+ - National identification numbers
27
+ - Contact information (phone numbers, email addresses)
28
+ - Bank account or credit card details
29
+ - Health or medical information
30
+ - Any other data that can be used to identify you
31
+
32
+ Use this app cautiously and avoid sharing sensitive data.
33
+ Do not use this app in inappropriate contexts. By using this app, you agree to these terms and conditions.
34
+ ''')
35
+
36
+ client = AzureOpenAI(
37
+ api_key=st.secrets['API_KEY'],
38
+ api_version=st.secrets['API_VERSION'],
39
+ azure_endpoint=st.secrets['ENDPOINT']
40
+ )
41
+
42
+ if "openai_model" not in st.session_state:
43
+ st.session_state["openai_model"] = st.secrets['MODEL']
44
+
45
+ if "messages" not in st.session_state:
46
+ st.session_state.messages = []
47
+
48
+ for message in st.session_state.messages:
49
+ with st.chat_message(message["role"]):
50
+ st.markdown(message["content"])
51
+
52
+ if prompt := st.chat_input("What is up?"):
53
+ st.session_state.messages.append({"role": "user", "content": prompt})
54
+ with st.chat_message("user"):
55
+ st.markdown(prompt)
56
+
57
+ with st.chat_message("assistant"):
58
+ stream = client.chat.completions.create(
59
+ model=st.session_state["openai_model"],
60
+ messages=[
61
+ {"role": m["role"], "content": m["content"]}
62
+ for m in st.session_state.messages
63
+ ],
64
+ stream=True,
65
+ )
66
+ response = st.write_stream(stream)
67
+ st.session_state.messages.append(
68
+ {"role": "assistant", "content": response})
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit==1.36.0
2
+ openai==1.55.3
3
+ arize-phoenix==5.12.0
4
+ openinference-instrumentation==0.1.18
5
+ openinference-instrumentation-openai==0.1.18