Skip to content

Commit e4389b1

Browse files
committed
initial
0 parents  commit e4389b1

File tree

8 files changed

+1287
-0
lines changed

8 files changed

+1287
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.env
2+
node_modules

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# graphql-openai
2+
3+
This is an example implementation of openai with a graphql yoga server.
4+
5+
Server runs on http://localhost:4000/graphql
6+
It requires environment variable `OPENAI_API_KEY` set with your OpenAI token
7+
8+
## Install
9+
`npm install -g pnpm` if you do not have pnpm (other install options: https://pnpm.io/installation)
10+
11+
`pnpm install`
12+
13+
## Yoga Server
14+
15+
Set up your OpenAI token as `OPENAI_API_KEY` first in a .env file
16+
17+
Run:
18+
`pnpm dev`
19+
20+
Yoga comes with a graphiQL interface, so open http://localhost:4000/graphql and use the examples below to start.
21+
22+
## Graphql Requests
23+
24+
```graphql
25+
# Examples with gpt
26+
query getGpt {
27+
chatGpt(question: "What is the most powerful product for Apple MDM?") {
28+
question
29+
answer
30+
}
31+
}
32+
33+
subscription steamGpt {
34+
chatGpt(question: "What is the most powerful product for Apple MDM?") {
35+
question
36+
answer
37+
done
38+
}
39+
}
40+
41+
# Examples with davinci
42+
query animal {
43+
animals(question: "dog") {
44+
question
45+
answer
46+
}
47+
}
48+
49+
subscription animalStream {
50+
animals(question: "tiger") {
51+
question
52+
answer
53+
done
54+
}
55+
}
56+
```

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@sumcoding/graphql-openai",
3+
"version": "1.0.0",
4+
"description": "",
5+
"author": "@sumcoding",
6+
"license": "MIT",
7+
"scripts": {
8+
"dev": "cross-env NODE_ENV=development ts-node-dev --exit-child --respawn src/api/main.ts",
9+
"start": "ts-node src/api/main.ts"
10+
},
11+
"keywords": ["graphql", "gpt", "openai", "chat", "ai", "bot"],
12+
"dependencies": {
13+
"@graphql-tools/schema": "^10.0.0",
14+
"@graphql-yoga/plugin-graphql-sse": "^2.0.1",
15+
"dotenv": "^16.3.0",
16+
"graphql": "^16.6.0",
17+
"graphql-sse": "^2.1.4",
18+
"graphql-yoga": "^4.0.1",
19+
"openai": "^3.3.0"
20+
},
21+
"devDependencies": {
22+
"@types/node": "20.3.1",
23+
"cross-env": "7.0.3",
24+
"ts-node": "10.9.1",
25+
"ts-node-dev": "2.0.0",
26+
"typescript": "5.1.3"
27+
}
28+
}

0 commit comments

Comments
 (0)