Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 20 |
SYSTEM_INSTRUCTION = (
|
| 21 |
-
"You are Okemo Language Model (OLM), a
|
| 22 |
-
"
|
| 23 |
-
"
|
|
|
|
| 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
|
| 336 |
-
temperature = 0.
|
| 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
|
| 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 |
-
|
| 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
|
| 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
|
| 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 |
|