Giter Site home page Giter Site logo

mutagen's Introduction

Mutagen

MutaGen is a Python library that makes it easy to dynamically mutate data structures (dictionaries, sets, lists, and models) based on user input. Built on top of Pydantic and leveraging the Instructor library, which simplifies working with structured outputs from large language models, MutaGen provides a flexible and efficient way to update data structures in response to user input, ensuring schema-adherent mutations that maintain data integrity. Get ready to supercharge your data manipulation workflows!

Key Features

  • AI-Powered Mutations: Leverages OpenAI-compatible language models to generate intelligent data structure mutations based on user input.
  • Schema-Adherent Updates: Ensures that mutated data structures adhere to their original schema, maintaining data integrity and consistency.
  • Flexible Data Support: Supports mutations for dictionaries, sets, lists, and custom models defined using Pydantic. Efficient and Scalable: Built on top of Pydantic and leveraging the Instructor library, MutaGen provides a lightweight and efficient solution for dynamic data manipulation.
  • Simple API: Offers a simple and intuitive API for integrating MutaGen into your application, making it easy to get started with AI-powered data mutations.

Examples

Mutate a dictionary

# Create a Mutagen instance with an Instructor client and an LLM model
mutagen = Mutagen(instructor_client, "meta-llama/Meta-Llama-3-70B-Instruct")

# Define a dictionary to mutate
input_dict = {"name": "John", "age": 25, "color": "blue"}

# Define a user message to guide the mutation
user_message = "I hate the color blue, and I'm 30 years old now!"

# Mutate the dictionary using the user message
new_dict, mutations = mutagen.mutate_dict(input_dict, user_message)

# new_dict: {"name": "John", "age": 30}
# mutations: [
#     Mutation(type='set', key='age', value=30),
#     Mutation(type='remove', key='color')
# ]

Mutate a Pydantic model

from pydantic import BaseModel

# Define a Pydantic model
class Person(BaseModel):
    name: str
    occupation: str

# Create an instance of the model
person = Person(name="John", occupation="Engineer")

# Define a user message to guide the mutation
user_message = "I want to change my occupation to Data Scientist."

# Mutate the model using the user message
new_person, mutations = mutagen.mutate_model(person, user_message)

# new_person: Person(name='John', occupation='Data Scientist')
# mutations: [Mutation(type='set', key='occupation', value='Data Scientist')]

Mutate a list or set

# Define a list to mutate
input_list = ["apple", "banana", "cherry"]

# Define a user message to guide the mutation
user_message = "I want to add a new fruit, orange."

# Mutate the list using the user message
new_list, mutations = mutagen.mutate_list(input_list, user_message)
# Use mutagen.mutate_set() for sets

# new_list: ["apple", "banana", "cherry", "orange"]
# mutations: [Mutation(type='add', value='orange')]

TODOs

  • v0.1 Release
  • Nested data structures

mutagen's People

Contributors

jonaslsaa avatar

Watchers

 avatar Kostas Georgiou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.