Framework for the textbase package.
Project description
textbase-framework
An add-on for the textbase repository which enables you to deploy your bots to the internet for everyone to use!
To use it, you just have to import the library and use a decorator function called bot
.
You can also use different models by importing the models
module. Currently we support:
- OpenAI
- HuggingFace
- BotLibre
Example:
from textbase_framework import bot, Message
from textbase_framework.models import OpenAI
OpenAI.api_key = os.getenv("OPENAI_API_KEY")
# System prompt; this will set the tone of the bot for the rest of the conversation.
SYSTEM_PROMPT = """You are chatting with an AI. There are no specific prefixes for responses, so you can ask or talk about anything you like.
The AI will respond in a natural, conversational manner. Feel free to start the conversation with any question or topic, and let's have a
pleasant chat!
"""
@bot() #The decorator function
def on_message(message_history: List[Message], state: dict = None):
# Your logic for the bot. A very basic request to OpenAI is provided below. You can choose to handle it however you want.
bot_response = OpenAI.generate(
model="gpt-3.5-turbo",
system_prompt=SYSTEM_PROMPT,
message_history=message_history
)
'''
The response HAS to be in the format given below so that our backend framework has no issues communicating with the frontend.
'''
response = {
"data": {
"messages": [
{
"type": "string",
"value": bot_response
},
{
"type": "audio",
"value": ""
}
],
"state": state
},
"errors": [
{
"message": ""
}
]
}
return {
"status_code": 200,
"response": response
}
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
Built Distribution
Close
Hashes for textbase_framework-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d118b00200613752f30d3f7395695e869ec957d35f7130fe79943aa68ccd31a |
|
MD5 | 7fdb2f7d241900edf925c94b1ae77961 |
|
BLAKE2b-256 | e548743561efdd1c8db8de95c8cb147bd170edf10cee984c901011101fcd0b99 |