No project description provided
Project description
Malevich is a platform for building, iterating and deploying AI-driven product backend flows:
- Vast library of pre-built components shortens the gap between the system design and first run
- You are not limited to our components: easily implement and integrate your own codebase
- Deploy on GPU and production with 1 line of code
Getting Started
Malevich is a Python package that help you to build your components and product flows. Dive deeper into our documentation here. Let's walkthrough how you can create an AI-based product with couple lines of code.
Installation
To install Malevich, you should have Python 3.10 and pip
package manager installed. Run the following command to install our package:
python3 -m pip install malevich
Make sure everything is set up:
malevich --help
Install Components
Malevich works like a package manager allowing you to install components and use them from within the code. Let's install some components for our pipeline:
malevich install spacy openai scrape
Browse through our library here and find the components that meet your needs.
Connect Components
The real magic happens when components are interconnected into a more complex and useful pipeline. Let's do it by writing a few more lines of code:
# flow.py
import os
import pandas as pd
from malevich import collection, flow
from malevich.openai import prompt_completion
from malevich.scrape import scrape_web
from malevich.spacy import extract_named_entities
prompt = """
You are a professional journalist. You've received
news containing many references to different people.
Your task is to understand the roles of these {entities}
and write a brief summary about them. The brief should
include the following information:
- Who is the person?
- What is their role in the news?
- What are the main events they are involved in?
Only include individuals for whom there is sufficient
information in the news. Otherwise, omit their names
entirely from the brief.
"""
@flow()
def write_brief():
# Scrape some news from the OpenAI blog.
links = collection(
'News Links',
df=pd.DataFrame(
[
'https://openai.com/blog/sam-altman-returns-as-ceo-openai-has-a-new-initial-board',
], columns=['link']
)
)
# The scraper app will retrieve information from websites specified by XPath —
# a query language that allows extracting information from markup documents.
text = scrape_web(
links,
config={
'spider': 'xpath',
'min_length': 100,
'max_results': 25,
'links_are_independent': True,
'max_depth': 1,
'spider_cfg': {
'components': [{
'key': 'news-text',
# Specify XPath query.
'xpath': "//div[@id='content']//text()"
}],
'output_type': 'text',
'include_keys': False
}
})
# Extract names of entities.
entities = extract_named_entities(
text, config={
'output_format': 'list',
'filter_labels': ['PERSON'],
}
)
# Write a brief about the news using OpenAI API
# to generate text based on our prompt and extracted names.
return text, prompt_completion(
entities,
config={
'user_prompt': prompt,
'openai_api_key': os.getenv('OPENAI_API_KEY'),
}
)
if __name__ == '__main__':
from malevich import CoreInterpreter
# Create a task for writing a brief.
pipeline = write_brief()
# Before running the task, interpret it to make
# the platform aware of dependencies and execution flow.
pipeline.interpret(
CoreInterpreter(
core_auth=('example', 'Welcome to Malevich!')
)
)
# Execute the task.
text, brief = pipeline()
# Save results.
text.get_df().to_csv('text.csv')
brief.get_df().to_csv('brief.csv')
Execute
Before executing this demo code, make sure you have the Open AI API key in your environment:
export OPENAI_API_KEY=<YOUR KEY>
Now, all you need is a 1 command to run the deployemnt:
python flow.py
Your results are stored in text.csv
and brief.csv
files.
Deploy
Running this as a script is cool, but what if you want to integrate this flow into your own system with a production deployment? That's done by adding just one line:
# ...
if __name__ == '__main__':
from malevich import CoreInterpreter
# Create a task for writing a brief.
pipeline = write_brief()
# Before deployment, interpret it to make
# the platform aware of dependencies and execution flow.
pipeline.interpret(
CoreInterpreter(
core_auth=('example', 'Welcome to Malevich!')
)
)
# Deploy the flow
print(pipeline.publish().get_url())
By running this script, you will get a link to an HTTP endpoint hosted by Malevich Core, which can be integrated into your application, be it a desktop, mobile, web app, or any other program. Enjoy the ride!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file malevich-0.4.1.tar.gz
.
File metadata
- Download URL: malevich-0.4.1.tar.gz
- Upload date:
- Size: 153.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb1b7cdd82c97d8591bfc009083dc927d3e435f958b578cb3698195dc288d98f |
|
MD5 | 3d39b962777dce2fe381d560bd060624 |
|
BLAKE2b-256 | a6307d9e1d92d85d7fa3c118c7775c5fa5c007934cd0264e2f1af3226c5070a4 |
File details
Details for the file malevich-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: malevich-0.4.1-py3-none-any.whl
- Upload date:
- Size: 220.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f54578345c8b4215ea74a0a0ad177afadc2d119042fa7f779119d4f01ff450ee |
|
MD5 | 842ea9f8c4cec099c715e1060ebe81d9 |
|
BLAKE2b-256 | 4e71a5e1dbe358660a8670de5bc000fcd9d2b225e5286c257b08b6c80c6189ba |