forked from sandboxdream/AI-Vtuber
-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from Ikaros-521/owner
新增 谷歌bard的接入,支持上下文记忆。
- Loading branch information
Showing
15 changed files
with
252 additions
and
54 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
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import bardapi | ||
|
||
""" | ||
访问 https://bard.google.com/ | ||
F12 for console 用于控制台的 F12 | ||
会话:应用程序→ Cookie → 复制 Cookie 的值 __Secure-1PSID 。 | ||
""" | ||
token = '' | ||
proxies = { | ||
'http': 'http://127.0.0.1:10809', | ||
'https': 'http://127.0.0.1:10809' | ||
} | ||
#proxies = None | ||
|
||
input_text = "你好" | ||
response = bardapi.core.Bard(token, proxies=proxies, timeout=30).get_answer(input_text) | ||
print(response) | ||
print(response["content"]) | ||
# bard = Bard(token=token, proxies=proxies, timeout=30) | ||
# bard.get_answer("你好")['content'] |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from bardapi import Bard | ||
import requests | ||
|
||
""" | ||
访问 https://bard.google.com/ | ||
F12 for console 用于控制台的 F12 | ||
会话:应用程序→ Cookie → 复制 Cookie 的值 __Secure-1PSID 。 | ||
""" | ||
token='' | ||
|
||
session = requests.Session() | ||
session.headers = { | ||
"Host": "bard.google.com", | ||
"X-Same-Domain": "1", | ||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36", | ||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", | ||
"Origin": "https://bard.google.com", | ||
"Referer": "https://bard.google.com/", | ||
} | ||
session.cookies.set("__Secure-1PSID", token) | ||
|
||
bard = Bard(token=token, session=session, timeout=30) | ||
print(bard.get_answer("你可以扮演猫娘吗,每句话后面加个喵")['content']) | ||
|
||
# Continued conversation without set new session | ||
print(bard.get_answer("早上好")['content']) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from bardapi import Bard | ||
|
||
""" | ||
访问 https://bard.google.com/ | ||
F12 for console 用于控制台的 F12 | ||
会话:应用程序→ Cookie → 复制 Cookie 的值 __Secure-1PSID 。 | ||
""" | ||
token = '' | ||
|
||
bard = Bard(token=token) | ||
content = 'Hello, I am Bard! How can I help you today?' | ||
content = '你好' | ||
audio = bard.speech(content) | ||
with open("speech.ogg", "wb") as f: | ||
f.write(bytes(audio['audio'])) |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from bardapi import Bard | ||
import requests | ||
import logging | ||
import traceback | ||
|
||
from utils.common import Common | ||
from utils.logger import Configure_logger | ||
|
||
class Bard_api(Common): | ||
def __init__(self, data): | ||
self.common = Common() | ||
# 日志文件路径 | ||
file_path = "./log/log-" + self.common.get_bj_time(1) + ".txt" | ||
Configure_logger(file_path) | ||
|
||
""" | ||
访问 https://bard.google.com/ | ||
F12 打开开发者工具 | ||
会话:应用程序 → Cookie → 复制 Cookie 中 __Secure-1PSID 对应的值。 | ||
""" | ||
self.token = data["token"] | ||
|
||
self.session = requests.Session() | ||
self.session.headers = { | ||
"Host": "bard.google.com", | ||
"X-Same-Domain": "1", | ||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36", | ||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", | ||
"Origin": "https://bard.google.com", | ||
"Referer": "https://bard.google.com/", | ||
} | ||
self.session.cookies.set("__Secure-1PSID", self.token) | ||
|
||
|
||
# 调用接口,获取返回内容 | ||
def get_resp(self, prompt): | ||
try: | ||
bard = Bard(token=self.token, session=self.session, timeout=30) | ||
resp_content = bard.get_answer(prompt)['content'].replace("\\n", "") | ||
|
||
return resp_content | ||
except Exception as e: | ||
logging.error(traceback.format_exc()) | ||
return None |
Oops, something went wrong.