core

Basic jevey objects
Exported source
import os
from fastcore.all import *

TYPESAFE_API_URL = "https://api.typesafe.ai/"

Primitives

Jev has 3 Primitives: Choice, Score and Noul. All these objects have a name and instructions.


source

Prim

def Prim(
    type:str, name:str, instructions:str
):

Base class for Noul, Choice and Score

Exported source
class Prim(AttrDict):
    """Base class for Noul, Choice and Score"""
    def __init__(self, type: str, name: str, instructions: str):
        store_attr()
prim = Prim(type="base", name="test", instructions="Some instructions")
prim
{'instructions': 'Some instructions', 'name': 'test', 'type': 'base'}

source

Noul

def Noul(
    name:str, instructions:dict
):

Bool decision value

Exported source
class Noul(Prim):
    """Bool decision value"""
    def __init__(self, name: str, instructions: dict):
        super().__init__(type="noul", name=name, instructions=instructions)
n = Noul("is_bug", "Is the customer reporting a software defect?")
n
{ 'instructions': 'Is the customer reporting a software defect?',
  'name': 'is_bug',
  'type': 'noul'}

Client

For the Client make sure to set up JEV_API_KEY as an env variable.


source

Client

def Client(
    model:str='jev-latest'
):

Client for the Jev API

Exported source
import json
from fastspec.spec import SpecParser
from fastspec.oapi import OpenAPIClient
Exported source
spec_obj = dict2obj(json.loads(urlread(f"{TYPESAFE_API_URL}openapi.json")))
spec_obj.servers = [{"url": TYPESAFE_API_URL}]
spec_obj.servers
[{'url': 'https://api.typesafe.ai/'}]
Exported source
JEV_SPEC = SpecParser.from_openapi(spec_obj)
JEV_SPEC
SpecParser(base_url='https://api.typesafe.ai/', ops=2)
Exported source
class Client(BasicRepr):
    """Client for the Jev API"""
    HEADERS = {"Authorization": f"Bearer {os.environ['JEV_API_KEY']}",
    "Content-Type": "application/json"}
    def __init__(self, model="jev-latest"):
        store_attr()
        self.c = OpenAPIClient(JEV_SPEC, headers=self.HEADERS)
        self.questions = dict()
c = Client()
c
Client(model='jev-latest', c=<fastspec.oapi.OpenAPIClient object>, questions={})

source

Client.__iadd__

def __iadd__(
    q:__main__.Prim
):
Exported source
@patch
def __iadd__(self:Client, q:Prim): 
    self.questions[q.name] = {k: v for k, v in q.items() if k != "name"}
    return self
c += n
c
Client(model='jev-latest', c=<fastspec.oapi.OpenAPIClient object>, questions={'is_bug': {'type': 'noul', 'instructions': 'Is the customer reporting a software defect?'}})

source

Client.__call__

def __call__(
    state:str
):

Call self as a function.

Exported source
@patch
def __call__(self:Client, state:str):
        return self.c.func_dict["/v1/systemone:POST"](
            model=self.model, state=state, questions=self.questions,
        )
res = await c("This is working perfectly")
res
{ 'answers': {'is_bug': {'noul': 0.03, 'type': 'noul'}},
  'model': 'jev-1.13.0',
  'usage': {'input_tokens': 278, 'output_tokens': 21}}

source

Decision

def Decision(
    *args, **kwargs
):
Exported source
class Decision:
    pass