# core


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

<details open class="code-fold">
<summary>Exported source</summary>

``` python
import os
from fastcore.all import *

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

</details>

# Primitives

Jev has 3 Primitives: `Choice`, `Score` and
[`Noul`](https://CarloLepelaars.github.io/jevey/core.html#noul). All
these objects have a name and instructions.

------------------------------------------------------------------------

<a
href="https://github.com/CarloLepelaars/jevey/blob/main/jevey/core.py#L17"
target="_blank" style="float:right; font-size:smaller">source</a>

### Prim

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

*Base class for Noul, Choice and Score*

<details open class="code-fold">
<summary>Exported source</summary>

``` python
class Prim(AttrDict):
    """Base class for Noul, Choice and Score"""
    def __init__(self, type: str, name: str, instructions: str):
        store_attr()
```

</details>

``` python
prim = Prim(type="base", name="test", instructions="Some instructions")
prim
```

``` python
{'instructions': 'Some instructions', 'name': 'test', 'type': 'base'}
```

------------------------------------------------------------------------

<a
href="https://github.com/CarloLepelaars/jevey/blob/main/jevey/core.py#L23"
target="_blank" style="float:right; font-size:smaller">source</a>

### Noul

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

*Bool decision value*

<details open class="code-fold">
<summary>Exported source</summary>

``` python
class Noul(Prim):
    """Bool decision value"""
    def __init__(self, name: str, instructions: dict):
        super().__init__(type="noul", name=name, instructions=instructions)
```

</details>

``` python
n = Noul("is_bug", "Is the customer reporting a software defect?")
n
```

``` python
{ 'instructions': 'Is the customer reporting a software defect?',
  'name': 'is_bug',
  'type': 'noul'}
```

# Client

For the
[`Client`](https://CarloLepelaars.github.io/jevey/core.html#client) make
sure to set up `JEV_API_KEY` as an env variable.

------------------------------------------------------------------------

<a
href="https://github.com/CarloLepelaars/jevey/blob/main/jevey/core.py#L43"
target="_blank" style="float:right; font-size:smaller">source</a>

### Client

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

*Client for the Jev API*

<details open class="code-fold">
<summary>Exported source</summary>

``` python
import json
from fastspec.spec import SpecParser
from fastspec.oapi import OpenAPIClient
```

</details>

<details open class="code-fold">
<summary>Exported source</summary>

``` python
spec_obj = dict2obj(json.loads(urlread(f"{TYPESAFE_API_URL}openapi.json")))
spec_obj.servers = [{"url": TYPESAFE_API_URL}]
spec_obj.servers
```

</details>

    [{'url': 'https://api.typesafe.ai/'}]

<details open class="code-fold">
<summary>Exported source</summary>

``` python
JEV_SPEC = SpecParser.from_openapi(spec_obj)
JEV_SPEC
```

</details>

    SpecParser(base_url='https://api.typesafe.ai/', ops=2)

<details open class="code-fold">
<summary>Exported source</summary>

``` python
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()
```

</details>

``` python
c = Client()
c
```

    Client(model='jev-latest', c=<fastspec.oapi.OpenAPIClient object>, questions={})

------------------------------------------------------------------------

<a
href="https://github.com/CarloLepelaars/jevey/blob/main/jevey/core.py#L55"
target="_blank" style="float:right; font-size:smaller">source</a>

### Client.\_\_iadd\_\_

``` python
def __iadd__(
    q:__main__.Prim
):
```

<details open class="code-fold">
<summary>Exported source</summary>

``` python
@patch
def __iadd__(self:Client, q:Prim): 
    self.questions[q.name] = {k: v for k, v in q.items() if k != "name"}
    return self
```

</details>

``` python
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?'}})

------------------------------------------------------------------------

<a
href="https://github.com/CarloLepelaars/jevey/blob/main/jevey/core.py#L61"
target="_blank" style="float:right; font-size:smaller">source</a>

### Client.\_\_call\_\_

``` python
def __call__(
    state:str
):
```

*Call self as a function.*

<details open class="code-fold">
<summary>Exported source</summary>

``` python
@patch
def __call__(self:Client, state:str):
        return self.c.func_dict["/v1/systemone:POST"](
            model=self.model, state=state, questions=self.questions,
        )
```

</details>

``` python
res = await c("This is working perfectly")
res
```

``` python
{ 'answers': {'is_bug': {'noul': 0.03, 'type': 'noul'}},
  'model': 'jev-1.13.0',
  'usage': {'input_tokens': 278, 'output_tokens': 21}}
```

------------------------------------------------------------------------

<a
href="https://github.com/CarloLepelaars/jevey/blob/main/jevey/core.py#L67"
target="_blank" style="float:right; font-size:smaller">source</a>

### Decision

``` python
def Decision(
    *args, **kwargs
):
```

<details open class="code-fold">
<summary>Exported source</summary>

``` python
class Decision:
    pass
```

</details>
