ar12c commited on
Commit
856af02
·
verified ·
1 Parent(s): d7038d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -16,11 +16,12 @@ import gradio as gr
16
 
17
  os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
18
 
19
- # --- SYSTEM INSTRUCTION MODIFIED to force web context into the response ---
20
  SYSTEM_INSTRUCTION = (
21
- "You are Okemo Language Model (OLM), a concise and helpful assistant. "
22
- "When web context is provided, you MUST start your response with the phrase 'Search Context: [The provided web context] ' "
23
- "followed by your concise answer. For complex queries, first generate an internal reasoning chain (DO NOT show it to the user)."
 
24
  )
25
  # -------------------------------------------------------------------------
26
 
@@ -332,8 +333,8 @@ def generate_response(prompt: str) -> Iterator[str]:
332
  input_tensor = torch.tensor(input_ids, dtype=torch.long, device=device).unsqueeze(0)
333
  generated_token_ids = []
334
 
335
- # --- TEMPERATURE = 0.6 to favor deterministic copying/output ---
336
- temperature = 0.6
337
  # ----------------------------------------------------------------------
338
 
339
  eos_id = voc.word2index[voc.EOS]
@@ -368,12 +369,12 @@ def generate_response(prompt: str) -> Iterator[str]:
368
  yield word + " "
369
 
370
  # ------------------------
371
- # Core Chat Handler (Guardrail removed)
372
  # ------------------------
373
  def on_submit(user_message: str, history: Optional[List[List[str]]], train_input_state: Dict[str, str], *_):
374
  """
375
  Token-by-token chat handler.
376
- Allows AI model core to generate response for all inputs.
377
  """
378
  history = history or []
379
  user_message = re.sub(r'\(Attached:.*?\)|\[IMAGE_PREVIEW_URL:.*?]', '', user_message or "").strip()
@@ -387,7 +388,7 @@ def on_submit(user_message: str, history: Optional[List[List[str]]], train_input
387
  raw = perform_web_search(query)
388
  search_summary = prepare_web_content(raw)
389
 
390
- # The instruction now handles prepending the search context.
391
  prefix = f"The provided web context is: {search_summary}. " if search_summary else ""
392
  full_prompt = f"{SYSTEM_INSTRUCTION} {prefix}{user_message}"
393
 
@@ -422,7 +423,7 @@ def on_submit(user_message: str, history: Optional[List[List[str]]], train_input
422
  # Gradio Interface
423
  # ------------------------
424
  with gr.Blocks(title="OkemoLLM") as demo:
425
- gr.Markdown("# 🌐 OkemoLLM — Streaming DuckDuckGo + Web Context in Response")
426
  status = gr.Markdown(f"Ready. Current Checkpoint Iteration: **{start_iteration}**")
427
  chat = gr.Chatbot(height=400)
428
 
 
16
 
17
  os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
18
 
19
+ # --- SYSTEM INSTRUCTION MODIFIED FOR CHATGPT-LIKE BEHAVIOR ---
20
  SYSTEM_INSTRUCTION = (
21
+ "You are Okemo Language Model (OLM), a highly **helpful, verbose, and comprehensive** AI assistant, similar to ChatGPT. "
22
+ "Your goal is to provide detailed and well-structured answers in a conversational tone. "
23
+ "For complex queries, first generate an internal reasoning chain (DO NOT show it to the user). "
24
+ "If external context is provided, **naturally integrate that knowledge** into your answer; do not use a fixed prefix like 'Search Context:'."
25
  )
26
  # -------------------------------------------------------------------------
27
 
 
333
  input_tensor = torch.tensor(input_ids, dtype=torch.long, device=device).unsqueeze(0)
334
  generated_token_ids = []
335
 
336
+ # --- TEMPERATURE EDITED TO 0.8 for more conversational and expansive language ---
337
+ temperature = 0.8
338
  # ----------------------------------------------------------------------
339
 
340
  eos_id = voc.word2index[voc.EOS]
 
369
  yield word + " "
370
 
371
  # ------------------------
372
+ # Core Chat Handler
373
  # ------------------------
374
  def on_submit(user_message: str, history: Optional[List[List[str]]], train_input_state: Dict[str, str], *_):
375
  """
376
  Token-by-token chat handler.
377
+ Saves the constructed full prompt into the state for training.
378
  """
379
  history = history or []
380
  user_message = re.sub(r'\(Attached:.*?\)|\[IMAGE_PREVIEW_URL:.*?]', '', user_message or "").strip()
 
388
  raw = perform_web_search(query)
389
  search_summary = prepare_web_content(raw)
390
 
391
+ # The prefix now provides the context purely for the model's internal use/integration.
392
  prefix = f"The provided web context is: {search_summary}. " if search_summary else ""
393
  full_prompt = f"{SYSTEM_INSTRUCTION} {prefix}{user_message}"
394
 
 
423
  # Gradio Interface
424
  # ------------------------
425
  with gr.Blocks(title="OkemoLLM") as demo:
426
+ gr.Markdown("# 🌐 OkemoLLM — Streaming DuckDuckGo + Web Context Integrated")
427
  status = gr.Markdown(f"Ready. Current Checkpoint Iteration: **{start_iteration}**")
428
  chat = gr.Chatbot(height=400)
429