guardrails icon indicating copy to clipboard operation
guardrails copied to clipboard

How to use model without api with guard

Open MuhammadHammadBashir opened this issue 1 year ago • 3 comments

I have models locally downloaded and using from ctransformers import AutoModelForCausalLM from ctransformers import AutoModelForCausalLM, AutoConfig, Config conf = AutoConfig(Config(temperature=0.8, repetition_penalty=1.1, batch_size=52, max_new_tokens=1024, context_length=2048)) llm = AutoModelForCausalLM.from_pretrained("/content/llama-2-13b-chat.Q4_K_S.gguf", model_type="llama", config = conf)

with api we can use like this res = guard( openai.chat.completions.create, prompt_params={"doctors_notes": doctors_notes}, max_tokens=1024, temperature=0.3, )

but how to use above model in this context

MuhammadHammadBashir avatar Jan 22 '24 17:01 MuhammadHammadBashir

Hey Muhammad,

In that case, you would wrap the model invocation in a custom callable, following the docs here.

In this case it could be as simple as

def custom_llm_callable(prompt):
  return llm( #pass prompt to the llm here

res = guard(
  custom_llm_callable,
  prompt_params={"doctors_notes": doctors_notes},
  max_tokens=1024,
  temperature=0.3,
)

zsimjee avatar Jan 22 '24 18:01 zsimjee

@MuhammadHammadBashir we also recently added support for HuggingFace models. So if you are using one of those from the transformers library you can treat model.generate like an llm api.

We still need to add better docs for this functionality, but you can find a summary and example here: https://www.guardrailsai.com/blog/0.3-release/#anthropic-and-hugging-face-models-support

CalebCourier avatar Jan 26 '24 14:01 CalebCourier

thank you for info.

On Fri, Jan 26, 2024 at 7:50 PM Caleb Courier @.***> wrote:

@MuhammadHammadBashir https://github.com/MuhammadHammadBashir we also recently added support for HuggingFace models. So if you are using one of those from the transformers library you can treat model.generate like an llm api.

We still need to add better docs for this functionality, but you can find a summary and example here:

https://www.guardrailsai.com/blog/0.3-release/#anthropic-and-hugging-face-models-support

— Reply to this email directly, view it on GitHub https://github.com/guardrails-ai/guardrails/issues/551#issuecomment-1912189183, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKJTVY6G5WUQFBRFQGGPSLTYQO7FHAVCNFSM6AAAAABCFTDTFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJSGE4DSMJYGM . You are receiving this because you were mentioned.Message ID: @.***>

MuhammadHammadBashir avatar Jan 27 '24 09:01 MuhammadHammadBashir

Hi @MuhammadHammadBashir as there's been no updates on this thread in a few months. If you have any questions or issues still please don't hesitate to reopen this or reach out to me.

dtam avatar Jul 22 '24 16:07 dtam