Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ openai.api_key = os.getenv('OPENAI_KEY')
|
|
18 |
|
19 |
def chat_with_model(prompts):
|
20 |
model = "gpt-3.5-turbo"
|
21 |
-
#model = "gpt-4-32k"
|
22 |
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
23 |
conversation.extend([{'role': 'user', 'content': prompt} for prompt in prompts])
|
24 |
response = openai.ChatCompletion.create(model=model, messages=conversation)
|
@@ -68,7 +68,7 @@ def CompressXML(xml_text):
|
|
68 |
if isinstance(elem.tag, str) and 'Comment' in elem.tag:
|
69 |
elem.parent.remove(elem)
|
70 |
#return ET.tostring(root, encoding='unicode', method="xml")
|
71 |
-
return ET.tostring(root, encoding='unicode', method="xml")[:
|
72 |
|
73 |
|
74 |
def read_file_content(file):
|
@@ -93,6 +93,7 @@ def main():
|
|
93 |
st.title("Chat with AI")
|
94 |
|
95 |
prompts = ['']
|
|
|
96 |
|
97 |
user_prompt = st.text_area("Your question:", '', height=120)
|
98 |
uploaded_file = st.file_uploader("Choose a file", type=["xml", "json", "htm", "txt"])
|
@@ -109,11 +110,12 @@ def main():
|
|
109 |
response = chat_with_model(prompts)
|
110 |
st.write('Response:')
|
111 |
st.write(response)
|
|
|
112 |
filename = generate_filename(user_prompt)
|
113 |
create_file(filename, user_prompt, response)
|
114 |
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
115 |
|
116 |
-
if file_content
|
117 |
st.markdown(f"**Content Added to Prompt:**\n{file_content}")
|
118 |
|
119 |
htm_files = glob.glob("*.txt")
|
|
|
18 |
|
19 |
def chat_with_model(prompts):
|
20 |
model = "gpt-3.5-turbo"
|
21 |
+
#model = "gpt-4-32k" # 32k tokens between prompt and inference tokens
|
22 |
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
23 |
conversation.extend([{'role': 'user', 'content': prompt} for prompt in prompts])
|
24 |
response = openai.ChatCompletion.create(model=model, messages=conversation)
|
|
|
68 |
if isinstance(elem.tag, str) and 'Comment' in elem.tag:
|
69 |
elem.parent.remove(elem)
|
70 |
#return ET.tostring(root, encoding='unicode', method="xml")
|
71 |
+
return ET.tostring(root, encoding='unicode', method="xml")[:8000] # hack - top N characters to keep context document under token max
|
72 |
|
73 |
|
74 |
def read_file_content(file):
|
|
|
93 |
st.title("Chat with AI")
|
94 |
|
95 |
prompts = ['']
|
96 |
+
file_content = ""
|
97 |
|
98 |
user_prompt = st.text_area("Your question:", '', height=120)
|
99 |
uploaded_file = st.file_uploader("Choose a file", type=["xml", "json", "htm", "txt"])
|
|
|
110 |
response = chat_with_model(prompts)
|
111 |
st.write('Response:')
|
112 |
st.write(response)
|
113 |
+
|
114 |
filename = generate_filename(user_prompt)
|
115 |
create_file(filename, user_prompt, response)
|
116 |
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
117 |
|
118 |
+
if len(file_content) > 0:
|
119 |
st.markdown(f"**Content Added to Prompt:**\n{file_content}")
|
120 |
|
121 |
htm_files = glob.glob("*.txt")
|