Giter VIP home page Giter VIP logo

financial-tone's Introduction

Overview

Developed by Cartesia AI
Date of development Feb 14, 2024
Validator type Format
Blog -
License Apache 2
Input/Output Output

Description

This validator checks an LLM-generated output (in a financial context) for a particular tone.

Requirements

  • Dependencies: transformers, torch

Installation

guardrails hub install hub://cartesia/financial_tone

Usage Examples

Validating string output via Python

In this example, we use the financial_tone validator on any LLM generated text.

# Import Guard and Validator
from guardrails.hub import FinancialTone
from guardrails import Guard

# Use the Guard with the validator
guard = Guard().use(FinancialTone, on_fail="exception")

# Test passing response
guard.validate(
    "Growth is strong and we have plenty of liquidity.",
    metadata={"financial_tone": "positive"}
)

try:
    # Test failing response
    guard.validate(
        "There are doubts about our finances, and we are struggling to stay afloat.",
        metadata={"financial_tone": "positive"}
    )
except Exception as e:
    print(e)

API Reference

__init__(self, on_fail="noop")

    Initializes a new instance of the Validator class.

    Parameters:

    • on_fail (str, Callable): The policy to enact when a validator fails. If str, must be one of reask, fix, filter, refrain, noop, exception or fix_reask. Otherwise, must be a function that is called when the validator fails.

__call__(self, value, metadata={}) โ†’ ValidationResult

    Validates the given value using the rules defined in this validator, relying on the metadata provided to customize the validation process. This method is automatically invoked by guard.parse(...), ensuring the validation logic is applied to the input data.

    Note:

    1. This method should not be called directly by the user. Instead, invoke guard.parse(...) where this method will be called internally for each associated Validator.
    2. When invoking guard.parse(...), ensure to pass the appropriate metadata dictionary that includes keys and values required by this validator. If guard is associated with multiple validators, combine all necessary metadata into a single dictionary.

    Parameters:

    • value (Any): The input value to validate.
    • metadata (dict): A dictionary containing metadata required for validation.
    Key Type Description Default Required
    financial_tone string One of positive, negative, neutral neutral No
    financial_tone_threshold float A float value between 0 and 1 0.8 No

financial-tone's People

Contributors

thekaranacharya avatar calebcourier avatar zsimjee avatar krandiash avatar smohiuddin avatar

Watchers

 avatar

financial-tone's Issues

Running error while installing

`(env) ubuntu@ip-xxxx~/guardrails$ guardrails hub install hub://cartesia/financial_tone
2024-03-31 20:11:54 ip-xxxxxx guardrails-cli[7820] NOTICE Installing hub://cartesia/financial_tone...
  Running command git clone --filter=blob:none --quiet ...
.....
INFO Collecting git+https://github.com/krandiash/financial-tone.git
  Cloning https://github.com/krandiash/financial-tone.git to /tmp/pip-req-build-toevdg8f
  Resolved https://github.com/krandiash/financial-tone.git to commit 26b71c897f13900e2bc1d7ccaa89d086a31050db
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: financial_tone
  Building wheel for financial_tone (pyproject.toml): started
  Building wheel for financial_tone (pyproject.toml): finished with status 'done'
  Created wheel for financial_tone: filename=financial_tone-0.0.0-py3-none-any.whl size=12524 sha256=05f854822a0b02e908539d617177039d3512e624ddd72ed6a07bcef2db5fd9b8
  Stored in directory: /tmp/pip-ephem-wheel-cache-wcldyd4e/wheels/0f/b4/d8/4672f892796b72d674501d53d506140583150705a6ac7acccd
Successfully built financial_tone
Installing collected packages: financial_tone
Successfully installed financial_tone-0.0.0

ERROR: unknown command "inspect"
2024-03-31 20:12:01 ip-172-31-86-75 guardrails-cli[7820] ERROR Failed to inspect `

What could be going wrong here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.