yxmnjxzx commited on
Commit
0c5522c
·
verified ·
1 Parent(s): b51fc11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -103
app.py CHANGED
@@ -97,119 +97,48 @@ class PromptRefiner:
97
  {
98
  "role": "system",
99
  "content": """You are a markdown formatting expert. Format your responses with proper spacing and structure following these rules:
100
-
101
- 1. Paragraph Spacing:
102
- - Add TWO blank lines between major sections (##)
103
- - Add ONE blank line between subsections (###)
104
- - Add ONE blank line between paragraphs within sections
105
- - Add ONE blank line before and after lists
106
- - Add ONE blank line before and after code blocks
107
- - Add ONE blank line before and after blockquotes
108
-
109
- 2. Section Formatting:
110
- # Title
111
-
112
- ## Major Section
113
-
114
- [blank line]
115
- Content paragraph 1
116
- [blank line]
117
- Content paragraph 2
118
- [blank line]
119
-
120
- ### Subsection
121
- [blank line]
122
- Content
123
- [blank line]
124
-
125
- 3. List Formatting:
126
- [blank line]
127
- - List item 1
128
- - List item 2
129
- - List item 3
130
- [blank line]
131
-
132
- 4. JSON Output Structure:
133
- {
134
- "section_name": "
135
- Content paragraph 1
136
-
137
- Content paragraph 2
138
-
139
- - List item 1
140
- - List item 2
141
- "
142
- }
143
-
144
- Transform content while maintaining clear visual separation between elements. Each logical section should be clearly distinguished with appropriate spacing."""
145
- },
146
- {
147
- "role": "user",
148
- "content": prompt
149
- }
150
- ]
151
- ''' messages = [
152
- {
153
- "role": "system",
154
- "content": """You are a professional markdown formatting expert. Transform any content into well-structured documentation following these precise rules:
155
-
156
- 1. Document Structure:
157
- - Start with # for main title
158
- - Use ## for major sections
159
- - Use ### for subsections
160
- - Add > blockquote for key summaries or important notes
161
- - Separate major sections with ---
162
-
163
- 2. Content Types:
164
- Technical:
165
- - Use ```language for code blocks
166
- - Format inline code with `backticks`
167
- - Use $$ $$ for math equations
168
- - Create tables for comparisons or data
169
- - Use bullet points for features/characteristics
170
-
171
- Narrative:
172
- - Format dialogue with proper quotations
173
- - Use *italics* for emphasis
174
- - Keep paragraphs focused and concise
175
-
176
- Instructional:
177
- - Use numbered lists for steps
178
- - Bold key terms with **emphasis**
179
- - Add examples in code blocks
180
- - Use tables for parameter explanations
181
-
182
- 3. Visual Organization:
183
- - Maximum 3 levels of headers
184
- - Short paragraphs (3-5 sentences)
185
- - Consistent spacing between sections
186
- - Clear hierarchy in information
187
- - Strategic use of line breaks
188
-
189
- 4. Special Elements:
190
- - Tables for structured comparisons
191
- - Fenced code blocks with language specification
192
- - Blockquotes for summaries/key points
193
- - Lists only when necessary
194
- - LaTeX for mathematical notation
195
-
196
- Transform the content while maintaining clarity, professionalism, and readability. Focus on creating a logical flow that enhances understanding."""
197
  },
198
  {
199
  "role": "user",
200
  "content": prompt
201
  }
202
- ]'''
203
  response = self.client.chat.completions.create(
204
  model=model,
205
  messages=messages,
206
  max_tokens=8000, # Increased token limit
207
- temperature=0.8
 
208
  )
209
-
210
- output = response.choices[0].message.content.strip()
211
- # Basic post-processing
212
- return output.replace('\n\n', '\n').strip()
 
 
 
 
 
 
213
 
214
  except Exception as e:
215
  return f"Error: {str(e)}"
 
97
  {
98
  "role": "system",
99
  "content": """You are a markdown formatting expert. Format your responses with proper spacing and structure following these rules:
100
+
101
+ 1. Paragraph Spacing:
102
+ - Add TWO blank lines between major sections (##)
103
+ - Add ONE blank line between subsections (###)
104
+ - Add ONE blank line between paragraphs within sections
105
+ - Add ONE blank line before and after lists
106
+ - Add ONE blank line before and after code blocks
107
+ - Add ONE blank line before and after blockquotes
108
+
109
+ 2. Section Formatting:
110
+ # Title
111
+
112
+ ## Major Section
113
+
114
+ [blank line]
115
+ Content paragraph 1
116
+ [blank line]
117
+ Content paragraph 2
118
+ [blank line]"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  },
120
  {
121
  "role": "user",
122
  "content": prompt
123
  }
124
+ ]
125
  response = self.client.chat.completions.create(
126
  model=model,
127
  messages=messages,
128
  max_tokens=8000, # Increased token limit
129
+ temperature=0.8,
130
+ stream=True # Enable streaming in the API call
131
  )
132
+ # Initialize an empty string to accumulate the response
133
+ full_response = ""
134
+
135
+ # Process the streaming response
136
+ for chunk in response:
137
+ if chunk.choices[0].delta.content is not None:
138
+ full_response += chunk.choices[0].delta.content
139
+
140
+ # Return the complete response
141
+ return full_response.replace('\n\n', '\n').strip()
142
 
143
  except Exception as e:
144
  return f"Error: {str(e)}"