Skip to content

Commit bb2a999

Browse files
authored
add pollinations ai provider
1 parent 4a7667f commit bb2a999

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

chatbot.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import scratchattach as sa
2-
from openai import OpenAI
2+
import requests
33
import time
44

55
index = 0
66

7-
# AI Setup
8-
client = OpenAI(
9-
base_url="https://ai.aerioncloud.com/v1", # This provider has shut down, will need to be changed to another one
10-
api_key="sk=1234",
11-
)
7+
def encode(text: str):
8+
"""
9+
TODO: FIX: Function to encode special character into wen url format.
1210
11+
@parameter:
1312
13+
- text: the text to be encoded.
14+
"""
15+
encoded = encoded.replace("?", "%3D") # more here...
16+
17+
return encoded
18+
1419
# Function to simplify AI calling
1520
def answer(query: str, username: str):
1621
"""
@@ -23,20 +28,10 @@ def answer(query: str, username: str):
2328
"""
2429
global index
2530
print("Answering...")
31+
prompt = { "content": "You are a helpful scratch.mit.edu user and bot called ScratchOn. You cannot swear or do anything inappropriate. Never say anything bad about someone or something. Your language must be appropriate for 7-12 year olds. Always refer to yourself as ScratchOn, or _Scratch-On_ as your scratch username. Either refer to the user by their username, or don't refer to them at all. Keep your answers short and concise, up to 500 characters. Do not use regular emojis, only use Scratch-style emojis like :), _:D_, or XD. Speak like a scratch.mit.edu user would, using simple words and phrases a 12 years old would use in a chat, for example 'Hey!', 'That's cool!', 'Thanks!', 'No problem!', 'I guess you're right lol'. Answer the following user with their question/message." }
2632

27-
resp = client.chat.completions.create(
28-
model="gpt-4-turbo",
29-
messages=[
30-
{
31-
"role": "system",
32-
"content": "You are a helpful scratch.mit.edu user and bot called ScratchOn. You cannot swear or do anything inappropriate. Never say anything bad about someone or something. Your language must be appropriate for 7-12 year olds. Always refer to yourself as ScratchOn, or _Scratch-On_ as your scratch username. Either refer to the user by their username, or don't refer to them at all. Keep your answers short and concise, up to 500 characters. Do not use regular emojis, only use Scratch-style emojis like :), _:D_, or XD. Speak like a scratch.mit.edu user would, using simple words and phrases a 12 years old would use in a chat, for example 'Hey!', 'That's cool!', 'Thanks!', 'No problem!', 'I guess you're right lol'.",
33-
},
34-
{"role": "user", "content": f"{username}: {query}"},
35-
],
36-
)
37-
38-
result = resp.choices[0].message.content
39-
33+
res = requests.get(f"https://text.pollinations.ai/{encode(prompt + " : " + username + " : " + query)}")
34+
result = res.json()
4035
print("Answered !")
4136
return result
4237

0 commit comments

Comments
 (0)