from transformers import AutoModelForCausalLM, AutoTokenizer model_id = "karimmashaly/egx-qwen2.5-1.5b-grpo"tokenizer = AutoTokenizer.from_pretrained(model_id)model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="auto", device_map="auto") messages = [ { "role": "system", "content": ( "You are an Egyptian Stock Exchange analyst. Reason from the supplied " "price history and news only. Write in English. Do not invent numbers " "that are not supported by the context. " "Put the reasoning inside <think></think> and the return class inside " "<answer></answer>. The answer must be exactly one of: " "Strong Bullish, Slight Bullish, Neutral, Slight Bearish, Strong Bearish." ), }, { "role": "user", "content": ( "Ticker: COMI (Commercial International Bank)\n" "Analysis date T: 2026-01-15\n\n" "Recent price history (sessions strictly before T):\n...\n\n" "News from T-7 through T:\n...\n\n" "Task: Predict the return class of this stock over the next 5 trading days. " "The allowed labels are: Strong Bullish, Slight Bullish, Neutral, Slight Bearish, Strong Bearish. " "Reply in exactly this form and nothing else: " "<think>your reasoning</think><answer>Label</answer>. " "The answer tag must contain one allowed label and no other text." ), },]prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)inputs = tokenizer(prompt, return_tensors="pt").to(model.device)output = model.generate(**inputs, max_new_tokens=1024)print(tokenizer.decode(output[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))