lynx   »   [go: up one dir, main page]

y:

\n

\\[
(x+y) + (x-y) = 10 + 4 \\;\\Longrightarrow\\; 2x = 14 \\;\\Longrightarrow\\; x = 7.
\\]\"\"\"

\n
result2 = split_response(test_response2)\nprint(\"Test 2:\")\nprint(f\"Analysis: {result2['analysis_content']}\")\nprint(f\"Final: {result2['final_content'][:100]}...\")\nprint()\n\n# Test case 3: No analysis prefix\ntest_response3 = \"\"\"**Black holes** are fascinating cosmic objects where gravity is so strong that nothing can escape.\"\"\"\n\nresult3 = split_response(test_response3)\nprint(\"Test 3:\")\nprint(f\"Analysis: '{result3['analysis_content']}'\")\nprint(f\"Final: {result3['final_content'][:100]}...\")\n
\n

if name == \"main\":
test_splitting()
'''

\n","updatedAt":"2025-09-15T06:42:07.786Z","author":{"_id":"660d1700280a82e38fec3267","avatarUrl":"/avatars/ac98bf11da196578988ededfe94150e4.svg","fullname":"star","name":"ml345","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":1}},"numEdits":1,"identifiedLanguage":{"language":"en","probability":0.5947610139846802},"editors":["ml345"],"editorAvatarUrls":["/avatars/ac98bf11da196578988ededfe94150e4.svg"],"reactions":[],"isReport":false}},{"id":"68c7ede61485115e4b8ff5b1","author":{"_id":"648ede44e6598457da68a33a","avatarUrl":"/avatars/db13899c26a88a1af526ff52b605aeb4.svg","fullname":"Jiahui Li","name":"Carrieischoc","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"isOwner":false,"isOrgMember":false},"createdAt":"2025-09-15T10:43:50.000Z","type":"comment","data":{"edited":false,"hidden":false,"latest":{"raw":"Thank you so much for bringing this method!","html":"

Thank you so much for bringing this method!

\n","updatedAt":"2025-09-15T10:43:50.502Z","author":{"_id":"648ede44e6598457da68a33a","avatarUrl":"/avatars/db13899c26a88a1af526ff52b605aeb4.svg","fullname":"Jiahui Li","name":"Carrieischoc","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false}},"numEdits":0,"identifiedLanguage":{"language":"en","probability":0.908835768699646},"editors":["Carrieischoc"],"editorAvatarUrls":["/avatars/db13899c26a88a1af526ff52b605aeb4.svg"],"reactions":[],"isReport":false}}],"pinned":false,"locked":false,"collection":"discussions","isPullRequest":false,"isReport":false},"repo":{"name":"openai/gpt-oss-120b","type":"model"},"activeTab":"discussion","discussionRole":0,"watched":false,"muted":false,"repoDiscussionsLocked":false}">

assistantfinal, analysis keyword is contained in the huggingface gpt-oss-120 output. Is this intended?

#130
by ml345 - opened
y:

\n

\\[
(x+y) + (x-y) = 10 + 4 \\;\\Longrightarrow\\; 2x = 14 \\;\\Longrightarrow\\; x = 7.
\\]\"\"\"

\n
result2 = split_response(test_response2)\nprint(\"Test 2:\")\nprint(f\"Analysis: {result2['analysis_content']}\")\nprint(f\"Final: {result2['final_content'][:100]}...\")\nprint()\n\n# Test case 3: No analysis prefix\ntest_response3 = \"\"\"**Black holes** are fascinating cosmic objects where gravity is so strong that nothing can escape.\"\"\"\n\nresult3 = split_response(test_response3)\nprint(\"Test 3:\")\nprint(f\"Analysis: '{result3['analysis_content']}'\")\nprint(f\"Final: {result3['final_content'][:100]}...\")\n
\n

if name == \"main\":
test_splitting()
'''

\n","updatedAt":"2025-09-15T06:42:07.786Z","author":{"_id":"660d1700280a82e38fec3267","avatarUrl":"/avatars/ac98bf11da196578988ededfe94150e4.svg","fullname":"star","name":"ml345","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":1}},"numEdits":1,"identifiedLanguage":{"language":"en","probability":0.5947610139846802},"editors":["ml345"],"editorAvatarUrls":["/avatars/ac98bf11da196578988ededfe94150e4.svg"],"reactions":[],"isReport":false}},{"id":"68c7ede61485115e4b8ff5b1","author":{"_id":"648ede44e6598457da68a33a","avatarUrl":"/avatars/db13899c26a88a1af526ff52b605aeb4.svg","fullname":"Jiahui Li","name":"Carrieischoc","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"isOwner":false,"isOrgMember":false},"createdAt":"2025-09-15T10:43:50.000Z","type":"comment","data":{"edited":false,"hidden":false,"latest":{"raw":"Thank you so much for bringing this method!","html":"

Thank you so much for bringing this method!

\n","updatedAt":"2025-09-15T10:43:50.502Z","author":{"_id":"648ede44e6598457da68a33a","avatarUrl":"/avatars/db13899c26a88a1af526ff52b605aeb4.svg","fullname":"Jiahui Li","name":"Carrieischoc","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false}},"numEdits":0,"identifiedLanguage":{"language":"en","probability":0.908835768699646},"editors":["Carrieischoc"],"editorAvatarUrls":["/avatars/db13899c26a88a1af526ff52b605aeb4.svg"],"reactions":[],"isReport":false}}],"pinned":false,"locked":false,"collection":"discussions","isPullRequest":false,"isReport":false},"primaryEmailConfirmed":false,"repo":{"name":"openai/gpt-oss-120b","type":"model"},"discussionRole":0,"acceptLanguages":["*"],"hideComments":true,"repoDiscussionsLocked":false,"isDiscussionAuthor":false}">

from transformers import pipeline
import torch
import os

model_id = "openai/gpt-oss-120b"

Use shared cache directory as per README.md guidelines

cache_dir = os.path.join(os.path.dirname(os.path.abspath(file)), "llm_weights")
os.makedirs(cache_dir, exist_ok=True)

pipe = pipeline(
"text-generation",
model=model_id,
torch_dtype="auto",
device_map={"": 0},
model_kwargs={"cache_dir": cache_dir},
)

messages = [
{"role": "user", "content": "Explain quantum mechanics clearly and concisely."},
]

try:
outputs = pipe(
messages,
max_new_tokens=256,
temperature=0.7,
do_sample=True,
top_p=0.9,
pad_token_id=pipe.tokenizer.eos_token_id,
)
print(outputs[0]["generated_text"])
except Exception as e:
print(f"Generation failed: {e}")
print("Try reducing max_new_tokens or using CPU device")

==============
[{'role': 'user', 'content': 'Explain quantum mechanics clearly and concisely.'}, {'role': 'assistant', 'content': "analysisWe need to explain quantum mechanics clearly and concisely. Provide a brief overview: core principles, wavefunction, superposition, uncertainty, measurement, entanglement, quantization, Schrödinger equation, etc. Use analogies, avoid heavy math but maybe simple equations. Keep concise but thorough. Probably bullet points. Let's produce final answer.assistantfinalQuantum Mechanics in a nutshell\n\n| Core idea | What it means | Everyday analogy |\n|----------|----------------|-------------------|\n| 1. Quantized energy | Particles (electrons, photons, etc.) can only have certain discrete energy values, not a continuous range. | Like a staircase: you can stand on a step (allowed energy) but not in between. |\n| 2. Wave‑particle duality | Every quantum object has both particle‑like and wave‑like aspects. Its state is described by a wavefunction\u202fψ(x,t). | A water wave that also carries a tiny boat—its height tells you the probability of finding the boat. |\n| 3. Superposition | A system can exist in a combination of several possible states simultaneously until measured. | A spinning coin that is both “heads” and “"}]

ml345 changed discussion title from assistantfinal, analysis keyword is contained in the huggingface gpt-oss-120 output. Is this okay? to assistantfinal, analysis keyword is contained in the huggingface gpt-oss-120 output. Is this intended?

Hello. I'm encountering the same issue. have you resolved it yet? Thanks.

Made RE splitting logic with claude meanwhile. I wish the answers were provided separtely.

import re
from typing import Dict

def split_response(response: str) -> Dict[str, str]:
"""Split the response into analysis and final content"""
# Find the analysis part (everything before "assistantfinal")
analysis_match = re.search(r'^(.*?)assistantfinal', response, flags=re.DOTALL)

if analysis_match:
    analysis_content = analysis_match.group(1).strip()
    # Remove "analysis" prefix if present
    analysis_content = re.sub(r'^analysis\s*', '', analysis_content)
    
    # Find the final content (everything after "assistantfinal")
    final_content = re.sub(r'^.*?assistantfinal\s*', '', response, flags=re.DOTALL).strip()
else:
    # If no "assistantfinal" found, check for just "analysis" prefix
    if response.startswith('analysis'):
        analysis_content = response.strip()
        final_content = ""
    else:
        # No clear separation, treat entire response as final content
        analysis_content = ""
        final_content = response.strip()

return {
    "analysis_content": analysis_content,
    "final_content": final_content
}

def test_splitting():
# Test case 1: Response from the actual results
test_response1 = """analysisWe need to explain quantum entanglement. Provide a clear explanation, possibly with analogies, mention key concepts: superposition, nonlocal correlations, Bell's theorem, measurements, etc. Should be accessible.assistantfinalQuantum entanglement is a striking feature of quantum mechanics in which two (or more) particles become linked so that the state of one instantly influences the state of the other, no matter how far apart they are."""

result1 = split_response(test_response1)
print("Test 1:")
print(f"Analysis: {result1['analysis_content'][:100]}...")
print(f"Final: {result1['final_content'][:100]}...")
print()

# Test case 2: Math problem response
test_response2 = """analysisWe need to solve system: x + y = 10, x - y = 4. Solve: add: 2x = 14 => x = 7. Then y = 3. Then x*y = 21. Provide answer.assistantfinalFrom the two equations  

\[
\begin{cases}
x + y = 10 \\
x - y = 4
\end{cases}
\]

add them to eliminate yy:

\[
(x+y) + (x-y) = 10 + 4 \;\Longrightarrow\; 2x = 14 \;\Longrightarrow\; x = 7.
\]"""

result2 = split_response(test_response2)
print("Test 2:")
print(f"Analysis: {result2['analysis_content']}")
print(f"Final: {result2['final_content'][:100]}...")
print()

# Test case 3: No analysis prefix
test_response3 = """**Black holes** are fascinating cosmic objects where gravity is so strong that nothing can escape."""

result3 = split_response(test_response3)
print("Test 3:")
print(f"Analysis: '{result3['analysis_content']}'")
print(f"Final: {result3['final_content'][:100]}...")

if name == "main":
test_splitting()
'''

Thank you so much for bringing this method!

Sign up or log in to comment

Лучший частный хостинг