Python Integration

track_completion('https://api.requesty.ai/chat', 'organization_id')

This code must be placed before your chat interaction code. You only need to call track_completion once.

Usage

There are two main ways to use the requestyai library, depending on whether or not you want to track the ip_address and user_url:

Basic Usage (without ip_address and user_url): For basic usage, all you need to do is call the track_completion function with your endpoint:

from requestyai import track_completion 

track_completion('https://api.requesty.ai/chat')

Advanced Usage (with ip_address and user_url): If you want to track the ip_address and user_url, you need to extract these values in your chat function (e.g., chat()) and pass them to track_completion:

from flask import request
from requestyai import track_completion 

@app.route('/api/chat', methods=['POST'])
def chat():
    user_url = request.headers.get('Referer', 'N/A')
    ip_address = request.headers.get('X-Forwarded-For', request.remote_addr)
    track_completion('https://api.requesty.ai/chat'', ip_address=ip_address, user_url=user_url)

This code attempts to extract the Referer and X-Forwarded-For headers from the incoming HTTP request. If these headers aren't available, it uses default values ('N/A' for user_url and the client's IP address for ip_address).

Diagram

The following diagram provides a high-level overview of how the library works:

 User Message
        |
        v
OpenAI API <-- Requestyai Library captures 'user_message', 'user_timestamp', and 'engine'
        |
        v
  AI Response
        |
        v
 Requestyai Library captures 'bot_message' and 'bot_timestamp', then sends all data to the endpoint

Please note: This library is designed to work with OpenAI's Python library and it modifies the behavior of openai.Completion.create to capture data. Make sure you import and initialize chatbot_library before you use openai.Completion.create in your code.

Last updated