Skip to main content

Deliver AI products in days, not months, using requesty.ai

Project description

RequestyAI Python API library

tests

Deliver AI products in days, not months, using requesty.ai

Step up your AI game with a simple integration:

  • Real-time insights into your AI flows: See how your clients use your LLMs
  • Hassle free auditing and logging: Don't stress about storage and infra
  • Powerful analytics: Discover trends using your Requesty's insight-explorer

Installation

pip install requestyai

AInsights

A client library to effortlessly integrate powerful insights into your AI flows.

Create a client with minimal configuration and capture and request/response pair for future analysis.

Notes

Thread-safety

The insights client is thread-safe. You can safely use a single client from multiple threads.

Asynchronous

The insights client is asynchronous. capture()-ing requests/responses is a non-blocking operation, and it will not interrupt the flow of your application.

Usage pattern #1: Create client instance

If you prefer creating and using client instance, just add an AInsights instance next to your OpenAI one, and capture every interaction by adding a single call.

It doesn't matter if you're using simple free-text outputs, JSON outputs or tools, the insights client will capture everything.

Check out this working sample

from openai import OpenAI
from requestyai import AInsights


class OpenAIWrapper:
    def __init__(self, openai_api_key, requesty_api_key):
        self.model = OpenAI(api_key=openai_api_key)
        self.args = {
            model="gpt-4o",
            temperature=0.7,
            max_tokens=150
        }

        self.insights = AInsights.new_client(api_key=requesty_api_key)

    def chat(self, user_id: str, user_input: str):
        messages = [
            { "role": "system", "content": "You are a helpful assistant." },
            { "role": "user", "content": user_input }
        ]

        class Response(BaseModel):
            answer: str

        response = self.model.beta.chat.completions.parse(messages=messages,
                                                          response_format=Response,
                                                          **self.args)

        self.insights.capture(messages=messages,
                              response=response,
                              args=self.args,
                              user_id=user_id)

        return Response.model_validate_json(response.choices[0].message.content)


if __name__ == "__main__":
    requesty_api_key = os.environ["REQUESTY_API_KEY"]
    openai_api_key = os.environ["OPENAI_API_KEY"]

    wrapper = OpenAIWrapper(openai_api_key, requesty_api_key)

    # Dummy loggin to capture the user's ID
    user_id = input("User ID: ")

    while True:
        user_input = input("Ask any question?")
        response = wrapper.chat(user_id, user_input)
        print(response.answer)

Usage pattern #2: Use a global instance

You like it simple. You just want to call OpenAI from anywhere in your code, and the insights should be no different.

Just create a simple file (ainsights_instance.py is a reasonable name) in your project, and import it everywhere. The client is thread-safe.

Check out this working sample

import os
from requestyai import AInsights


requesty_key = os.environ["REQUESTY_KEY"]
ainsights = AInsights.new_client(api_key=requesty_key)

Then, calling OpenAI and capturing is as easy as:

It doesn't matter if you're using simple free-text outputs, JSON outputs or tools, the insights client will capture everything.

from openai import OpenAI
from ainsights_instance import ainsights


if __name__ == '__main__':
    openai.api_key = os.environ["OPENAI_API_KEY"]

    messages = [{ "role": "user", "content": user_input }]
    args = {
        model="gpt-4o-mini",
        temperature=0.7,
        max_tokens=150
    }
    response = openai.chat.completions.create(messages=messages, **args)

    ainsights.capture(messages=messages, response=response, args=args)

    print(response.choices[0].message.content)

User tracking

If you want your insights to be tied to a specific user, you can specify the user_id argument when calling capture(...).

See "Usage pattern #1" above for specific details.

Sample applications

Check out the samples directory for working examples you can try out in no time.

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

requestyai-0.3.4.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requestyai-0.3.4-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file requestyai-0.3.4.tar.gz.

File metadata

  • Download URL: requestyai-0.3.4.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.8.18 Linux/6.5.0-1025-azure

File hashes

Hashes for requestyai-0.3.4.tar.gz
Algorithm Hash digest
SHA256 5cd5b2a747a79445395f249f7363127980a78af28f3d6f558b585851136bfe79
MD5 641b90611a67e88c1a31b85186968199
BLAKE2b-256 10b337557de3eed78ed35b5b3d3228906d7b53b483ba8fd52d73b6ce0812deb1

See more details on using hashes here.

File details

Details for the file requestyai-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: requestyai-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.8.18 Linux/6.5.0-1025-azure

File hashes

Hashes for requestyai-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fba0a0860cdb106db76dede46ea4e02a16f2b35018ee009f7e3cdcf0900a2515
MD5 cd88863c9703176deb004a8ac452b6c1
BLAKE2b-256 91d30a471117fe38dfd864066682115f4ec703df075210cb7bb831eb17d89b42

See more details on using hashes here.

Supported by

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