Views
No views yet
PortalSolrSearchTool calls. Handles both technical queries (generates tool calls) and conversational input (responds naturally).Input: "How do I configure static IP in RHEL 9?"
Output: <tool_call>[{"name": "PortalSolrSearchTool", "arguments": {"user_query": "configure static IP in RHEL 9"}}]1pip install unsloth
2# Or for faster installation:
3pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"1from unsloth import FastLanguageModel
2from transformers import TextStreamer
3
4# Load model
5model, tokenizer = FastLanguageModel.from_pretrained(
6 "jbarguti/granite-4-h-micro-tool-call-finetune-redhat",
7 max_seq_length=2048,
8 load_in_4bit=True,
9)
10
11FastLanguageModel.for_inference(model)
12
13# Helper function
14def ask_question(query):
15 """Ask a question and get tool call or conversational response"""
16 print(f"\n{'='*80}")
17 print(f"Query: {query}")
18 print(f"{'='*80}")
19 print("Response:")
20
21 messages = [{"role": "user", "content": query}]
22 inputs = tokenizer.apply_chat_template(
23 messages,
24 tokenize=True,
25 add_generation_prompt=True,
26 return_tensors="pt"
27 ).to("cuda")
28
29 text_streamer = TextStreamer(tokenizer, skip_prompt=True)
30 _ = model.generate(
31 inputs,
32 max_new_tokens=128,
33 temperature=0.3,
34 top_p=0.95,
35 top_k=50,
36 streamer=text_streamer
37 )
38 print(f"{'='*80}\n")
39
40# Try some examples
41ask_question("How do I configure static IP in RHEL 9?")
42ask_question("Hello!")
43ask_question("What are the prerequisites for OpenShift 4.15?")
44
45# Interactive mode
46print("Interactive Mode - Type 'quit' to exit")
47while True:
48 query = input("\nYour question: ").strip()
49 if query.lower() in ['quit', 'exit', 'q']:
50 break
51 if query:
52 ask_question(query)1temperature = 0.3 # Low for consistent tool call formatting
2max_new_tokens = 128
3top_p = 0.95
4top_k = 501# Technical query
2Input: "What are the prerequisites for OpenShift 4.15?"
3Output: <tool_call>[{"name": "PortalSolrSearchTool", "arguments": {"user_query": "prerequisites for OpenShift 4.15"}}]
4
5# Greeting
6Input: "Hello!"
7Output: Hello! I'm Red Hat's Ask Red Hat assistant. How can I help you with Red Hat products and services today?
8
9# Error troubleshooting
10Input: "ERROR rhsm cannot connect to Red Hat Subscription Management"
11Output: <tool_call>[{"name": "PortalSolrSearchTool", "arguments": {"user_query": "ERROR rhsm cannot connect to Red Hat Subscription Management"}}]