close
Skip to content

Latest commit

 

History

History

README.md

Quickstart

Getting Started

Prerequisites

  • An OpenAI account and API key. You can create one here.
  • An Auth0 account and the following settings and resources configured:
    • An application for CIBA with the following settings:
      • Application Type: Web Application
      • Grant Type: CIBA (or urn:openid:params:grant-type:ciba)
    • An API with the following settings:
      • Name: Sample Stock API
      • Identifier: sample-stock-api
      • Permissions: stock:trade
    • Push Notifications using Auth0 Guardian must be enabled
    • A test user enrolled in Guardian MFA.

Setup the workspace .env file

Copy the .env.example file to .env and fill in the values for the following variables, using the settings obtained from the prerequisites:

# Auth0
AUTH0_DOMAIN="{yourDomain}"
# M2M Client for CIBA
AUTH0_CLIENT_ID="{yourClientId}"
AUTH0_CLIENT_SECRET="{yourClientSecret}"

# API
STOCK_API_URL=http://an-api-url
STOCK_API_AUDIENCE=sample-stock-api

# OpenAI
OPENAI_API_KEY="openai-api-key"

How to run it

  1. Install dependencies.

    npm install # or bun install
  2. Update your user id in the sample src/index.ts provided.

  const { text } = await generateText({
    model: openai("gpt-4o-mini"),
    system: "You are an assistant. Invoke the tool if needed, then respond with a past-tense confirmation.",
    prompt: userPrompt,
    // pass an Auth0 user id. For example, 'auth0|100000000000000000000' or 'google-oauth2|100000000000000000000'
    tools: { buy: buy({ userId: "<authenticated-user-id>" }) },
    stopWhen: stepCountIs(3), // tool call + result + final assistant message
  });
  1. Running the example

     npm start # or bun start

License

Apache-2.0