77import requests
88
99from .types import EvaluationRequest , EvaluationResponse , LLMMessage , SyntaxCheckArgs
10+ from .utils import get_api_key , get_base_url
1011
1112logger = logging .getLogger ("qualifire" )
1213
1314
1415class Client :
1516 def __init__ (
1617 self ,
17- api_key : str ,
18- base_url : str = "https://proxy.qualifire.ai" ,
19- version : str = None ,
18+ api_key : Optional [ str ] ,
19+ base_url : Optional [ str ] = None ,
20+ version : Optional [ str ] = None ,
2021 debug : bool = False ,
2122 ) -> None :
22- self ._base_url = base_url
23- self ._api_key = api_key
23+ self ._base_url = base_url or get_base_url ()
24+ self ._api_key = api_key or get_api_key ()
2425 self ._version = version
2526 self ._debug = debug
2627
@@ -47,8 +48,6 @@ def evaluate(
4748 :param input: The primary input for the evaluation.
4849 :param output: The primary output (e.g., LLM response) to evaluate.
4950 :param assertions: A list of custom assertions to check against the output.
50- :param consistency_check: Check for consistency between
51- input/output and context.
5251 :param dangerous_content_check: Check for dangerous content generation.
5352 :param grounding_check: Check if the output is grounded in the provided
5453 input/context.
@@ -60,8 +59,6 @@ def evaluate(
6059 :param messages: List of message objects representing conversation history.
6160 :param pii_check: Check for personally identifiable information.
6261 :param prompt_injections: Check for attempts at prompt injection.
63- :param responseFunctionCalls: Expected function calls in the response
64- (if applicable).
6562 :param sexual_content_check: Check for sexually explicit content.
6663 :param syntax_checks: Dictionary defining syntax checks (e.g., JSON, SQL).
6764
@@ -80,7 +77,6 @@ def evaluate(
8077 input="Translate 'hello' to French and provide the result in JSON format.",
8178 output='{"translation": "bonjour"}',
8279 assertions=["The output must contain the key 'translation'"],
83- consistency_check=True,
8480 dangerous_content_check=True,
8581 grounding_check=True,
8682 hallucinations_check=True,
@@ -96,7 +92,6 @@ def evaluate(
9692 ],
9793 pii_check=True,
9894 prompt_injections=True,
99- # responseFunctionCalls="some_function_call", # Optional
10095 sexual_content_check=True,
10196 syntax_checks={
10297 "json": SyntaxCheckArgs(args="strict") # Example syntax check
@@ -135,16 +130,15 @@ def evaluate(
135130 if response .status_code != 200 :
136131 raise Exception (f"Qualifire API error: { response .text } " )
137132
138- jsonResponse = response .json ()
139- return EvaluationResponse (** jsonResponse )
133+ json_response = response .json ()
134+ return EvaluationResponse (** json_response )
140135
141136 def invoke_evaluation (
142137 self ,
143138 input : str ,
144139 output : str ,
145140 evaluation_id : str ,
146- ):
147-
141+ ) -> EvaluationResponse :
148142 url = f"{ self ._base_url } /api/evaluation/invoke/"
149143
150144 payload = {
@@ -163,5 +157,5 @@ def invoke_evaluation(
163157 response .raise_for_status ()
164158 raise Exception (f"Qualifire API error: { response .text } " )
165159
166- jsonResponse = response .json ()
167- return EvaluationResponse (** jsonResponse )
160+ json_response = response .json ()
161+ return EvaluationResponse (** json_response )
0 commit comments