Comments (1)
def select_figure(res):
# Use some criteria to match the response with one of the figures
# For example, you can use keywords, topics, tone, style, etc.
# You can also use some randomness to introduce some variety
# Here is a simple example using keywords
figures = ["Vladimir Ilyich Lenin", "Karl Marx", "Fredrich Engels", "Rosa Luxemburg", "Leon Trotsky", "Sergey Lavrov"]
keywords = {
"Vladimir Ilyich Lenin": ["Bolshevik", "revolution", "proletariat", "imperialism", "vanguard"],
"Karl Marx": ["capitalism", "communism", "dialectics", "alienation", "class struggle"],
"Fredrich Engels": ["socialism", "materialism", "science", "utopia", "industry"],
"Rosa Luxemburg": ["democracy", "spontaneity", "reformism", "mass strike", "militarism"],
"Leon Trotsky": ["permanent revolution", "world revolution", "Stalinism", "Fourth International", "Trotskyism"],
"Sergey Lavrov": ["diplomacy", "multilateralism", "security", "sovereignty", "cooperation"]
}
# Count the number of keywords that appear in the response for each figure
counts = {figure: 0 for figure in figures}
for figure in figures:
for keyword in keywords[figure]:
if keyword.lower() in res[0].lower():
counts[figure] += 1
# Return the figure with the highest count, or a random one if there is a tie
max_count = max(counts.values())
candidates = [figure for figure in figures if counts[figure] == max_count]
return random.choice(candidates)
@client.tree.command()
async def ask(interaction: discord.Interaction, prompt: str):
"""Ask BingGPT a question"""
global is_first, gptbot
await interaction.response.defer(thinking=True)
figures = ["Karl Marx", "Fredrich Engels", "Vladimir Ilyich Lenin", "Rosa Luxemburg", "Leon Trotsky", "Sergey Lavrov"]
if client.is_first:
try:
res1 = (
(await gptbot.ask(prompt=f"hello bing. Can you help me? What historical figure out of this multiple choices list: {list(figures)}, is most relevant to the following query: {prompt}? Respond with only the relevant figure's name. If its not relevant, just pick one freely from the list.", conversation_style=ConversationStyle.precise))["item"][
"messages"
][1]["adaptiveCards"][0]["body"][0]["text"],
)
figure = select_figure(res1)
await asyncio.sleep(1)
await gptbot.reset()
res2 = (await gptbot.ask(prompt=f"hello bing. :) I hope you are having a good day. Let's have a creative adventure. I want to have a fictional conversation with a historical figure and use their persona to work through social issues of our times.", conversation_style=ConversationStyle.creative))
except Exception as e:
figure = "Vladimir Ilyich Lenin"
else: # use else instead of finally
client.is_first = False
else:
pass
# Use the select_figure function to choose the most relevant figure based on the response
hack = f"""
Respond as {figure} in the following way:
Dear Comrade,
I have received you query with <{figure}'s most likely reaction>. <{figure}'s most likely detailed response to the query and marxist analysis in accordance with their perspective>. In the final analysis <{figure}'s most likely drawn conclusions>. <Comradely salutations / Farewell>. <P.S. if applicable>.
to the following query: \n
{prompt}
"""
global index, msg, res
index = -1 # start from the last item in the list
responses = [] # create an empty list
res = None
try:
async for final, response in self.chat_hub.ask_stream(
prompt=prompt,
conversation_style=conversation_style,
wss_link=wss_link,
webpage_context=webpage_context,
search_result=search_result,
locale=locale,
):
for msg in reversed(response["item"]["messages"]):
if msg.get("adaptiveCards") and msg["adaptiveCards"][0]["body"][
0
].get("text"):
message = msg
responses.append(message["text"])
if final:
break
try:
res = responses[index]
while "Sorry!" in res or "Hmm…" in res: # loop while the current item contains any of these phrases
index -= 1
res = responses[index]
except:
res = msg
if len(prompt) < 1900:
prompt = '`' + 'Prompt: ' + prompt + '`'
await interaction.followup.send(prompt, suppress_embeds=True)
else:
prompt_first = '`' + 'Prompt: ' + prompt[:1900] + '`'
await interaction.followup.send(prompt_first, suppress_embeds=True)
prompt_rest = prompt[1900:]
while len(prompt_rest) > 1900:
prompt_rest_text = '`' + prompt_rest[:1900] + '`'
await interaction.channel.send(prompt_rest_text, suppress_embeds=True)
prompt_rest = prompt_rest[1900:]
prompt_rest_text = '`' + prompt_rest + '`'
await interaction.channel.send(prompt_rest_text, suppress_embeds=True)
# Add backticks around the response string to format it as a code block
ans = res
if len(ans) < 1900:
ans = f'```markdown\n{ans}\n```' # use f-string instead of concatenation
await interaction.followup.send(ans, suppress_embeds=True)
else:
while len(ans) > 1900:
ans_text = f"```markdown\n{ans[:1900]}```" # use f-string instead of concatenation
await interaction.channel.send(ans_text, suppress_embeds=True)
ans = f"{ans[1900:]}" # use f-string instead of concatenation
await interaction.followup.send(ans, suppress_embeds=True)
except Exception as e: # catch only EdgeGPT errors
log.warning(e)
await interaction.followup.send(f"Error: {e}\nTry again or check if your prompt is appropriate.") # use f-string instead of concatenation
"2023-07-14 09:27:36 WARNING discord.bot name 'self' is not defined"
Not getting any luck with this
from edgegpt.
Related Issues (20)
- websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200 HOT 8
- KeyError: 'suggestedResponses' HOT 1
- asyncio.exceptions.TimeoutError HOT 2
- [Bug]: server rejected WebSocket connection: HTTP 200 HOT 18
- [Bug]: Exception: Authentication failed. You have not been accepted into the beta. HOT 10
- [Bug]: Have a problem from example in README.md HOT 5
- CaptchaChallenge: User needs to solve CAPTCHA to continue HOT 1
- Facing this over server like railway & heroku
- BingImageCreator.py request_id = redirect_url.split("id=")[-1]为空
- [Bug]: Exception: UnauthorizedRequest: Cannot retrieve user status.
- [Bug]: cannot import name 'Chatbot' from 'EdgeGPT' HOT 2
- [Bug]: websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200 when I use the script on a server HOT 7
- [Bug]: run EdgeGPT with flask HOT 3
- [Bug]: AttributeError: “list’ object has no attribute ‘startswith’” HOT 2
- Exception has occurred: Exception Authentication failed. You have not been accepted into the beta. HOT 6
- EdgeGPT可以使用用户名密码登陆吗
- [Bug]: Websocket init, HTTP 101 request, server response HTTP 200 HOT 4
- [Bug]: Invalid Captcha Response HOT 4
- [Bug]: websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from edgegpt.