ariG23498 HF Staff commited on
Commit
262ce4c
·
verified ·
1 Parent(s): ba0b22a

Upload HuggingFaceTB_SmolLM3-3B_6.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. HuggingFaceTB_SmolLM3-3B_6.py +48 -0
HuggingFaceTB_SmolLM3-3B_6.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "transformers",
5
+ # "torch",
6
+ # ]
7
+ # ///
8
+
9
+ try:
10
+ tools = [
11
+ {
12
+ "name": "get_weather",
13
+ "description": "Get the weather in a city",
14
+ "parameters": {"type": "object", "properties": {"city": {"type": "string", "description": "The city to get the weather for"}}}}
15
+ ]
16
+
17
+ messages = [
18
+ {
19
+ "role": "user",
20
+ "content": "Hello! How is the weather today in Copenhagen?"
21
+ }
22
+ ]
23
+
24
+ inputs = tokenizer.apply_chat_template(
25
+ messages,
26
+ enable_thinking=False, # True works as well, your choice!
27
+ xml_tools=tools,
28
+ add_generation_prompt=True,
29
+ tokenize=True,
30
+ return_tensors="pt"
31
+ ).to(model.device)
32
+
33
+ outputs = model.generate(inputs)
34
+ print(tokenizer.decode(outputs[0]))
35
+ with open('HuggingFaceTB_SmolLM3-3B_6.txt', 'w') as f:
36
+ f.write('Everything was good in HuggingFaceTB_SmolLM3-3B_6.txt')
37
+ except Exception as e:
38
+ with open('HuggingFaceTB_SmolLM3-3B_6.txt', 'w') as f:
39
+ import traceback
40
+ traceback.print_exc(file=f)
41
+ finally:
42
+ from huggingface_hub import upload_file
43
+ upload_file(
44
+ path_or_fileobj='HuggingFaceTB_SmolLM3-3B_6.txt',
45
+ repo_id='model-metadata/custom_code_execution_files',
46
+ path_in_repo='HuggingFaceTB_SmolLM3-3B_6.txt',
47
+ repo_type='dataset',
48
+ )