将bard与Python和Brad-Api一起使用
#python #bard #generativeai

bard-api是一个python软件包,允许我们通过python脚本使用bard。

GitHub logo dsdanielpark / Bard-API

非官方的Python软件包通过Cookie Value返回Google Bard的响应。

Development Status :: 5 - Production/Stable

Google bard api

PyPI package Code style: black PyPI

通过cookie的值返回Google Bard的响应的python软件包。

请谨慎行事并负责任地使用此软件包。

我提到了bard推理过程进行了反向设计的this github repository(github.com/acheong08/Bard)。使用__Secure-1PSID,您可以提出问题并从Google Bard那里获得答案。该软件包设计用于应用于Python软件包ExceptNotifierCo-Coder。请注意,Bardapi不是免费的服务,而是提供的工具,可以帮助开发人员测试由于开发和发布Google Bard的API的延迟而测试某些功能。它的设计具有轻巧的结构,可以轻松适应官方API的出现。因此,我强烈建议将其用于任何其他目的。

hf-transllm

如果要测试开放式模型,那就是released under the Apache License (allowing




步骤1.获取cookie数据

转到https://bard.google.com并打开Chrome开发人员工具,然后单击Application选项卡。
单击Storage下的Cookies,然后复制_Secure-1PSID的值。

chrome

步骤2.安装bard-api和python-dotenv

pip install bardapi


pip install git+https://github.com/dsdanielpark/Bard-API.git
pip install python-dotenv

步骤3.创建.env文件

COOKIE_TOKEN='put your cookie value'

步骤4.编写代码

import os
from bardapi import Bard
from dotenv import load_dotenv


load_dotenv()

token = os.environ['COOKIE_TOKEN']
bard = Bard(token=token)
response = bard.get_answer("What is a LLM?")['content']
print(response)

output

LLM stands for Master of Laws. It is a postgraduate law degree that is typically obtained after completing a Juris Doctor (JD) degree. LLM programs can be general or specialized, and they can be offered in a variety of subjects, such as tax law, environmental law, and international law.

The LLM degree is a valuable credential for lawyers who want to specialize in a particular area of law or who want to advance their careers in academia or government. LLM programs can also help lawyers to develop their research and writing skills, which are essential for success in many legal careers.

The full form of LLM is Legum Magister, which is Latin for "Master of Laws." The LLM degree is abbreviated as LL.M. in English.

Here are some of the benefits of obtaining an LLM degree:

* **Specialization:** LLM programs allow you to specialize in a particular area of law, such as tax law, environmental law, or international law. This can give you a competitive edge in the job market and help you to advance your career.
* **Research and writing skills:** LLM programs can help you to develop your research and writing skills, which are essential for success in many legal careers.
* **International experience:** Many LLM programs are offered in countries outside of the United States. This can give you the opportunity to gain international experience and learn about different legal systems.

If you are interested in pursuing an LLM degree, there are a few things you should keep in mind:

* **Admission requirements:** Admission requirements for LLM programs vary from school to school. However, most programs require that you have a JD degree or an equivalent law degree.
* **Cost:** The cost of an LLM degree can vary depending on the school and the program. However, LLM programs can be expensive, so it is important to factor in the cost when making your decision.
* **Career opportunities:** LLM degrees can open up a variety of career opportunities for lawyers. However, the specific opportunities that are available to you will depend on your area of specialization and your work experience.

If you are considering pursuing an LLM degree, I recommend that you research different programs and talk to lawyers who have LLM degrees. This will help you to make an informed decision about whether or not an LLM degree is right for you.

指定输出格式

import os
from bardapi import Bard
from dotenv import load_dotenv


load_dotenv()

token = os.environ['COOKIE_TOKEN']
bard = Bard(token=token)
prompt='''
What is a LLM?
The answer format should be the following.

答案:{
[
id:1,
内容:草稿1
],
id:2,
内容:草稿2
]
}
'''
响应= bard.get_answer(提示)['content']
打印(响应)


## Get Drafts


python
导入我们
来自Bardapi进口吟游诗人
来自dotenv import load_dotenv

load_dotenv()

token = os.environ ['cookie_token']
bard = bard(token = token)
提示='''
什么是LLM?
'''

响应= bard.get_answer(提示)['选择']

选择回答:
id =选择['id']
响应=选择['content'] [0]
打印(id)
打印(响应)