Skip to content

shopsavvy/openai-shopsavvy-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI Function Calling + ShopSavvy

Ready-to-use OpenAI function calling schemas and examples for product search and price comparison using the ShopSavvy Data API.

Setup

Get an API key at shopsavvy.com/data.

Python

pip install openai shopsavvy-sdk

TypeScript

npm install openai @shopsavvy/sdk

Function Schemas

The schemas/ directory contains JSON schema definitions for each function that can be passed directly to the OpenAI API:

  • search_products.json - Search for products by keyword
  • get_offers.json - Get current retailer offers for a product
  • get_price_history.json - Get historical price data
  • get_deals.json - Browse current shopping deals

Python Example

import json
import os
from openai import OpenAI
from shopsavvy import ShopSavvyDataAPI, ShopSavvyConfig

client = OpenAI()
api = ShopSavvyDataAPI(ShopSavvyConfig(api_key=os.environ["SHOPSAVVY_API_KEY"]))

# Load function schemas
with open("schemas/search_products.json") as f:
    search_schema = json.load(f)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Find the best price for AirPods Pro"}],
    tools=[{"type": "function", "function": search_schema}],
)

See examples/example_python.py for a complete working example with tool call handling.

TypeScript Example

import OpenAI from 'openai'
import { ShopSavvyDataAPI } from '@shopsavvy/sdk'
import searchSchema from './schemas/search_products.json'

const openai = new OpenAI()
const api = new ShopSavvyDataAPI({ apiKey: process.env.SHOPSAVVY_API_KEY! })

const response = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Find the best price for AirPods Pro' }],
  tools: [{ type: 'function', function: searchSchema }],
})

See examples/example_typescript.ts for a complete working example with tool call handling.

License

MIT

About

OpenAI function calling schemas and examples for ShopSavvy Data API - Python and TypeScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages