-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const autocannon = require('autocannon'); | ||
|
||
autocannon({ | ||
url:"http://localhost:8080/quote?query=fun", | ||
connections: 100, | ||
pipelining: 1, | ||
duration:10 | ||
},console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "benchmark", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"autocannon": "^7.15.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { build } from "esbuild"; | ||
let runtime = process.argv[2]; | ||
|
||
|
||
build({ | ||
entryPoints: ["src/index.js", "src/prompts/quote.jsonnet","src/prompts/config.jsonnet"], | ||
// entryPoints: ["src/index.js"], | ||
bundle: true, | ||
// minify: true, | ||
minifySyntax: true, | ||
// outfile: "bin/app.js", | ||
outdir: "bin", | ||
format: "esm", | ||
target: "esnext", | ||
platform: "node", | ||
// external: ["arakoo"], | ||
loader:{ | ||
".jsonnet":"copy" | ||
}, | ||
define: { | ||
"process.env.arakoo": JSON.stringify(runtime === "arakoo"), | ||
}, | ||
}).catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "hono-openai", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@arakoodev/jsonnet": "file:../../../jsonnet/", | ||
"@hono/node-server": "^1.11.0", | ||
"hono": "^3.9" | ||
}, | ||
"type": "module", | ||
"devDependencies": { | ||
"esbuild": "^0.20.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Hono } from "hono"; | ||
const app = new Hono(); | ||
// import { serve } from "@hono/node-server"; | ||
import Jsonnet from "@arakoodev/jsonnet"; | ||
|
||
let openAiEndpoint = "https://api.openai.com/v1/chat/completions"; | ||
|
||
app.get('/quote', async (c) => { | ||
try { | ||
let jsonnet = new Jsonnet(); | ||
let query = c.req.query("query"); | ||
let prompt = JSON.parse(jsonnet.evaluateFile("./prompts/quote.jsonnet")).prompt; | ||
let fetchBody = jsonnet.extString("prompt", prompt).extString("query", query).extString("model", "gpt-3.5-turbo").evaluateFile("./prompts/config.jsonnet"); | ||
console.log(typeof fetchBody) | ||
let response = await fetch(openAiEndpoint, { | ||
method: "POST", | ||
headers: { | ||
"Content-type": "application/json", | ||
"Authorization": "Bearer openai key here" | ||
}, | ||
body: fetchBody | ||
}); | ||
let body = await response.json(); | ||
console.log(body.choices[0].message.content) | ||
return c.json(body.choices[0].message.content); | ||
} catch (error) { | ||
console.log("error occured"); | ||
console.log(error); | ||
} | ||
}) | ||
|
||
app.get('/hello', async (c) => { | ||
try { | ||
let jsonnet = new Jsonnet(); | ||
const code = ` | ||
local username = std.extVar('name'); | ||
local Person(name='Alice') = { | ||
name: name, | ||
welcome: 'Hello ' + name + '!', | ||
}; | ||
{ | ||
person1: Person(username), | ||
person2: Person('Bob'), | ||
}`; | ||
let result = jsonnet.extString("name", "ll").evaluateSnippet(code); | ||
return c.json(JSON.parse(result)); | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
}) | ||
|
||
app.fire(); | ||
|
||
// serve(app, (info) => { | ||
// console.log(`Server started on http://localhost:${info.port}`); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
model: std.extVar("model"), | ||
messages:[ | ||
{ | ||
role:"system", | ||
content:std.extVar("prompt") | ||
}, | ||
{ | ||
role:"user", | ||
content:std.extVar("query") | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
local prompt =||| | ||
You will provide the user with inspiring, thought-provoking, or funny quotes every time they ask for one. It could be quotes from famous philosophers, authors, celebrities, or even random quotes that will make them smile. Each quote will come with the name of the person who said it and must include a short description of their background and achievements. Ask the user for a brief description of what kind of quote they would like to receive, for example "a funny quote about life". If the description leaves out details, such as what type (inspirational, for example) of quote or the subject (dogs, for example) of the quote you should randomly generate a replacement and find a quote relating to that. If the user is doesn't have a subject in mind or would just like a random quote, generate a quote of a random type and subject and give it to the user. If the user shows disapproval for a quote, make a note of it and immediately provide a quote, relating to the same subjects as before, from a different person. If the user approves of a quote, immediately provide another quote that relates with the original. If the user asks about the person who originally said the quote, provide a brief description of the person's background and achievements that relate to the quote. | ||
|||; | ||
{ | ||
"prompt" : prompt, | ||
} |