File size: 1,251 Bytes
740e144
 
4a1492e
 
 
740e144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a1492e
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
license: llama3
language:
- tr
pipeline_tag: text-generation
---

## Usage
```python
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline


model_id = "Trendyol/Trendyol-LLM-8b-chat-v2.0"

pipe = pipeline(
    "text-generation",
    model=model_id,
    model_kwargs={
        "torch_dtype": torch.bfloat16,
        "use_cache":True, 
        "use_flash_attention_2": True
    },
    device_map='auto',
)

terminators = [
    pipe.tokenizer.eos_token_id,
    pipe.tokenizer.convert_tokens_to_ids("<|eot_id|>")
]

sampling_params = dict(do_sample=True, temperature=0.3, top_k=50, top_p=0.9, repetition_penalty=1.1)
DEFAULT_SYSTEM_PROMPT = "Sen yardımsever bir asistansın ve sana verilen talimatlar doğrultusunda en iyi cevabı üretmeye çalışacaksın."

def generate_output(user_query, sys_prompt=DEFAULT_SYSTEM_PROMPT):
    messages = [
        {"role": "system", "content": sys_prompt},
        {"role": "user", "content": user_query}
    ]

    outputs = pipe(
        messages,
        max_new_tokens=1024,
        eos_token_id=terminators,
        return_full_text=False,
        **sampling_params
    )

    return outputs[0]["generated_text"]

response = generate_output("Türkiye'de kaç il var?")
print(response)
```