Views
No views yet
1from datetime import datetime, timedelta
2import torch
3
4from mistral_common.protocol.instruct.request import ChatCompletionRequest
5from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
6from huggingface_hub import hf_hub_download
7from transformers import Mistral3ForConditionalGeneration
8
9
10def load_system_prompt(repo_id: str, filename: str) -> str:
11 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
12 with open(file_path, "r") as file:
13 system_prompt = file.read()
14 today = datetime.today().strftime("%Y-%m-%d")
15 yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
16 model_name = repo_id.split("/")[-1]
17 return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
18
19
20model_id = "huihui-ai/Huihui-Mistral-Small-3.2-24B-Instruct-2506-abliterated"
21SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
22
23tokenizer = MistralTokenizer.from_hf_hub(model_id)
24
25model = Mistral3ForConditionalGeneration.from_pretrained(
26 model_id, torch_dtype=torch.bfloat16
27)
28
29image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438"
30
31messages = [
32 {"role": "system", "content": SYSTEM_PROMPT},
33 {
34 "role": "user",
35 "content": [
36 {
37 "type": "text",
38 "text": "What action do you think I should take in this situation? List all the possible actions and explain why you think they are good or bad.",
39 },
40 {"type": "image_url", "image_url": {"url": image_url}},
41 ],
42 },
43]
44
45tokenized = tokenizer.encode_chat_completion(ChatCompletionRequest(messages=messages))
46
47input_ids = torch.tensor([tokenized.tokens])
48attention_mask = torch.ones_like(input_ids)
49pixel_values = torch.tensor(tokenized.images[0], dtype=torch.bfloat16).unsqueeze(0)
50image_sizes = torch.tensor([pixel_values.shape[-2:]])
51
52output = model.generate(
53 input_ids=input_ids,
54 attention_mask=attention_mask,
55 pixel_values=pixel_values,
56 image_sizes=image_sizes,
57 max_new_tokens=1000,
58)[0]
59
60decoded_output = tokenizer.decode(output[len(tokenized.tokens) :])
61print(decoded_output)
62# In this situation, you are playing a Pokémon game where your Pikachu (Level 42) is facing a wild Pidgey (Level 17). Here are the possible actions you can take and an analysis of each:
63
64# 1. **FIGHT**:
65# - **Pros**: Pikachu is significantly higher level than the wild Pidgey, which suggests that it should be able to defeat Pidgey easily. This could be a good opportunity to gain experience points and possibly items or money.
66# - **Cons**: There is always a small risk of Pikachu fainting, especially if Pidgey has a powerful move or a status effect that could hinder Pikachu. However, given the large level difference, this risk is minimal.
67
68# 2. **BAG**:
69# - **Pros**: You might have items in your bag that could help in this battle, such as Potions, Poké Balls, or Berries. Using an item could help you capture Pidgey or heal Pikachu if needed.
70# - **Cons**: Using items might not be necessary given the level difference. It could be more efficient to just fight and defeat Pidgey quickly.
71
72# 3. **POKÉMON**:
73# - **Pros**: You might have another Pokémon in your party that is better suited for this battle or that you want to gain experience. Switching Pokémon could also be strategic if you want to train a lower-level Pokémon.
74# - **Cons**: Switching Pokémon might not be necessary since Pikachu is at a significant advantage. It could also waste time and potentially give Pidgey a turn to attack.
75
76# 4. **RUN**:
77# - **Pros**: Running away could be a quick way to avoid the battle altogether. This might be useful if you are trying to conserve resources or if you are in a hurry to get to another location.
78# - **Cons**: Running away means you miss out on the experience points, items, or money that you could gain from defeating Pidgey. It also might not be the most efficient use of your time if you are trying to train your Pokémon.
79
80# ### Recommendation:
81# Given the significant level advantage, the best action to take is likely **FIGHT**. This will allow you to quickly defeat Pidgey and gain experience points for Pikachu. If you are concerned about Pikachu's health, you could use the **BAG** to heal Pikachu before or during the battle. Running away or switching Pokémon does not seem necessary in this situation. bc1qqnkhuchxw0zqjh2ku3lu4hq45hc6gy84uk70ge