Skip to content

Commit

Permalink
add get chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-gee committed Nov 28, 2023
1 parent aff4793 commit cded792
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pip install webtranspose
<a href="https://twitter.com/mikegeecmu">
<img src="https://img.shields.io/twitter/follow/mikegeecmu?style=flat&label=%40mikegeecmu&logo=twitter&color=0bf&logoColor=fff" alt="X" />
</a>
<a href="https://github.com/mikegeecmu/webtranspose/blob/main/LICENSE">
<img src="https://img.shields.io/github/license/mike-gee/webtranspose?label=license&logo=github&color=f80&logoColor=fff" alt="License" />
<a href="https://github.com/mike-gee/webtranspose/blob/master/LICENSE.rst">
<img src="https://img.shields.io/badge/LICENSE-GNU%20AGPLv3-blue" alt="License" />
</a>
<a href="https://github.com/mikegeecmu/webtranspose/blob/main/LICENSE">
<img src="https://img.shields.io/badge/docs-Web%20Transpose-blue" alt="License" />
Expand Down Expand Up @@ -45,6 +45,9 @@ In the near future, **nobody will open websites**. Instead, we will be directly
```python
import webtranspose as webt

import os
os.environ['WEBTRANSPOSE_API_KEY'] = "YOUR WEBT API KEY"

crawl = webt.Crawl(
"https://www.example.com",
max_pages=100,
Expand All @@ -58,6 +61,9 @@ await crawl.crawl() # crawl.queue_crawl() for async
```python
import webtranspose as webt

import os
os.environ['WEBTRANSPOSE_API_KEY'] = "YOUR WEBT API KEY"

schema = {
"Merchant Name": "string",
"Title of Product": "string",
Expand All @@ -67,11 +73,28 @@ schema = {
scraper = webt.Scraper(
schema,
render_js=True,
api_key="YOUR_WEBTRANSPOSE_API_KEY"
)
out_json = scraper.scrape("https://www.example.com")
```

## Web Search (SERP API)

```python
import webtranspose as webt

import os
os.environ['WEBTRANSPOSE_API_KEY'] = "YOUR WEBT API KEY"

results = webt.search("what caused the fourth great ninja war?")
# results.keys()
# ['results']

# AI Filter
results = webt.search_filter("Paul Graham's Blog")
# results.keys()
# ['results', 'filtered_results']
```


## Installation

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[tool.poetry]
name = "webtranspose"
version = "0.2.1"
version = "0.3.0"
description = "APIs for the internet"
authors = ["Mike Gee <[email protected]>"]

Expand Down
28 changes: 28 additions & 0 deletions src/webtranspose/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,31 @@ def delete_crawls(self, crawl_id_list: list):
"crawl_id_list": crawl_id_list,
}
run_webt_api(query_json, "v1/chat/crawls/delete", self.api_key)


def get_chatbot(chatbot_id: str, api_key = None) -> Chatbot:
"""
Get a chatbot.
:param chatbot_id: The ID of the chatbot.
:return: The chatbot.
"""
if api_key is None:
api_key = os.environ.get("WEBTRANSPOSE_API_KEY")
if api_key is None:
raise ValueError(
"No Web Transpose API provided. \n\nTo use Chatbots, set the WEBTRANSPOSE_API_KEY from https://webtranspose.com."
)
get_json = {
"chatbot_id": chatbot_id,
}
chat_json = run_webt_api(get_json, "v1/chat/get", api_key)
chatbot_data = chat_json.get('chatbot', {})
chatbot = Chatbot(
chatbot_id=chatbot_data.get('id'),
name=chatbot_data.get('name'),
max_pages=chatbot_data.get('num_run', 100),
verbose=False,
_created=True
)
return chatbot

0 comments on commit cded792

Please sign in to comment.