8000 GitHub - shoggoth13/aityping
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

shoggoth13/aityping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

AITyping

Using AI to "type" (really validate) Python code. Tries to be "Ambient AI". Allows you to do things like:

isinstance("Julia", PersonName)
>>> True

isinstance("Idaho", PersonName)
>>> False

🚀 Overview

The typing module in Python helps the user understand the codebase better. They are useful for distinguishing between ints and strings, for example. The aityping module helps do "fuzzy typing". This is really run-time validation. However, it's bundled up as a type so that you can use it with Pydantic Models easily.

📄 Installation

pip install aityping

💻 Usage

Setup

First, you need to set your OpenAI key:

import os
os.environ["OPENAI_API_KEY"] = 'YOUR_OPENAI_API_KEY'

Quickstart

Next we import the get_ai_type function:

from aityping import get_ai_type

After that is done we can create a "type" with some fuzzy logic

PersonName = get_ai_type("is a persons name")

We can now use this to do type checking as we would with any other type.

isinstance("Julia", PersonName)
>>> True

isinstance("Idaho", PersonName)
>>> False

We can also use it to type a Pydantic model and then have that do validation.

from pydantic import BaseModel

class Record(BaseModel):
    name: PersonName

Record(name='Julia')
>>> Record(name='Julia')

Record(name='Idaho')
>>> ValidationError: 1 validation error for Record
>>> name
>>>   Flagged as invalid. (type=type_error)

LLM Configuration

By default, this will use the following LLM configuration:

ChatOpenAI(model="gpt-3.5-turbo", temperature=0)

If you want to use a different configuration, you easily can!

from langchain.chat_models import ChatOpenAI
PersonName = get_ai_type("is a persons name", llm=ChatOpenAI(model="gpt-4"))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0