Skip to content

Simple example of openai served up as a graphql api, using graphql-yoga.

Notifications You must be signed in to change notification settings

sumcoding/graphql-openai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-openai

This is an example implementation of openai with a graphql yoga server.

Server runs on http://localhost:4000/graphql It requires environment variable OPENAI_API_KEY set with your OpenAI token

Install

npm install -g pnpm if you do not have pnpm (other install options: https://pnpm.io/installation)

pnpm install

Yoga Server

Set up your OpenAI token as OPENAI_API_KEY first in a .env file

Run: pnpm dev

Yoga comes with a graphiQL interface, so open http://localhost:4000/graphql and use the examples below to start.

Graphql Requests

subscription chat_stream {
  chat(question: "What is the best framework?") {
    question
    answer
  }
}

subscription animals_stream {
  animals(question: "Parrot") {
    answer
  }
}

query chat {
  chat(question: "What is the best framework?") {
    question
    answer
  }
}

query animals {
  animals(question: "Dog") {
    answer
  }
}

About

Simple example of openai served up as a graphql api, using graphql-yoga.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published