Skip to main content

A GPT wrapper that learns from user feedback

Project description

FeedbackGPT

FeedbackGPT is a simple-to-use mechanism for improving LLM responses based on human feedback. Currently, this library wraps LLMs provided by OpenAI and exposes a chat interface that is almost identical in usage to those provided by OpenAI.

Documentation

Coming soon!

Getting Started

Installation

pip install feedbackgpt

Example Usage

Run Locally

This example stores and retrieves feedback locally. It is for demo/prototyping purposes and any provided feedback will be deleted between runs.

from feedback import FeedbackGPT

# Insert your own OpenAI Key
OPEN_AI_KEY="YOUR_OPEN_AI_KEY"

# Initialize FeedbackGPT
feedback_gpt = FeedbackGPT(OPEN_AI_KEY)

# Example message that is sent to LLM
messages = [
	{
		"role": "user",
		"content": "17077 is a prime number"
	}
]

# Before feedback is added, the model responds incorrectly
response = feedback_gpt.chat(messages, temperature=0)
response_message = response.choices[0].message.content
print(response_message)
# Outputs:
# No, 17077 is not a prime number. It can be divided evenly by 7 and 2441.

# Provide feedback on how FeedbackGPT can better respond next time
feedback = "The correct answer is 17077 IS a prime number. It is NOT divisible by either 7 or 2441."
feedback_gpt.feedback(messages, response_message, feedback)

# After feedback is added, the FeedbackGPT responds to the message correctly
response = feedback_gpt.chat(messages, temperature=0)
response_message = response.choices[0].message.content
print(response_message)
# Outputs:
# Yes, 17077 is a prime number.

Run Persistent Feedback Memory

FeedbackGPT integrates with Pinecone in order to store feedback that persists across sessions. In order to leverage persistent feedback, you'll first need to create a Pinecone account and retrieve your API Key and environment. You can then initialize FeedbackGPT as follows:

from feedbackgpt import FeedbackGPT

# Insert your own OpenAI Key
OPEN_AI_KEY="YOUR_OPEN_AI_KEY"

# Specify Pinecone API Key and Environment
pinecone_options = {
	"pineone_key": "YOUR_PINECONE_API_KEY",
	"pinecone_environment": "YOUR_PINECONE_ENVIRONMENT"
}

# Initialize FeedbackGPT with Pinecone Options
feedback_gpt = FeedbackGPT(OPEN_AI_KEY, pinecone_options=pinecone_options)

# Example message that is sent to LLM
messages = [
	{
		"role": "user",
		"content": "17077 is a prime number"
	}
]

# Before feedback is added, the model responds incorrectly
response = feedback_gpt.chat(messages, temperature=0)
response_message = response.choices[0].message.content
print(response_message)
# Outputs:
# No, 17077 is not a prime number. It can be divided evenly by 7 and 2441.

# Provide feedback on how FeedbackGPT can better respond next time
feedback = "The correct answer is 17077 IS a prime number. It is NOT divisible by either 7 or 2441."
feedback_gpt.feedback(messages, response_message, feedback)

# After feedback is added, the FeedbackGPT responds to the message correctly
# NOTE: The pincone index may take a few seconds to update. So, feedback may not be immediately reflected.
response = feedback_gpt.chat(messages, temperature=0)
response_message = response.choices[0].message.content
print(response_message)
# Outputs:
# Yes, 17077 is a prime number.

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

feedbackgpt-0.0.1.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

feedbackgpt-0.0.1-py3-none-any.whl (6.1 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