@@ -133,6 +133,10 @@ xinghuo_web: # -----讯飞星火web模式api配置这行不填-----
|
|||||||
GtToken: # GtToken
|
GtToken: # GtToken
|
||||||
prompt: 你是智能聊天机器人,你叫 wcferry。请用这个角色回答我的问题 # 根据需要对角色进行设定
|
prompt: 你是智能聊天机器人,你叫 wcferry。请用这个角色回答我的问题 # 根据需要对角色进行设定
|
||||||
```
|
```
|
||||||
|
bard: # -----bard配置这行不填-----
|
||||||
|
api_key: # api-key 创建地址:https://ai.google.dev/pricing?hl=en,创建后复制过来即可
|
||||||
|
model_name: gemini-pro # 新模型上线后可以选择模型
|
||||||
|
|
||||||
|
|
||||||
## HTTP
|
## HTTP
|
||||||
如需要使用 HTTP 接口,请参考 [wcfhttp](https://wechatferry.readthedocs.io/zh/latest/?badge=latest)。
|
如需要使用 HTTP 接口,请参考 [wcfhttp](https://wechatferry.readthedocs.io/zh/latest/?badge=latest)。
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import google.generativeai as genai
|
||||||
import bardapi
|
|
||||||
|
class BardAssistant:
|
||||||
|
def __init__(self, conf: dict) -> None:
|
||||||
class BardAssistant:
|
self._api_key = conf["api_key"]
|
||||||
def __init__(self, conf: dict) -> None:
|
self._model_name = conf["model_name"]
|
||||||
self._token = conf["token"]
|
genai.configure(api_key=self._api_key)
|
||||||
self._bard = bardapi.core.Bard(self._token)
|
self._bard = genai.GenerativeModel(self._model_name)
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return 'BardAssistant'
|
def __repr__(self):
|
||||||
|
return 'BardAssistant'
|
||||||
@staticmethod
|
|
||||||
def value_check(conf: dict) -> bool:
|
@staticmethod
|
||||||
if conf:
|
def value_check(conf: dict) -> bool:
|
||||||
return all(conf.values())
|
if conf:
|
||||||
return False
|
return all(conf.values())
|
||||||
|
return False
|
||||||
def get_answer(self, msg: str, sender: str = None) -> str:
|
|
||||||
response = self._bard.get_answer(msg)
|
def get_answer(self, msg: str, sender: str = None) -> str:
|
||||||
return response['content']
|
response = self._bard.generate_content(msg)
|
||||||
|
return response.text
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from configuration import Config
|
from configuration import Config
|
||||||
config = Config().BardAssistant
|
config = Config().BardAssistant
|
||||||
if not config:
|
if not config:
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
bard_assistant = BardAssistant(config)
|
bard_assistant = BardAssistant(config)
|
||||||
rsp = BardAssistant.get_answer("who are you?")
|
rsp = BardAssistant.get_answer("who are you?")
|
||||||
print(rsp)
|
print(rsp)
|
||||||
|
|||||||
@@ -71,9 +71,5 @@ xinghuo_web: # -----讯飞星火web模式api配置这行不填 抓取方式详
|
|||||||
prompt: 你是智能聊天机器人,你叫wcferry。请用这个角色回答我的问题 # 根据需要对角色进行设定
|
prompt: 你是智能聊天机器人,你叫wcferry。请用这个角色回答我的问题 # 根据需要对角色进行设定
|
||||||
|
|
||||||
bard: # -----bard配置这行不填-----
|
bard: # -----bard配置这行不填-----
|
||||||
token: # token 长这样 eQhXAaCa3c3lUVXl-EvA210yikeNMsXHtDAX7doVyeFtW6ZbS-ENTSZg4-_713z1rWSXDQ.
|
api_key: # api-key 创建地址:https://ai.google.dev/pricing?hl=en,创建后复制过来即可
|
||||||
# 你的bard的token,抓取方式见https://github.com/dsdanielpark/Bard-API,支持gemini(账号设置为美国),cooike值为__Secure-1PSID
|
model_name: gemini-pro # 新模型上线后可以选择模型
|
||||||
# 特殊注意事项:
|
|
||||||
# 1、只需要登录gmail抓取账号的__Secure-1PSID即可
|
|
||||||
# 2、如果网页登录了bard,已配置的机器人token会失效,需要清除浏览器上的google账号的cookie录后,重新抓取cooike值
|
|
||||||
# 3、新建的账号可能无法登录bard,需要提前确认是否可以使用bard
|
|
||||||
|
|||||||
1
robot.py
1
robot.py
@@ -16,6 +16,7 @@ from base.func_chengyu import cy
|
|||||||
from base.func_news import News
|
from base.func_news import News
|
||||||
from base.func_tigerbot import TigerBot
|
from base.func_tigerbot import TigerBot
|
||||||
from base.func_xinghuo_web import XinghuoWeb
|
from base.func_xinghuo_web import XinghuoWeb
|
||||||
|
from base.func_bard import BardAssistant
|
||||||
from configuration import Config
|
from configuration import Config
|
||||||
from constants import ChatType
|
from constants import ChatType
|
||||||
from job_mgmt import Job
|
from job_mgmt import Job
|
||||||
|
|||||||
Reference in New Issue
Block a user