File size: 862 Bytes
299633b
 
 
 
 
 
 
 
 
5a77d9b
 
 
 
 
 
 
 
299633b
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Load the model (TinyLlama)
model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

def get_llm_reply(user_input: str) -> str:
    prompt = f"""
You are 'FreightBot', an AI freight agent that helps with truckload bookings, price estimates, and delivery updates.

Respond in a short, professional style like a real broker. Always sound confident.

User: {user_input}
FreightBot:
"""
    inputs = tokenizer(prompt, return_tensors="pt")
    output = model.generate(
        **inputs,
        max_new_tokens=100,
        do_sample=True,
        temperature=0.7
    )
    response = tokenizer.decode(output[0], skip_special_tokens=True)
    return response.replace(prompt, "").strip()