Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: pandyamarut <[email protected]>
  • Loading branch information
pandyamarut committed Sep 27, 2024
1 parent 1d3a76c commit d609499
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import runpod
from typing import List, AsyncGenerator
from typing import List, AsyncGenerator, Dict, Union
from tensorrt_llm import LLM, SamplingParams
from huggingface_hub import login
from tensorrt_llm.hlapi import BuildConfig, KvCacheConfig
Expand Down Expand Up @@ -47,22 +47,7 @@ async def generate_async(self, prompts: List[str], max_tokens: int = 100) -> Asy
worker = TRTLLMWorker(model_path)



# def handler(job):
# """Handler function that will be used to process jobs."""
# job_input = job['input']
# prompts = job_input.get('prompts', ["Hello, how are you?"])
# max_tokens = job_input.get('max_tokens', 100)
# streaming = job_input.get('streaming', False)

# try:
# results = worker.generate(prompts, max_tokens)
# return {"status": "success", "output": results}
# except Exception as e:
# return {"status": "error", "message": str(e)}


async def handler(job):
async def handler(job: Dict) -> AsyncGenerator[Dict[str, Union[str, List[str]]], None]:
"""Handler function that will be used to process jobs."""
job_input = job['input']
prompts = job_input.get('prompts', ["Hello, how are you?"])
Expand All @@ -78,8 +63,8 @@ async def handler(job):
yield {"status": "success", "output": results}
else:
results = worker.generate(prompts, max_tokens)
return {"status": "success", "output": results}
yield {"status": "success", "output": results}
except Exception as e:
return {"status": "error", "message": str(e)}
yield {"status": "error", "message": str(e)}

runpod.serverless.start({"handler": handler, "return_aggregate_stream": True})

0 comments on commit d609499

Please sign in to comment.