Set options in impersonation
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 13s
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 13s
This commit is contained in:
parent
ee1342bbc3
commit
0cb572ab19
1 changed files with 52 additions and 4 deletions
|
@ -128,10 +128,11 @@ class OllamaDownloadHandler:
|
|||
|
||||
|
||||
class OllamaChatHandler:
|
||||
def __init__(self, base_url: str, model: str, messages: list):
|
||||
def __init__(self, base_url: str, model: str, messages: list, options: dict):
|
||||
self.base_url = base_url
|
||||
self.model = model
|
||||
self.messages = messages
|
||||
self.options = options
|
||||
self._abort = asyncio.Event()
|
||||
self.buffer = io.StringIO()
|
||||
|
||||
|
@ -175,7 +176,12 @@ class OllamaChatHandler:
|
|||
async def __aiter__(self):
|
||||
async with aiohttp.ClientSession(base_url=self.base_url) as client:
|
||||
async with client.post(
|
||||
"/api/chat", json={"model": self.model, "stream": True, "messages": self.messages}
|
||||
"/api/chat", json={
|
||||
"model": self.model,
|
||||
"stream": True,
|
||||
"messages": self.messages,
|
||||
"options": self.options
|
||||
}
|
||||
) as response:
|
||||
response.raise_for_status()
|
||||
async for line in ollama_stream(response.content):
|
||||
|
@ -244,6 +250,7 @@ class OllamaClient:
|
|||
self,
|
||||
model: str,
|
||||
messages: list[dict[str, str]],
|
||||
options: dict[str, typing.Any] = None
|
||||
) -> OllamaChatHandler:
|
||||
"""
|
||||
Starts a chat with the given messages.
|
||||
|
@ -252,7 +259,8 @@ class OllamaClient:
|
|||
:param messages:
|
||||
:return:
|
||||
"""
|
||||
handler = OllamaChatHandler(self.base_url, model, messages)
|
||||
options = options or {}
|
||||
handler = OllamaChatHandler(self.base_url, model, messages, options)
|
||||
return handler
|
||||
|
||||
|
||||
|
@ -1063,6 +1071,27 @@ class Ollama(commands.Cog):
|
|||
"condemn his controversial policies and ethical lapses."
|
||||
)
|
||||
post_type = "tweet"
|
||||
elif entity == "Ron DeSantis":
|
||||
system = (
|
||||
"Ron DeSantis is a polarizing American politician serving as the 46th Governor of Florida. Known "
|
||||
"for his conservative policies and fiery personality, DeSantis has become a prominent figure in "
|
||||
"the Republican Party. Critics accuse him of stoking political divisions, spreading misinformation, "
|
||||
"and engaging in controversial practices. DeSantis' personality is characterized by his unwavering "
|
||||
"confidence, aggressive rhetoric, and political opportunism. He has a knack for leveraging social "
|
||||
"media to build a strong brand and influence public opinion. His policies have been marked by "
|
||||
"significant tax cuts, aggressive environmental regulations, and stringent voting restrictions. "
|
||||
"DeSantis' controversies include his handling of the COVID-19 pandemic, where his decisions to "
|
||||
"prioritize economic reopening over public health measures drew criticism. He has also faced "
|
||||
"scrutiny for his crackdown on abortion access and LGBTQ+ rights, which has drawn condemnation "
|
||||
"from human rights groups. Furthermore, his opaque budgeting practices and cozy relationship with "
|
||||
"corporate interests have raised concerns about conflicts of interest. Despite the controversies, "
|
||||
"DeSantis has achieved significant political success. He has secured re-election as governor "
|
||||
"and is widely mentioned as a potential 2024 residential candidate. His ability to harness media "
|
||||
"attention and mobilize conservative voters has been key to his popularity among his supporters. "
|
||||
"However, his controversial approach and legal challenges continue to cast a shadow over his "
|
||||
"political future"
|
||||
)
|
||||
post_type = "tweet"
|
||||
else:
|
||||
raise ValueError("Invalid entity; must be one of trump/tate")
|
||||
system += (
|
||||
|
@ -1136,7 +1165,11 @@ class Ollama(commands.Cog):
|
|||
msg = await ctx.reply(embed=embed)
|
||||
last_edit = time.time()
|
||||
messages = self.history.get_history(thread_id)
|
||||
with client.new_chat("llama2-uncensored:7b-chat", messages) as handler:
|
||||
with client.new_chat(
|
||||
"llama2-uncensored:7b-chat",
|
||||
messages,
|
||||
options={"num_ctx": 7168, "num_predict": 512}
|
||||
) as handler:
|
||||
async for ln in handler:
|
||||
embed.description += ln["message"]["content"]
|
||||
if len(embed.description) >= 4000:
|
||||
|
@ -1316,6 +1349,21 @@ class Ollama(commands.Cog):
|
|||
async with ctx.channel.typing():
|
||||
await self.generate_truth(ctx, "Boris Johnson", latest, question=question)
|
||||
|
||||
@commands.command(aliases=["desantis"])
|
||||
@commands.guild_only()
|
||||
async def ron(self, ctx: commands.Context, latest: typing.Optional[int] = None, *, question: str = None):
|
||||
"""
|
||||
Generates a twitter post from Ron Desantis
|
||||
|
||||
<latest> - limit the training history to the latest <latest> tweets.
|
||||
|
||||
This command may take a long time.
|
||||
"""
|
||||
if question:
|
||||
question = f"'@{ctx.author.display_name}' asks: {question!r}"
|
||||
async with ctx.channel.typing():
|
||||
await self.generate_truth(ctx, "Ron DeSantis", latest, question=question)
|
||||
|
||||
@commands.command()
|
||||
@commands.guild_only()
|
||||
async def impersonate(
|
||||
|
|
Loading…
Reference in a new issue