Add1E commited on
Commit
b1abb7f
·
verified ·
1 Parent(s): d13fe78

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ import time
4
+
5
+ openai.api_type = "azure"
6
+ openai.api_version = "2023-12-01-preview"
7
+ API_VERZEICHNIS = [
8
+ {"url":"https://tensora-oai-france.openai.azure.com/", "model" : "gpt-4-1106", "key" : ""},
9
+ {"url": "https://tensora-oai.openai.azure.com/", "model" : "gpt-4-0613", "key" : ""},
10
+ {"url":"https://tensora-oai-france.openai.azure.com/", "model" : "gpt-4-1106", "key" : ""},
11
+ {"url":"https://tensora-oai-france.openai.azure.com/", "model" : "gpt-4-1106", "key" : ""}
12
+ ]
13
+
14
+ if st.button("Test"):
15
+ prompt = "Tell me a 3 paragraph story"
16
+ for api in API_VERZEICHNIS:
17
+ st.code(f"{api['url']} + Model: {api['model']}")
18
+ openai.api_key=api["key"]
19
+ openai.api_base=api["url"]
20
+ try:
21
+ start_time = time.time()
22
+ response = openai.ChatCompletion.create(
23
+ engine=api["model"],
24
+ temperature = 0.2,
25
+ messages=[
26
+ {"role": "system", "content": prompt}
27
+ ],
28
+ )
29
+ end_time = time.time()
30
+ except Exception as e2:
31
+ st.error(e2)
32
+ time_in_s = end_time-start_time
33
+ #st.write(response.choices[0].message["content"])
34
+ tokens_pro_sek = round(response["usage"]["completion_tokens"]/time_in_s,2)
35
+ st.write(f"Used Completion Tokens: {response['usage']['completion_tokens']}, Used Time: {round(time_in_s,2)}")
36
+ st.write(f"Tokens per second: {tokens_pro_sek}")