ar12c commited on
Commit
bca0968
Β·
verified Β·
1 Parent(s): 6c9267b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # filename: okemo_backend.py
2
- # OkemoLLM backend β€” Streaming responses + DuckDuckGo + AI summarization
3
 
4
  import os
5
  import re
@@ -271,19 +271,22 @@ def perform_web_search(query: str) -> str:
271
  return ""
272
 
273
  # ------------------------
274
- # Summarization (AI-based) (Unchanged)
275
  # ------------------------
276
- def summarize_text_with_ai(text: str) -> str:
277
- """Use GPT model to summarize fetched text before use."""
 
 
 
 
278
  if not text.strip():
279
  return ""
280
- gpt_model.eval()
281
- prompt = f"Summarize this information in 2 short sentences:\n{text}"
282
- summary = ""
283
- # Use the generator function to get the summary
284
- for token in generate_response(prompt):
285
- summary += token
286
- return to_ascii(summary.strip())
287
 
288
  # ------------------------
289
  # Streaming Generator
@@ -339,9 +342,11 @@ def on_submit(user_message: str, history: Optional[List[List[str]]], train_input
339
  if is_search:
340
  query = WEB_TAG_RE.sub("", user_message).strip()
341
  raw = perform_web_search(query)
342
- search_summary = summarize_text_with_ai(raw)
 
 
343
 
344
- prefix = f"Based on summarized web info: {search_summary}. " if search_summary else ""
345
  full_prompt = f"{SYSTEM_INSTRUCTION} {prefix}{user_message}"
346
 
347
  current_state = train_input_state.copy()
@@ -353,7 +358,7 @@ def on_submit(user_message: str, history: Optional[List[List[str]]], train_input
353
 
354
  response_stream = generate_response(full_prompt)
355
  partial_reply = ""
356
- search_status = f"πŸ” Used summarized web info: {search_summary}" if search_summary else "No web info used."
357
 
358
  if not history or (history and history[-1][1] is not None):
359
  history.append([user_message, None])
@@ -375,7 +380,7 @@ def on_submit(user_message: str, history: Optional[List[List[str]]], train_input
375
  # Gradio Interface
376
  # ------------------------
377
  with gr.Blocks(title="OkemoLLM") as demo:
378
- gr.Markdown("# 🌐 OkemoLLM β€” Streaming DuckDuckGo + AI summarization")
379
  status = gr.Markdown(f"Ready. Current Checkpoint Iteration: **{start_iteration}**")
380
  chat = gr.Chatbot(height=400)
381
 
@@ -387,11 +392,11 @@ with gr.Blocks(title="OkemoLLM") as demo:
387
 
388
  gr.Markdown("---")
389
  gr.Markdown("## βš™οΈ Feedback-Based Training (Learn from Web Context)")
390
- gr.Markdown("**The training input automatically includes the web summary and your original prompt.**")
391
 
392
  with gr.Column():
393
  # This displays the full input context (System + Web Summary + User Prompt)
394
- prompt_display = gr.Textbox(label="Full Training Input (System + Web Summary + Prompt)", interactive=False)
395
  last_response_display = gr.Textbox(label="Model's Last Response", interactive=False)
396
  # This will be the Ground Truth/Target for training
397
  target_response = gr.Textbox(label="Desired Response (Ground Truth)", placeholder='Enter the correct/better response for the prompt above.', scale=1)
 
1
  # filename: okemo_backend.py
2
+ # OkemoLLM backend β€” Streaming responses + DuckDuckGo + AI summarization (REMOVED)
3
 
4
  import os
5
  import re
 
271
  return ""
272
 
273
  # ------------------------
274
+ # Web Content Preparation (Replaces AI summarization for max retention)
275
  # ------------------------
276
+ def prepare_web_content(text: str) -> str:
277
+ """
278
+ Prepare raw web text by truncating it to a maximal safe length
279
+ (500 characters) to ensure maximum retention while avoiding context overflow.
280
+ """
281
+ MAX_WEB_CONTENT_LENGTH = 500
282
  if not text.strip():
283
  return ""
284
+
285
+ prepared_text = to_ascii(text.strip())
286
+ if len(prepared_text) > MAX_WEB_CONTENT_LENGTH:
287
+ prepared_text = prepared_text[:MAX_WEB_CONTENT_LENGTH] + "..."
288
+
289
+ return prepared_text
 
290
 
291
  # ------------------------
292
  # Streaming Generator
 
342
  if is_search:
343
  query = WEB_TAG_RE.sub("", user_message).strip()
344
  raw = perform_web_search(query)
345
+ # --- MODIFIED: Use prepare_web_content to retain more raw search text ---
346
+ search_summary = prepare_web_content(raw)
347
+ # ------------------------------------------------------------------------
348
 
349
+ prefix = f"Based on web context: {search_summary}. " if search_summary else ""
350
  full_prompt = f"{SYSTEM_INSTRUCTION} {prefix}{user_message}"
351
 
352
  current_state = train_input_state.copy()
 
358
 
359
  response_stream = generate_response(full_prompt)
360
  partial_reply = ""
361
+ search_status = f"πŸ” Used web context (retaining up to 500 chars): {search_summary}" if search_summary else "No web info used."
362
 
363
  if not history or (history and history[-1][1] is not None):
364
  history.append([user_message, None])
 
380
  # Gradio Interface
381
  # ------------------------
382
  with gr.Blocks(title="OkemoLLM") as demo:
383
+ gr.Markdown("# 🌐 OkemoLLM β€” Streaming DuckDuckGo + Increased Web Retention")
384
  status = gr.Markdown(f"Ready. Current Checkpoint Iteration: **{start_iteration}**")
385
  chat = gr.Chatbot(height=400)
386
 
 
392
 
393
  gr.Markdown("---")
394
  gr.Markdown("## βš™οΈ Feedback-Based Training (Learn from Web Context)")
395
+ gr.Markdown("**The training input automatically includes the web context (up to 500 chars) and your original prompt.**")
396
 
397
  with gr.Column():
398
  # This displays the full input context (System + Web Summary + User Prompt)
399
+ prompt_display = gr.Textbox(label="Full Training Input (System + Web Context + Prompt)", interactive=False)
400
  last_response_display = gr.Textbox(label="Model's Last Response", interactive=False)
401
  # This will be the Ground Truth/Target for training
402
  target_response = gr.Textbox(label="Desired Response (Ground Truth)", placeholder='Enter the correct/better response for the prompt above.', scale=1)