Reformat
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
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"]
|
||||
self._prompt = conf['prompt']
|
||||
self._proxy = conf['proxy']
|
||||
|
||||
|
||||
genai.configure(api_key=self._api_key)
|
||||
self._bard = genai.GenerativeModel(self._model_name)
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return 'BardAssistant'
|
||||
|
||||
@@ -25,17 +26,16 @@ class BardAssistant:
|
||||
return False
|
||||
|
||||
def get_answer(self, msg: str, sender: str = None) -> str:
|
||||
response = self._bard.generate_content([{'role': 'user',
|
||||
'parts':[msg]}])
|
||||
response = self._bard.generate_content([{'role': 'user', 'parts': [msg]}])
|
||||
return response.text
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from configuration import Config
|
||||
config = Config().BardAssistant
|
||||
if not config:
|
||||
exit(0)
|
||||
|
||||
|
||||
bard_assistant = BardAssistant(config)
|
||||
if bard_assistant._proxy:
|
||||
os.environ['HTTP_PROXY'] = bard_assistant._proxy
|
||||
|
||||
Reference in New Issue
Block a user