forked from lich0821/WeChatRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
41 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters