guardrails-ai / guardrails

Adding guardrails to large language models.
https://www.guardrailsai.com/docs
Apache License 2.0
4.07k stars 310 forks source link

[docs] request: Add doc examples of how to call the new Guardrail Server endpoints. #977

Open JuanmaMenendez opened 3 months ago

JuanmaMenendez commented 3 months ago

Description There is no documentation or example to see how we can do API calls to the new Guardrails Server.

I know in http://127.0.0.1:8000/docs there are some info, but I am referring to clear code examples, and some clarification, for example do we need some special Auth token? how to get it? etc...

For example, how can we call to a Validate endpoint to run a Guard validation on a fix text, or during streaming?

I am not referring to the interface like: client = OpenAI( base_url='http://localhost:8000/guards/sensitive_topics/openai/v1', )

But directly to the endpoints.

CalebCourier commented 3 months ago

@JuanmaMenendez thanks for the inquiry!

Our recommended method of interacting with the Guardrails Server is through a client library using either the OpenAI proxy pattern like you've referenced, or with the guardrails-ai open source package as shown here: https://www.guardrailsai.com/docs/getting_started/guardrails_server#advanced-client-usage and here: https://www.guardrailsai.com/docs/concepts/deploying#a-quick-demonstration-of-using-the-guardrails-api-as-a-dev-server

We recommend interacting with the server in this way because it provides a unified interface for all of the different use cases you mention. For example, with the Guardrails AI library, the two use cases you mentioned are the same regardless of if you're using the Guardrails Server or running validation client-side:

how can we call to a Validate endpoint to run a Guard validation on a fix text

guard = Guard(name="my-guard")
guard.validate("fixed text")

or during streaming

guard = Guard(name="my-guard")
guard(model="gpt-3.5-turbo", stream=True)

This is why we do not have documentation specific to performing these operations with the Guardrails Server; i.e. the interaction with the client library is the same, the only difference is running the server and changing a few settings as shown in the docs I referenced above.

If you're intention is to interact directly with the endpoints via something like curl, that is the purpose of the Swagger documentation located at http://localhost:8000/doc. It should contain everything you need to know in order to interact with the API in a RESTful manner including schema definitions and example payloads.

If you're looking for something in between, we also publish the guardrails-api-client which is what we use within guardrails-ai to interact with the server.

I hope this addresses your concerns. If not, we're always open to hearing more about your use case to see where we can help.