Skip to content

Instantly share code, notes, and snippets.

@JarbasAl
Created October 6, 2023 03:57
Show Gist options
  • Save JarbasAl/16788bdcff3fa5bfb3634d6f2116cc04 to your computer and use it in GitHub Desktop.
Save JarbasAl/16788bdcff3fa5bfb3634d6f2116cc04 to your computer and use it in GitHub Desktop.
import random
from functools import wraps
import requests
from ovos_solver_openai_persona.engines import OpenAIChatCompletionsSolver
def rewrite(prompt: str):
def layer_handler(func):
solver = OpenAIChatCompletionsSolver({"key": "sk-xxxx"})
solver.initial_prompt = "your task is to rewrite text as if it was spoken by a different character"
func.solver = solver
@wraps(func)
def call_function(*args, **kwargs) -> str:
res = func(*args, **kwargs)
if prompt:
return solver.get_spoken_answer(prompt + ":" + str(res))
return solver.get_spoken_answer(str(res))
return call_function
return layer_handler
@rewrite("Rewrite this as if written by H.P.Lovecraft")
def lovecraftify(text: str):
return text
@rewrite(f'Add more "dude"ness to')
def dudeify(text: str):
return text
@rewrite(f'Rewrite this as if being explained to a 5 year old')
def eli5(text: str):
return text
utt = "Quantum mechanics is a branch of physics that describes the behavior of particles at the smallest scales. " \
"It involves principles such as superposition, where particles can exist in multiple states simultaneously, " \
"and entanglement, where particles become connected and can influence each other's properties."
print(lovecraftify(utt))
# Quantum mechanics unveils the eldritch secrets of the infinitesimal realm,
# where particles, ensnared in the web of superposition, dwell in manifold states.
# Through the dread phenomenon of entanglement, these entities intertwine,
# their very essence entwined, shaping the fabric of reality.
print(dudeify(utt))
# Quantum mechanics is like, the raddest branch of physics, dude.
# It's all about particles at the tiniest scales, doing crazy stuff like
# being in multiple states at once (superposition) and getting all connected and influencing each other (entanglement).
print(eli5(utt))
# Quantum mechanics is like a special kind of science that helps us understand really tiny things.
# It tells us that these tiny things can be in more than one place at the same time,
# and they can also be connected to each other and affect each other's behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment