Got the database setup and am able to pull a random word from the query. I can read the themes table and have the async functions setup, but not yet working as expected. There are a few test scripts in there that need to be cleaned up before pushing to main.

This commit is contained in:
Norm Rasmussen
2023-12-04 13:42:06 -05:00
parent df49bc9b26
commit e1c61bec3d
13 changed files with 178276 additions and 14 deletions

Binary file not shown.

28
all_words_tst.py Normal file
View File

@ -0,0 +1,28 @@
import requests
from sqlalchemy import text, create_engine
from sqlalchemy.orm import Session
from time import sleep
# engine = create_engine("sqlite+pysqlite:///allwords.db", echo=True)
# with Session(engine) as connect:
# with engine.connect() as connect:
# selections = connect.execute(text("SELECT words from all_words ORDER BY RANDOM() LIMIT 1"))
# print(selections)
# print(type(selections))
# for row in selections:
# y = row.words
# print(y)
# connect.execute(text("CREATE TABLE IF NOT EXISTS all_words (words TEXT(55))"))
headers = {"content-type": "application/json"}
words = requests.get("https://random-word-api.herokuapp.com/all", headers=headers).json()
words = str(words)[1:-1]
words = words.replace(',','\n')
f = open('./data.txt', 'w')
f.write(words)
f.close()
# for word in words:
# sleep(1)
# connect.execute(text(f"INSERT INTO all_words VALUES (:word)"), {"word": word})
# connect.commit()

26
async_test.py Normal file
View File

@ -0,0 +1,26 @@
import asyncio
import requests
async def grab_words():
while True:
await asyncio.sleep(.5)
word = str(requests.get("https://random-word-api.herokuapp.com/word").text)[2:-2]
print(word)
async def every(__seconds: float, func, *args, **kwargs):
while True:
func(*args, **kwargs)
await asyncio.sleep(__seconds)
async def main():
asyncio.ensure_future(grab_words())
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(grab_words())
loop.run_forever()
# loop.create_task(every(1, grab_words()))

178187
data.txt Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -2,17 +2,38 @@ from gpt4all import GPT4All
import requests
from pathlib import Path
MODEL = GPT4All(
model_name="gpt4all-falcon-q4_0.gguf",
# model_path=(Path.home() / ".cache" / "gpt4all"),
# /root/.pyenv/versions/gpt-song-prompt/lib/python3.10/site-packages/gpt4all
allow_download=True,
)
WORD_PROMPT = str(requests.get("https://random-word-api.herokuapp.com/word").text)[2:-2]
SYSTEM_TEMPLATE = 'A single sentence based on a word.'
PROMPT_TEMPLATE = '### Instruction: {0} \n### Response: '
with MODEL.chat_session(SYSTEM_TEMPLATE, PROMPT_TEMPLATE):
response = MODEL.generate(f"A single sentence about {WORD_PROMPT}.", temp=0.7)
print(WORD_PROMPT)
resp = str(response.splitlines()[0])
print(resp)
def prompt():
MODEL = GPT4All(
model_name="gpt4all-falcon-q4_0.gguf",
# model_path=(Path.home() / ".cache" / "gpt4all"),
# /root/.pyenv/versions/gpt-song-prompt/lib/python3.10/site-packages/gpt4all
allow_download=False,
)
WORD_PROMPT = str(requests.get("https://random-word-api.herokuapp.com/word").text)[
2:-2
]
SYSTEM_TEMPLATE = "A creative response about a word."
PROMPT_TEMPLATE = "### Instruction: {0} \n### Response: "
response = MODEL.generate(
f"Tell me something interesting about {WORD_PROMPT}.",
temp=0.7,
callback=stop_on_token_callback,
)
print(response)
# with MODEL.chat_session(SYSTEM_TEMPLATE, PROMPT_TEMPLATE):
# response = MODEL.generate(f"A single sentence about {WORD_PROMPT}.", temp=0.7)
# print(WORD_PROMPT)
# resp = str(response.splitlines()[0])
# print(resp)
def stop_on_token_callback(token_id, token_string):
if "." in token_string:
return False
return True
if __name__ == "__main__":
prompt()

View File

BIN
words_prompts.db Normal file

Binary file not shown.