Skip to content

Instantly share code, notes, and snippets.

@Jinksi
Created March 31, 2023 02:16
Show Gist options
  • Save Jinksi/c1b3b309702a332c1fd8d0c9f507d667 to your computer and use it in GitHub Desktop.
Save Jinksi/c1b3b309702a332c1fd8d0c9f507d667 to your computer and use it in GitHub Desktop.
Hello Woo product ChatGPT bot with marvin
import asyncio
import requests
from marvin import ai_fn, plugin, plugins, settings, Bot
consumer_key = "ck_"
consumer_secret = "cs_"
url = "https://woo-store-url.com"
@plugin
def fetch_products() -> list[dict]:
"""Use this plugin to fetch products from the WooCommerce API"""
endpoint = url + "/wp-json/wc/v3/products"
response = requests.get(endpoint, auth=(consumer_key, consumer_secret))
if response.status_code == 200:
products = response.json()
return products
else:
print("Error:", response.status_code)
return None
woo_bot = Bot(
name="Woo",
personality="Shop assistant",
instructions="You are helping a customer find a product. Show them what we have for sale.",
plugins=[fetch_products],
)
async def main():
await woo_bot.reset_thread()
await woo_bot.say(
"Hello! I am your am your helpful Woo bot, what can I help you with?"
)
await woo_bot.interactive_chat()
print(await woo_bot.history.log())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment