Skip to main content

File-based functions for ChatGPT's function calling with Pydantic support

Project description

Logo

File-based functions for ChatGPT's function calling with Pydantic support 🚀

Test Package version Supported Python versions

Key Features

  • Organization through file-centric functions, organized in directories.
  • Strong typing for functions using Pydantic.
  • Built-in in-memory FAISS vector database, with the option to integrate your own.
  • Easily test each function with an associated test.json file, supporting both unit and integration tests.
  • CI/CD integration, ensuring synchronicity between your vector db and the functions directory.
  • Minimalistic design with only two main dependencies: openai and pydantic.

Requirements

python >=3.9, <3.12
pydantic >=1.6, <=1.10.12
openai ^0.28.1

Installation

# pip
$ pip install sageai

# poetry
$ poetry add sageai

Functions Format

from typing import Optional

from pydantic import BaseModel, Field

from sageai.types.function import Function


class FunctionInput(BaseModel):
    location: str = Field(..., description="The city and state, e.g. San Francisco, CA.")


class FunctionOutput(BaseModel):
    weather: str


def get_current_weather(params: FunctionInput) -> FunctionOutput:
    weather = f"The weather in {params.location} is currently 22 degrees {params.unit}."
    return FunctionOutput(weather=weather)


function = Function(
    function=get_current_weather,
    description="Get the current weather in a given location.",
)

Setup

Create a functions directory in the root directory, and add your functions as described in the section above.

Then initalize SageAI.

sageai = SageAI(openai_key="")

Then index the vector database.

sageai.index()

That's it! Just start chatting 🚀

message = "What's the weather like in Boston right now?"
response = sageai.chat(message=message)
# The weather in Boston, MA is currently 22 degreees celsius.

Documentation

SageAI.init()

Pass

SageAI.index()

Pass

SageAI.chat()

Pass

Examples

Roadmap

  • Add tests
  • Support streaming
  • Support asyncio
  • Add debug flag for logger
  • Support Pydantic V2
  • Write Chainlit example
  • Write fullstack example

Contributing

Please see our CONTRIBUTING.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sageai-0.1.3.tar.gz (24.4 kB view hashes)

Uploaded Source

Built Distribution

sageai-0.1.3-py3-none-any.whl (12.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page