Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
import streamlit.components.v1 as components
|
3 |
-
|
4 |
-
import openai
|
5 |
import os
|
6 |
import base64
|
7 |
import glob
|
@@ -18,8 +16,17 @@ import textract
|
|
18 |
import zipfile
|
19 |
import random
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
from datetime import datetime
|
22 |
-
from openai import Completion
|
23 |
from xml.etree import ElementTree as ET
|
24 |
from bs4 import BeautifulSoup
|
25 |
from collections import deque
|
@@ -158,7 +165,7 @@ def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
|
158 |
key = os.getenv('OPENAI_API_KEY')
|
159 |
openai.api_key = key
|
160 |
|
161 |
-
for chunk in
|
162 |
model='gpt-3.5-turbo',
|
163 |
messages=conversation,
|
164 |
temperature=0.5,
|
@@ -189,7 +196,7 @@ def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
|
|
189 |
conversation.append({'role': 'user', 'content': prompt})
|
190 |
if len(file_content)>0:
|
191 |
conversation.append({'role': 'assistant', 'content': file_content})
|
192 |
-
response =
|
193 |
return response['choices'][0]['message']['content']
|
194 |
|
195 |
|
|
|
1 |
import streamlit as st
|
2 |
import streamlit.components.v1 as components
|
|
|
|
|
3 |
import os
|
4 |
import base64
|
5 |
import glob
|
|
|
16 |
import zipfile
|
17 |
import random
|
18 |
|
19 |
+
import httpx # add 11/13/23
|
20 |
+
import asyncio
|
21 |
+
#from openai import OpenAI
|
22 |
+
from openai import AsyncOpenAI
|
23 |
+
client = AsyncOpenAI(
|
24 |
+
# defaults to os.environ.get("OPENAI_API_KEY")
|
25 |
+
# api_key="My API Key",
|
26 |
+
)
|
27 |
+
|
28 |
+
|
29 |
from datetime import datetime
|
|
|
30 |
from xml.etree import ElementTree as ET
|
31 |
from bs4 import BeautifulSoup
|
32 |
from collections import deque
|
|
|
165 |
key = os.getenv('OPENAI_API_KEY')
|
166 |
openai.api_key = key
|
167 |
|
168 |
+
for chunk in client.chat.completions.create(
|
169 |
model='gpt-3.5-turbo',
|
170 |
messages=conversation,
|
171 |
temperature=0.5,
|
|
|
196 |
conversation.append({'role': 'user', 'content': prompt})
|
197 |
if len(file_content)>0:
|
198 |
conversation.append({'role': 'assistant', 'content': file_content})
|
199 |
+
response = client.chat.completions.create(model=model_choice, messages=conversation)
|
200 |
return response['choices'][0]['message']['content']
|
201 |
|
202 |
|