Spaces:
Running
Running
File size: 638 Bytes
40db491 7a54719 40db491 |
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 |
#pip install huggingface_hub
#export HF_TOKEN="<>"
from huggingface_hub import InferenceClient
import json
repo_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
llm_client = InferenceClient(
model=repo_id,
timeout=120,
)
def call_llm(inference_client: InferenceClient, prompt: str):
response = inference_client.post(
json={
"inputs": prompt,
"parameters": {"max_new_tokens": 200},
"task": "text-generation",
},
)
return json.loads(response.decode())[0]["generated_text"]
response=call_llm(llm_client, "write me a crazy joke")
print (response) |