Skip to content

Commit

Permalink
add Bard AI
Browse files Browse the repository at this point in the history
  • Loading branch information
Qewertyy committed Nov 17, 2023
1 parent 133d96b commit e849f6f
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
10 changes: 10 additions & 0 deletions examples/async_bard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import asyncio
from lexica import AsyncClient

async def main(prompt: str) -> dict:
client = AsyncClient()
response = await client.bard(prompt)
return response

if __name__ == "__main__":
print(asyncio.run(main("hello, who are you?")))
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/bard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from lexica import Client

def main(prompt: str) -> dict:
client = Client()
response = client.bard(prompt)
return response

if __name__ == "__main__":
print(main("hello, who are you?"))
36 changes: 34 additions & 2 deletions lexica/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ def gpt(self, prompt: str,context: str=False) -> dict:
Returns:
dict: Answer from the API in the following format:
{
"status": str,
"content": str
"message": str,
"content": str,
"code": int
}
"""
params = {
Expand Down Expand Up @@ -197,4 +198,35 @@ def getImages(self,task_id:str,request_id:str) -> dict:
json=payload,
headers={"content-type": "application/json"}
)
return resp

def bard(self, prompt: str,context: str=False) -> dict:
"""
Get an answer from Bard AI by google for the given prompt
Example:
>>> client = Client()
>>> response = client.bard("Hello, Who are you?")
>>> print(response)
Args:
prompt (str): Input text for the query.
Returns:
dict: Answer from the API in the following format:
{
"message": str,
"content": str,
"code": int
}
"""
params = {
"model_id": 20,
"prompt": prompt
}
resp = self._request(
url=f'{self.url}/models',
method='POST',
params=params,
headers={"content-type": "application/json"}
)
return resp
31 changes: 31 additions & 0 deletions lexica/core_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,37 @@ async def gpt(self, prompt: str,context: str = False) -> dict:
headers = {"content-type": "application/json"}
)
return resp

async def bard(self, prompt: str,context: str = False) -> dict:
"""
Get an answer from Bard AI by google for the given prompt
Example:
>>> client = Client()
>>> response = await client.bard("Hello, Who are you?")
>>> print(response)
Args:
prompt (str): Input text for the query.
Returns:
dict: Answer from the API in the following format:
{
"message": str,
"content": str,
"code": int
}
"""
params = {
"model_id": 20,
"prompt": prompt
}
resp = await self._request(
url=f'{self.url}/models',
method='POST',
params=params,
headers = {"content-type": "application/json"}
)
return resp

async def upscale(self, image: bytes) -> bytes:
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def get_long_description():

setup(
name="lexica-api",
version="1.3.9",
version="1.4.0",
author="Qewertyy",
author_email="[email protected]",
description="The python package for api.qewertyy.me",
Expand Down

0 comments on commit e849f6f

Please sign in to comment.