Merge pull request #9 from hibobmaster/dev

Support citing internet sources from Bing response
This commit is contained in:
BobMaster 2023-04-14 19:39:15 +08:00 committed by GitHub
commit 1d0d17505f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -1,6 +1,6 @@
## Introduction ## Introduction
This is a simple Matrix bot that uses OpenAI's GPT API and Bing AI to generate responses to user inputs. The bot responds to five types of prompts: `!gpt`, `!chat` and `!bing` and `!pic` and `!bard` depending on the first word of the prompt. This is a simple Matrix bot that uses OpenAI's GPT API and Bing AI and Google Bard to generate responses to user inputs. The bot responds to five types of prompts: `!gpt`, `!chat` and `!bing` and `!pic` and `!bard` depending on the first word of the prompt.
![Bing](https://user-images.githubusercontent.com/32976627/231073146-3e380217-a6a2-413d-9203-ab36965b909d.png) ![Bing](https://user-images.githubusercontent.com/32976627/231073146-3e380217-a6a2-413d-9203-ab36965b909d.png)
![Bard](https://i.imgur.com/OCXEuaa.png) ![Bard](https://i.imgur.com/OCXEuaa.png)
![ChatGPT](https://i.imgur.com/kK4rnPf.jpeg) ![ChatGPT](https://i.imgur.com/kK4rnPf.jpeg)

View file

@ -7,7 +7,7 @@ logger = getlogger()
class BingBot: class BingBot:
def __init__(self, session: aiohttp.ClientSession, bing_api_endpoint: str, jailbreakEnabled: bool = False): def __init__(self, session: aiohttp.ClientSession, bing_api_endpoint: str, jailbreakEnabled: bool = True):
self.data = { self.data = {
'clientOptions.clientToUse': 'bing', 'clientOptions.clientToUse': 'bing',
} }
@ -18,7 +18,7 @@ class BingBot:
self.jailbreakEnabled = jailbreakEnabled self.jailbreakEnabled = jailbreakEnabled
if self.jailbreakEnabled: if self.jailbreakEnabled:
self.data['jailbreakConversationId'] = json.dumps(True) self.data['jailbreakConversationId'] = True
async def ask_bing(self, prompt) -> str: async def ask_bing(self, prompt) -> str:
self.data['message'] = prompt self.data['message'] = prompt
@ -44,7 +44,7 @@ class BingBot:
self.data['conversationId'] = json_body['conversationId'] self.data['conversationId'] = json_body['conversationId']
self.data['clientId'] = json_body['clientId'] self.data['clientId'] = json_body['clientId']
self.data['invocationId'] = json_body['invocationId'] self.data['invocationId'] = json_body['invocationId']
return json_body['response'] return json_body['details']['adaptiveCards'][0]['body'][0]['text']
except Exception as e: except Exception as e:
logger.error("Error Exception", exc_info=True) logger.error("Error Exception", exc_info=True)