更新为官方api接口
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import bardapi
|
||||
|
||||
|
||||
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)
|
||||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import google.generativeai as genai
|
||||
|
||||
class BardAssistant:
|
||||
def __init__(self, conf: dict) -> None:
|
||||
self._api_key = conf["api_key"]
|
||||
self._model_name = conf["model_name"]
|
||||
genai.configure(api_key=self._api_key)
|
||||
self._bard = genai.GenerativeModel(self._model_name)
|
||||
|
||||
|
||||
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.generate_content(msg)
|
||||
return response.text
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user