Update app.py
Browse files
app.py
CHANGED
|
@@ -130,27 +130,36 @@ def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
|
| 130 |
|
| 131 |
# iterate through the stream of events
|
| 132 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
response = openai.ChatCompletion.create(
|
| 134 |
model='gpt-3.5-turbo',
|
| 135 |
messages=conversation,
|
| 136 |
temperature=0.5,
|
| 137 |
-
stream=True
|
| 138 |
)
|
| 139 |
collected_chunks = []
|
| 140 |
collected_messages = []
|
|
|
|
|
|
|
| 141 |
for chunk in response:
|
| 142 |
-
#
|
| 143 |
-
|
| 144 |
-
chunk_message
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
full_reply_content = ''.join([m.get('content', '') for m in collected_messages])
|
| 153 |
-
st.write(f"Full conversation received: {full_reply_content}")
|
| 154 |
st.write("Elapsed time:")
|
| 155 |
st.write(time.time() - start_time)
|
| 156 |
return full_reply_content
|
|
|
|
| 130 |
|
| 131 |
# iterate through the stream of events
|
| 132 |
start_time = time.time()
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
report = []
|
| 136 |
+
res_box = st.empty()
|
| 137 |
response = openai.ChatCompletion.create(
|
| 138 |
model='gpt-3.5-turbo',
|
| 139 |
messages=conversation,
|
| 140 |
temperature=0.5,
|
| 141 |
+
stream=True
|
| 142 |
)
|
| 143 |
collected_chunks = []
|
| 144 |
collected_messages = []
|
| 145 |
+
|
| 146 |
+
|
| 147 |
for chunk in response:
|
| 148 |
+
#collected_chunks.append(chunk) # save the event response
|
| 149 |
+
#chunk_message = chunk['choices'][0]['delta'] # extract the message
|
| 150 |
+
#collected_messages.append(chunk_message) # save the message
|
| 151 |
+
#content=chunk["choices"][0].get("delta",{}).get("content")
|
| 152 |
+
# join method to concatenate the elements of the list
|
| 153 |
+
# into a single string,
|
| 154 |
+
# then strip out any empty strings
|
| 155 |
+
|
| 156 |
+
report.append(chunk.choices[0].text)
|
| 157 |
+
result = "".join(report).strip()
|
| 158 |
+
result = result.replace("\n", "")
|
| 159 |
+
res_box.markdown(f'*{result}*')
|
| 160 |
+
|
| 161 |
full_reply_content = ''.join([m.get('content', '') for m in collected_messages])
|
| 162 |
+
#st.write(f"Full conversation received: {full_reply_content}")
|
| 163 |
st.write("Elapsed time:")
|
| 164 |
st.write(time.time() - start_time)
|
| 165 |
return full_reply_content
|