44from transformers import AutoModelForCausalLM , AutoTokenizer , BitsAndBytesConfig
55import time
66from typing import List
7+ import httpx
78
89# 모델 로딩 및 4bit 양자화 설정
910model_id = "sunnyanna/KULLM3-AWQ"
@@ -43,5 +44,24 @@ def kullm_batch_generate(prompts: List[str], max_new_tokens=512):
4344 decoded_results .append (result_text .split ('[/INST]' )[- 1 ].strip ())
4445 return decoded_results
4546
46- def generate_content (prompt : str , max_new_tokens = 512 ) -> str :
47- return kullm_batch_generate ([prompt ], max_new_tokens = max_new_tokens )[0 ]
47+ VLLM_API_URL = "http://localhost:8000/v1/completions"
48+
49+ async def vllm_generate_content (prompt : str , max_tokens : int = 512 ) -> str :
50+ headers = {"Content-Type" : "application/json" }
51+ payload = {
52+ "model" : "sunnyanna/KULLM3-AWQ" ,
53+ "prompt" : prompt ,
54+ "max_tokens" : max_tokens ,
55+ "temperature" : 0.2 ,
56+ "top_p" : 0.2 ,
57+ "stop" : None
58+ }
59+ async with httpx .AsyncClient () as client :
60+ response = await client .post (VLLM_API_URL , headers = headers , json = payload )
61+ response .raise_for_status ()
62+ result = response .json ()
63+ return result ["choices" ][0 ]["text" ].strip ()
64+
65+ # 기존 generate_content 함수 대체
66+ async def generate_content (prompt : str , max_new_tokens = 512 ) -> str :
67+ return await vllm_generate_content (prompt , max_tokens = max_new_tokens )
0 commit comments