Skip to content

Commit

Permalink
docs and format
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed Jun 1, 2023
1 parent ad59d1c commit 77419ec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
26 changes: 22 additions & 4 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,40 @@
class Chatbot()
```

Synchronous wrapper for the AsyncChatbot class.

<a id="Bard.AsyncChatbot"></a>

## AsyncChatbot Objects

```python
class AsyncChatbot()
```

A class to interact with Google Bard.
Parameters
session_id: str
The __Secure-1PSID cookie.
proxy: str
timeout: int
Request timeout in seconds.
session: requests.Session
Requests session object.

<a id="Bard.Chatbot.ask"></a>
<a id="Bard.AsyncChatbot.load_conversation"></a>

#### load\_conversation

```python
async def load_conversation(file_path: str, conversation_name: str) -> bool
```

Loads a conversation from history file. Returns whether the conversation was found.

<a id="Bard.AsyncChatbot.ask"></a>

#### ask

```python
def ask(message: str) -> dict
async def ask(message: str) -> dict
```

Send a message to Google Bard and return the response.
Expand Down
14 changes: 7 additions & 7 deletions src/Bard.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import argparse
import asyncio
import json
import os
import random
import re
import string
import sys
from typing import Dict
from typing import List

import httpx
import asyncio
from prompt_toolkit import prompt
from prompt_toolkit import PromptSession
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
Expand All @@ -17,8 +19,6 @@
from rich.console import Console
from rich.markdown import Markdown

from typing import List, Dict


def __create_session() -> PromptSession:
return PromptSession(history=InMemoryHistory())
Expand Down Expand Up @@ -61,22 +61,22 @@ def __init__(
):
self.loop = asyncio.get_event_loop()
self.async_chatbot = self.loop.run_until_complete(
AsyncChatbot.create(session_id, proxy, timeout)
AsyncChatbot.create(session_id, proxy, timeout),
)

def save_conversation(self, file_path: str, conversation_name: str):
return self.loop.run_until_complete(
self.async_chatbot.save_conversation(file_path, conversation_name)
self.async_chatbot.save_conversation(file_path, conversation_name),
)

def load_conversations(self, file_path: str) -> List[Dict]:
return self.loop.run_until_complete(
self.async_chatbot.load_conversations(file_path)
self.async_chatbot.load_conversations(file_path),
)

def load_conversation(self, file_path: str, conversation_name: str) -> bool:
return self.loop.run_until_complete(
self.async_chatbot.load_conversation(file_path, conversation_name)
self.async_chatbot.load_conversation(file_path, conversation_name),
)

def ask(self, message: str) -> dict:
Expand Down

0 comments on commit 77419ec

Please sign in to comment.