cryogenic22 commited on
Commit
2996e1f
·
verified ·
1 Parent(s): b308c3d

Update selfapi_writer.py

Browse files
Files changed (1) hide show
  1. selfapi_writer.py +37 -36
selfapi_writer.py CHANGED
@@ -55,11 +55,8 @@ class SelfApiWriter:
55
  overview_response = self.client.messages.create(
56
  model=self.model,
57
  max_tokens=1000,
 
58
  messages=[
59
- {
60
- "role": "system",
61
- "content": "You are an expert at creating concise summaries of book blueprints."
62
- },
63
  {
64
  "role": "user",
65
  "content": f"""The following blueprint was truncated due to length constraints.
@@ -89,6 +86,7 @@ class SelfApiWriter:
89
  # Truncate blueprint if too long
90
  truncated_blueprint, overview_summary = self._truncate_blueprint(blueprint)
91
 
 
92
  system_prompt = """You are an expert book planner analyzing a blueprint.
93
  Extract ALL relevant information and return it in a structured format.
94
  Include:
@@ -154,6 +152,9 @@ class SelfApiWriter:
154
  self.writing_guidelines = extracted_info["guidelines"]
155
  self.initialized = True
156
 
 
 
 
157
  return extracted_info
158
 
159
  except Exception as e:
@@ -172,24 +173,24 @@ class SelfApiWriter:
172
  # Iterative generation for introduction
173
  full_intro_content = ""
174
  for iteration in range(1, self.max_iterations + 1):
 
 
 
 
 
 
 
 
 
 
 
 
175
  response = self.client.messages.create(
176
  model=self.model,
177
  max_tokens=2000,
178
  temperature=0.7,
 
179
  messages=[
180
- {
181
- "role": "system",
182
- "content": f"""You are writing the introduction for '{self.book_info.get('title', 'Untitled Book')}'
183
- Full Blueprint Context:
184
- {full_blueprint}
185
-
186
- Core Vision: {self.book_info.get('vision', '')}
187
- Target Audience: {self.book_info.get('target_audience', '')}
188
-
189
- Writing Style: {self.writing_guidelines.get('style', 'Academic and clear')}
190
- Tone: {self.writing_guidelines.get('tone', 'Professional')}
191
- """
192
- },
193
  {
194
  "role": "user",
195
  "content": f"""Write the introduction: "{self.book_structure.get('introduction', 'Book Introduction')}"
@@ -239,30 +240,30 @@ class SelfApiWriter:
239
  # Iterative generation for chapter
240
  full_chapter_content = ""
241
  for iteration in range(1, self.max_iterations + 1):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  response = self.client.messages.create(
243
  model=self.model,
244
  max_tokens=2000,
245
  temperature=0.7,
 
246
  messages=[
247
- {
248
- "role": "system",
249
- "content": f"""You are writing '{self.book_info.get('title', 'Untitled Book')}'
250
- Full Blueprint Context:
251
- {full_blueprint}
252
-
253
- Chapter: {chapter_title}
254
- Part: {part_title}
255
-
256
- Target Audience: {self.book_info.get('target_audience', '')}
257
- Writing Style: {self.writing_guidelines.get('style', 'Academic and clear')}
258
- Tone: {self.writing_guidelines.get('tone', 'Professional')}
259
-
260
- Chapter Structure Requirements:
261
- {', '.join(self.writing_guidelines.get('chapter_structure', []))}
262
-
263
- Content Requirements:
264
- {', '.join(self.writing_guidelines.get('content_requirements', []))}"""
265
- },
266
  {
267
  "role": "user",
268
  "content": f"""Write Chapter: "{chapter_title}" in Part {part_idx + 1}: "{part_title}"
 
55
  overview_response = self.client.messages.create(
56
  model=self.model,
57
  max_tokens=1000,
58
+ system="You are an expert at creating concise summaries of book blueprints.",
59
  messages=[
 
 
 
 
60
  {
61
  "role": "user",
62
  "content": f"""The following blueprint was truncated due to length constraints.
 
86
  # Truncate blueprint if too long
87
  truncated_blueprint, overview_summary = self._truncate_blueprint(blueprint)
88
 
89
+ # Prepare system prompt for blueprint processing
90
  system_prompt = """You are an expert book planner analyzing a blueprint.
91
  Extract ALL relevant information and return it in a structured format.
92
  Include:
 
152
  self.writing_guidelines = extracted_info["guidelines"]
153
  self.initialized = True
154
 
155
+ # Store full blueprint in context
156
+ self.context['full_original_blueprint'] = blueprint
157
+
158
  return extracted_info
159
 
160
  except Exception as e:
 
173
  # Iterative generation for introduction
174
  full_intro_content = ""
175
  for iteration in range(1, self.max_iterations + 1):
176
+ # Prepare system prompt with full context
177
+ system_prompt = f"""You are writing the introduction for '{self.book_info.get('title', 'Untitled Book')}'
178
+ Full Blueprint Context:
179
+ {full_blueprint}
180
+
181
+ Core Vision: {self.book_info.get('vision', '')}
182
+ Target Audience: {self.book_info.get('target_audience', '')}
183
+
184
+ Writing Style: {self.writing_guidelines.get('style', 'Academic and clear')}
185
+ Tone: {self.writing_guidelines.get('tone', 'Professional')}
186
+ """
187
+
188
  response = self.client.messages.create(
189
  model=self.model,
190
  max_tokens=2000,
191
  temperature=0.7,
192
+ system=system_prompt,
193
  messages=[
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  {
195
  "role": "user",
196
  "content": f"""Write the introduction: "{self.book_structure.get('introduction', 'Book Introduction')}"
 
240
  # Iterative generation for chapter
241
  full_chapter_content = ""
242
  for iteration in range(1, self.max_iterations + 1):
243
+ # Prepare system prompt with full context
244
+ system_prompt = f"""You are writing '{self.book_info.get('title', 'Untitled Book')}'
245
+ Full Blueprint Context:
246
+ {full_blueprint}
247
+
248
+ Chapter: {chapter_title}
249
+ Part: {part_title}
250
+
251
+ Target Audience: {self.book_info.get('target_audience', '')}
252
+ Writing Style: {self.writing_guidelines.get('style', 'Academic and clear')}
253
+ Tone: {self.writing_guidelines.get('tone', 'Professional')}
254
+
255
+ Chapter Structure Requirements:
256
+ {', '.join(self.writing_guidelines.get('chapter_structure', []))}
257
+
258
+ Content Requirements:
259
+ {', '.join(self.writing_guidelines.get('content_requirements', []))}"""
260
+
261
  response = self.client.messages.create(
262
  model=self.model,
263
  max_tokens=2000,
264
  temperature=0.7,
265
+ system=system_prompt,
266
  messages=[
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  {
268
  "role": "user",
269
  "content": f"""Write Chapter: "{chapter_title}" in Part {part_idx + 1}: "{part_title}"