AIAnytime / AIAnytime/Guardrails-Implementation-in-LLMs

Getting Error "Validate Response as None

Abierto
#1 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
10
Forks
8
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Getting Validate Response as "None". Refer the screen shot . Please Help

Screenshot 2023-12-09 at 11 35 49 AM

import guardrails as gd
from rich import print
import openai
import streamlit as st
from dotenv import load_dotenv
import os

load_dotenv()

openai.api_key = os.getenv("OPENAI_API_KEY")

def without_guardrails(text):
response = openai.Completion.create(
prompt="Translate the texts to English language\n"+text,
engine="text-davinci-003",
max_tokens=2048,
temperature=0)

result = response['choices'][0]['text']
return result

rail_str = """

from guardrails.validators import Validator, EventDetail, register_validator
from typing import Dict, List
from profanity_check import predict
import openai

@register_validator(name="is-profanity-free", data_type="string")

class IsProfanityFree(Validator):
global predict
global EventDetail
def validate(self, key, value, schema) -> Dict:
text = value
prediction = predict([value])
if prediction[0] == 1:
raise EventDetail(
key,
value,
schema,
f"Value {value} contains profanity language",
"Sorry, It contains profanity language. I can't return the result.",
)
return schema

Translate the given statement into english language:

{{statement_to_be_translated}}

@complete_json_suffix

"""

guard = gd.Guard.from_rail_string(rail_str)

def main():

st.title("Guardrails Implementation in LLMs")

text_area = st.text_area("Enter the text to be translated")

if st.button("Translate"):
if len(text_area)>0:
st.info(text_area)

st.warning("Translation Without Guardrails")

without_guardrails_result = without_guardrails(text_area)
st.success(without_guardrails_result)

st.warning("Translation With Guardrails")

raw_llm_response, validated_response = guard(
openai.Completion.create,
prompt_params={"statement_to_be_translated": text_area},
engine="text-davinci-003",
max_tokens=2048,
temperature=0)

st.success(f"Validated Output: {validated_response}")

if __name__ == "__main__":
main()

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.