forked from cofactoryai/textbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
38 lines (30 loc) · 1.25 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import textbase
from textbase.message import Message
from textbase import models
import os
from typing import List
# Load your OpenAI API key
models.OpenAI.api_key = "YOUR_API_KEY"
# or from environment variable:
# models.OpenAI.api_key = os.getenv("OPENAI_API_KEY")
# Prompt for GPT-3.5 Turbo
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!
"""
@textbase.chatbot("talking-bot")
def on_message(message_history: List[Message], state: dict = None):
"""Your chatbot logic here
message_history: List of user messages
state: A dictionary to store any stateful information
Return a string with the bot_response or a tuple of (bot_response: str, new_state: dict)
"""
if state is None or "counter" not in state:
state = {"counter": 0}
else:
state["counter"] += 1
# # Generate GPT-3.5 Turbo response
bot_response = models.OpenAI.generate(
system_prompt=SYSTEM_PROMPT,
message_history=message_history,
model="gpt-3.5-turbo",
)
return bot_response, state