Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Text to SQL query #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jdubpark
Copy link

@jdubpark jdubpark commented Jun 1, 2023

Convert text to SQL query for more expressive ChatGPT searches, by using GPT, and executing queries on Flipside Crypto. Reference implementation caesarHQ/textSQL.

Flow

  1. ChatGPT dispatches its parsed user prompt to the plugin endpoint and follows the provided config
  2. For any non-specific searches, fall back to "Text to SQL" endpoint
  3. This endpoint calls GPT-3.5 with the prompt and prepended examples for a few-shot inference on text -> SQL
  4. The endpoint tries to parse the GPT output as JSON. If failed,
  5. The endpoint extracts SQL query from GPT and calls Flipside Crypto
  6. The endpoint returns any result from Flipside Crypto to ChatGPT

Requirements

  1. GPT API Key (process.env.OPENAI_API_KEY)
  2. Flipside Crypto API Key (process.env.FLIPSIDE_CRYPTO_API_KEY)

Limitations

  • ChatGPT plugin timeout: 45 seconds round trip for API calls
  • On our API: GPT API time + Flipside Crypto time

GPT API timeout: unknown, not measured yet
Flipside Crypto timeout: custom (currently set to 1 minute), but is bounded by (45 seconds - GPT API response time)

Work in Progress

  • Text/prompt to SQL on manual endpoint hit
  • OpenAI config for catch-all text-to-sql endpoint
  • Timeout resolution for timely response to plugin call
  • Tweak prepended prompt (examples & table schemes)

Note

When calling GPT API, we currently send user's original prompt with prepended prompts:

  1. First, we prepend text-to-sql examples (tested on Flipside).

https://github.com/jdubpark/solana-chatgpt-plugin/blob/69a2c4e910c86f255f4602298c84fca3279728e9/chatgpt-plugin/src/pages/api/handlers/generic-sql/index.ts#L90

  1. Then, we prepend the table schemas directly copied from Flipside docs.

https://github.com/jdubpark/solana-chatgpt-plugin/blob/69a2c4e910c86f255f4602298c84fca3279728e9/chatgpt-plugin/src/pages/api/handlers/generic-sql/index.ts#L89

  1. Then, we prepend the user's prompt (wrapped in GPT's chat-styled object) within the prompt template.

https://github.com/jdubpark/solana-chatgpt-plugin/blob/69a2c4e910c86f255f4602298c84fca3279728e9/chatgpt-plugin/src/pages/api/handlers/generic-sql/prompt.ts#L9-L26

cc @ngundotra

@vercel
Copy link

vercel bot commented Jun 1, 2023

@jdubpark is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants