ML functions
 
Loading...
Searching...
No Matches
ChatGPTRecommender Class Reference

A class that interacts with OpenAI's ChatGPT API for recommendation tasks, inheriting from MLFunction. More...

#include <ChatGPT.h>

Inheritance diagram for ChatGPTRecommender:
MLFunction

Public Member Functions

 ChatGPTRecommender ()
 Default constructor.
 
 ChatGPTRecommender (std::string url, std::string model)
 Constructor with custom URL and model.
 
 ~ChatGPTRecommender ()
 Destructor.
 
void apply (const SelectivityVector &rows, std::vector< VectorPtr > &args, const TypePtr &type, exec::EvalCtx &context, VectorPtr &output) const override
 Applies the ChatGPTRecommender function to the input array.
 
float * getTensor () const override
 Returns the tensor associated with this function.
 
CostEstimate getCost (std::vector< int > inputDims)
 Estimates the computational cost of applying the ChatGPTRecommender function.
 
- Public Member Functions inherited from MLFunction
virtual ~MLFunction ()=default
 Virtual destructor.
 
virtual std::vector< int > getDims ()
 Returns the dimensions of the function.
 
virtual std::string getFuncName ()
 Returns the name of the function.
 
virtual int getNumDims ()
 Returns the number of dimensions of the function.
 

Static Public Member Functions

static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures ()
 Returns the function signatures supported by this class.
 
static std::string getName ()
 Returns the name of the function.
 

Additional Inherited Members

- Protected Member Functions inherited from MLFunction
double getWeightedCost (std::string name, float cost)
 Calculates the weighted cost of the function.
 
std::vector< double > getCoefficientVector (std::string name)
 Retrieves the cost coefficients for the function.
 
- Protected Attributes inherited from MLFunction
std::vector< int > dims
 Dimensions of the function.
 

Detailed Description

A class that interacts with OpenAI's ChatGPT API for recommendation tasks, inheriting from MLFunction.

This class provides functionality to send user statistics and movie metadata to the ChatGPT API and retrieve personalized recommendations. It supports multi-threaded requests for improved performance.

Constructor & Destructor Documentation

◆ ChatGPTRecommender() [1/2]

ChatGPTRecommender::ChatGPTRecommender ( )
inline

Default constructor.

Initializes the ChatGPT API with the default URL and model ("gpt-3.5-turbo"). Requires the OPENAI_API_KEY environment variable to be set.

◆ ChatGPTRecommender() [2/2]

ChatGPTRecommender::ChatGPTRecommender ( std::string url,
std::string model )
inline

Constructor with custom URL and model.

Initializes the ChatGPT API with a custom URL and model. Requires the OPENAI_API_KEY environment variable to be set.

Parameters
urlThe URL of the OpenAI API endpoint.
modelThe model to use for text generation (e.g., "gpt-3.5-turbo").

◆ ~ChatGPTRecommender()

ChatGPTRecommender::~ChatGPTRecommender ( )
inline

Destructor.

Logs the total number of input tokens, output tokens, and API failures to a file.

Member Function Documentation

◆ apply()

void ChatGPTRecommender::apply ( const SelectivityVector & rows,
std::vector< VectorPtr > & args,
const TypePtr & type,
exec::EvalCtx & context,
VectorPtr & output ) const
inlineoverride

Applies the ChatGPTRecommender function to the input array.

This method processes the input array, sends user statistics and movie metadata to the ChatGPT API, and stores the personalized recommendations in the output vector.

Parameters
rowsA SelectivityVector specifying the rows to process.
argsA vector of input arguments (e.g., user statistics and movie metadata).
typeThe type of the output vector.
contextThe execution context.
outputThe output vector where the recommendations will be stored.

◆ getCost()

CostEstimate ChatGPTRecommender::getCost ( std::vector< int > inputDims)
inlinevirtual

Estimates the computational cost of applying the ChatGPTRecommender function.

Parameters
inputDimsA vector containing the dimensions of the input.
Returns
A CostEstimate object representing the estimated cost.

Reimplemented from MLFunction.

◆ getName()

static std::string ChatGPTRecommender::getName ( )
inlinestatic

Returns the name of the function.

Returns
The name of the function as a string ("chatgpt_recommender").

◆ getTensor()

float * ChatGPTRecommender::getTensor ( ) const
inlineoverridevirtual

Returns the tensor associated with this function.

Returns
A null pointer (no tensor is associated with this function).

Implements MLFunction.

◆ signatures()

static std::vector< std::shared_ptr< exec::FunctionSignature > > ChatGPTRecommender::signatures ( )
inlinestatic

Returns the function signatures supported by this class.

Returns
A vector of shared pointers to FunctionSignature objects.

The documentation for this class was generated from the following file: