File size: 808 Bytes
b1229df
8943693
 
 
 
 
 
 
9ec7f06
8943693
487fd82
 
 
 
 
 
 
 
 
 
 
 
 
 
cd4505d
487fd82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import openai
import streamlit as st

openai.api_key = os.getenv("OPENAI_API_KEY")

temperature = 0

prompt = st.text_area("Prompt")

st.markdown("----")
output_box = st.empty()

content = []

for chunk in openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    temperature=temperature,
    messages=[{"role": "user", "content": prompt}],
    stream=True,
):
    chunk_content = chunk["choices"][0].get("delta", {}).get("content")
    if chunk_content is not None:
        content.append(chunk_content)
    output = "".join(content).strip()
    output_box.markdown(output)

st.markdown("----")
st.subheader("共有用")

output = "".join(content).strip()
st.markdown(
    f"""
    ````
    ### Prompt
    ```
    {prompt}
    ```

    ### Output
    ```
    {output}
    ```
    ````
    """
)