semvec/pypi-packages huggingface dataset:
pyai21 0.0.5
An interpreter for imaginary Python code + wrapper for the AI21 API
Requires Python: >=3.6

This is a simple async Python wrapper for AI21's API. It also comes with a convenient decorator function (@interpret) that sends the returned result of a function to that API, with the provided keyword args.

Example of @interpret in action:

```python
@interpret(stops=['"""'])
async def answer_anything(question: str) -> str:
    return f"""
    from instant_answers import SemanticQuery
    querier = SemanticQuery(minimum_length=250, rank_by='upvotes', moderator_curated=True)
    question = "{question}"
    querier.get_answer(question)
    # You should get this thorough answer:
    # \"\"\""""

await answer_anything(question="Why did the French Revolution occur?")

    # "Revolutions can fundamentally transform the political, social, and economic structures of a..."

@interpret(stops=["']", "]"], count=10)
async def name_generator(kwargs: str) -> str:
    return f"""
    from names import generate_names
    generate_names(nationality="Korean", script="Latin", surname=True, seed=2031, count=1, quality="high")
    # Should return: ['Byung Soo Kim']
    # generate_names({kwargs}, seed=2031)
    # Should return: ['"""

await name_generator(kwargs='nationality="Singaporean", script="Latin", rareness="common"') 

    # "['Joh Jae Lin', 'James Yi Jin Hao', ..."
```

Generally fictional Python code works much better than natural language, in addition to being more concise.

# Usage

```bash
pip install pyai21
```

You'll need to have a .env file in your current working directory with the following variables:
```
AI21_API_KEY_FILE=your_api_key_file.txt # this should be a newline separated list of keys
POOL_KEY=skjhjfkhsk # optional: ignore this if you're not on the Personate discord server
```
Based on which of these are specified, it will return different functions. You can override this by importing get_ai21 or get_pool directly. The end results should be the same, however.

## get

```python
result = await get(
    prompt="Here are my top ten favourite things about Python: 1.", 
    stops=["10"],
    max=100,
    temp=0.85,
    top_p=1.0,
    size="j1-large",
    count=2,
    presence_penalty=0.2,
    count_penalty=0.2,
    frequency_penalty=20.0,
    banned_tokens=["type", "safety"],
    logit_biases={"shared": -10, "mutable": -0.5, "references": -50},
    key=None
)

# You can optionally specify a particular key if you're using ai21.
```

## emit

This shows you the top 64 most likely tokens that might follow after your prompt.

```python
result = await emit(prompt="Death is just the next", size="j1-jumbo")
#{ "token": "\u2581adventure", "logprob": -6.043289661407471 },
```

## match

```python
options = ["custard", "chocolate sauce", "eggnog", "sprinkles"]
top = await match(prompt="The best desert topping is", top=1, available_options=options, size="j1-jumbo")
```
asynchronise 0.0.2
Event dispatch + async generators
Requires Python: >=3.7

Asynchronise lets you turn your functions into fully coordinated, event-driven async generators that yield their results mid-step, allowing other functions (both synchronous and asynchronous, generators or non-generators) to use them immediately.

It's ideal if you need a small, tidy, async and sync-compatible framework for managing events with runtime type-checking. Or if you really love decorators.

## Installing

```bash
pip install asynchronise
```

## Example

```python
from asynchronise import Asynchronise

asy = Asynchronise()

@asy.send
async def do_expensive_multistep_stuff():
    flour: Ingredient[Flour] = await go_to_the_store()
    yield flour

    egg: Egg = await get_eggs(variety="scrambled")
    yield eggs, "scrambled"

    egg: Egg = await get_eggs(variety="raw")
    yield eggs, "raw"

    milk: Ingredient[Milk] = await get_milk()
    yield milk, "liquid"

@asy.collect({
    "egg": (Egg, "scrambled", lambda egg: egg.weight > 100)
})
def eat_egg(egg):
    # This won't block the event loop 
    time.sleep(10) 
    print("Yummy!")
    
@asy.send
@asy.collect({
    "orders": (int, "customer_order", None),
    "flour": (Flour, None, lambda flour: flour.type == "rye"),
    "liquid": (None, "liquid", None)
})
async def make_dough(orders, flour, liquid):
    # I don't actually understand how making bread works, sorry to any bakers out there.
    for order_num in range(orders):
        await liquid.stir()
        dough = await flour.mix(liquid)
        yield dough, order_num
    
```