fugthchat commited on
Commit
2b4f843
·
verified ·
1 Parent(s): 0b84830

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -128,6 +128,8 @@ async def generate_story(prompt: StoryPrompt):
128
  logging.error(f"Failed to get model for choice: {prompt.model_choice}")
129
  return JSONResponse(status_code=503, content={"error": "The AI model is not available or failed to load."})
130
 
 
 
131
  final_prompt = f"""<|user|>
132
  Here is the story so far:
133
  {prompt.story_memory}
@@ -136,3 +138,26 @@ Here is the part I just wrote or want to continue from:
136
  {prompt.prompt}
137
 
138
  Please use this feedback to guide the next chapter:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  logging.error(f"Failed to get model for choice: {prompt.model_choice}")
129
  return JSONResponse(status_code=503, content={"error": "The AI model is not available or failed to load."})
130
 
131
+ # This is the string that was broken.
132
+ # It starts with f""" and ends with """.
133
  final_prompt = f"""<|user|>
134
  Here is the story so far:
135
  {prompt.story_memory}
 
138
  {prompt.prompt}
139
 
140
  Please use this feedback to guide the next chapter:
141
+ {prompt.feedback}
142
+
143
+ Generate the next part of the story.<|endoftext|>
144
+ <|assistant|>"""
145
+
146
+ logging.info(f"Generating with {prompt.model_choice}...")
147
+ output = llm(
148
+ final_prompt,
149
+ max_tokens=512,
150
+ stop=["<|user|>", "<|endoftext|>"],
151
+ echo=False
152
+ )
153
+
154
+ generated_text = output["choices"][0]["text"].strip()
155
+ logging.info("Generation complete.")
156
+
157
+ return {"story_text": generated_text}
158
+
159
+ except Exception as e:
160
+ logging.error(f"An internal error occurred during generation: {e}", exc_info=True)
161
+ return JSONResponse(status_code=500, content={"error": "An unexpected error occurred."})
162
+ finally:
163
+ logging.info("Releasing model lock.")