Add Google Bard

This commit is contained in:
aki66938
2023-12-14 09:46:04 +08:00
parent 8f5a0d9d61
commit c653cda0ff
6 changed files with 49 additions and 1 deletions

33
base/func_bard.py Normal file
View File

@@ -0,0 +1,33 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import bardapi
import requests
class BardAssistant:
def __init__(self, conf: dict) -> None:
self._token = conf["token"]
self._bard = bardapi.core.Bard(self._token)
def __repr__(self):
return 'BardAssistant'
@staticmethod
def value_check(conf: dict) -> bool:
if conf:
return all(conf.values())
return False
def get_answer(self, msg: str, sender: str = None) -> str:
response = self._bard.get_answer(msg)
return response['content']
if __name__ == "__main__":
from configuration import Config
config = Config().BardAssistant
if not config:
exit(0)
bard_assistant = BardAssistant(config)
rsp = BardAssistant.get_answer("who are you?")
print(rsp)