NPI
NPi is an open-source platform providing Tool-use APIs to empower AI agents with the ability to take action in virtual world!
🛠️Try NPi Online: Try NPi on online Playground
👀 NPi Example: Highly recommended to check this first - See what you can build with NPi.
🔥 Introducing NPi: Why we build NPi?
📚 NPi Documentation: How to use NPi?
📢 Join our community on Discord: Let's build NPi together 👻 !
NPi (Natural-language Programming Interface), pronounced as "N π", is an open-source platform providing Tool-use APIs to empower AI agents with the ability to operate and interact with a diverse array of software tools and applications.
Installation
pip install npiai
One-Minute Quick Start
Let's create a new tool to compute the nth Fibonacci number. Start by crafting a new Python file titled main.py and insert the following snippet:
import os
import json
import asyncio
from openai import OpenAI
from npiai import FunctionTool, function
class MyTool(FunctionTool):
def __init__(self):
super().__init__(
name='Fibonacci',
description='My first NPi tool',
)
@function
def fibonacci(self, n: int) -> int:
"""
Get the nth Fibonacci number.
Args:
n: The index of the Fibonacci number in the sequence.
"""
if n == 0:
return 0
if n == 1:
return 1
return self.fibonacci(n - 1) + self.fibonacci(n - 2)
async def main():
async with MyTool() as tool:
print(f'The schema of the tool is\n\n {json.dumps(tool.tools, indent=2)}')
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
messages = [
{
"role": "user",
"content": "What's the 10-th fibonacci number?",
}
]
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=tool.tools, # use tool as functions package
tool_choice="auto",
max_tokens=4096,
)
response_message = response.choices[0].message
if response_message.tool_calls:
result = await tool.call(tool_calls=response_message.tool_calls)
print(f'The result of function\n\n {json.dumps(result, indent=2)}')
if __name__ == "__main__":
asyncio.run(main())
Now, run the tool:
python main.py
You will see the function result in OpenAI function calling format:
[
{
"role": "tool",
"name": "fibonacci",
"tool_call_id": "call_4KItpriZmoGxXgDloI5WOtHm",
"content": 55
}
]
content: 55 is the result of function calling, and the schema:
[
{
"type": "function",
"function": {
"name": "fibonacci",
"description": "Get the nth Fibonacci number.",
"parameters": {
"properties": {
"n": {
"description": "The index of the Fibonacci number in the sequence.",
"type": "integer"
}
},
"required": [
"n"
],
"type": "object"
}
}
}
]
That's it! You've successfully created and run your first NPi tool. 🎉
Next Steps
License
Apache License 2.0
Metadata
Release files for npiai 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| npiai-0.2.3.tar.gz | 49.6 kB | Without provenance | Details for npiai-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| npiai-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for npiai-0.2.3-py3-none-any.whl |
Total release size: 120.0 kB
Release files / npiai-0.2.3.tar.gz
| Download URL | npiai-0.2.3.tar.gz |
|---|---|
| Size | 49.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cb1f203426b1a1c0d64c94ce6bcc416cf6919e86add192f1c0b5d48c56653af
|
|
BLAKE2b-256 checksum How to use checksums |
00fc06b06df729e51996df01221981b08b6c6cfa689195dc679a7721a9395c18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.10 Darwin/22.6.0
|
Release files / npiai-0.2.3-py3-none-any.whl
| Download URL | npiai-0.2.3-py3-none-any.whl |
|---|---|
| Size | 70.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e8ab0677818bd7544065fe65c047a507467e4a1cb2baca52d3aa22db141d977
|
|
BLAKE2b-256 checksum How to use checksums |
0512c2f81124d073e3366e9443208c23e5b79c0b21f20f686197c0bb384640f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.10 Darwin/22.6.0
|
Security for npiai 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.