Skip to content

Commit

Permalink
Code added for Jsonnet parsing and also added a test case for this.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh4902 committed Sep 13, 2023
1 parent bc0c1e1 commit 43d2333
Show file tree
Hide file tree
Showing 10,227 changed files with 594,768 additions and 522,943 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parent":null,"pid":3709,"argv":["/opt/homebrew/Cellar/node/20.5.1/bin/node","/Users/harshvardhanparmar/Github-Projects/EdgeChains/JS/jsonnet-demo/node_modules/.bin/tap","--ts"],"execArgv":[],"cwd":"/Users/harshvardhanparmar/Github-Projects/EdgeChains/JS/jsonnet-demo","time":1694583338577,"ppid":3708,"coverageFilename":"/Users/harshvardhanparmar/Github-Projects/EdgeChains/JS/jsonnet-demo/.nyc_output/69330958-c7d6-4b21-bd2e-73292007bc48.json","externalId":"","uuid":"69330958-c7d6-4b21-bd2e-73292007bc48","files":[]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parent":"69330958-c7d6-4b21-bd2e-73292007bc48","pid":3710,"argv":["/opt/homebrew/Cellar/node/20.5.1/bin/node","/Users/harshvardhanparmar/Github-Projects/EdgeChains/JS/jsonnet-demo/app.test.js"],"execArgv":[],"cwd":"/Users/harshvardhanparmar/Github-Projects/EdgeChains/JS/jsonnet-demo","time":1694583338891,"ppid":3709,"coverageFilename":"/Users/harshvardhanparmar/Github-Projects/EdgeChains/JS/jsonnet-demo/.nyc_output/ef8874cb-60b5-4d41-bd70-5b0277756cd4.json","externalId":"app.test.js","uuid":"ef8874cb-60b5-4d41-bd70-5b0277756cd4","files":[]}
1 change: 1 addition & 0 deletions JS/jsonnet-demo/.nyc_output/processinfo/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"processes":{"69330958-c7d6-4b21-bd2e-73292007bc48":{"parent":null,"children":["ef8874cb-60b5-4d41-bd70-5b0277756cd4"]},"ef8874cb-60b5-4d41-bd70-5b0277756cd4":{"parent":"69330958-c7d6-4b21-bd2e-73292007bc48","externalId":"app.test.js","children":[]}},"files":{},"externalIds":{"app.test.js":{"root":"ef8874cb-60b5-4d41-bd70-5b0277756cd4","children":[]}}}
18 changes: 18 additions & 0 deletions JS/jsonnet-demo/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Jsonnet } from "@hanazuki/node-jsonnet";
const jsonnet = new Jsonnet();

// Evaluates a simple Jsonnet program into a JSON value
const result = await jsonnet.extString("keepMaxToken","true")
.extString("query","")
.extString("keepContext","true")
.extString("context","")
.extString("history","")
.extString("keepChatHistory","true")
.extCode("maxToken","100")
.evaluateFile('./example.jsonnet')
.then();


export async function parseJsonnet(){
return JSON.parse(result);
}
21 changes: 21 additions & 0 deletions JS/jsonnet-demo/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test, beforeEach, afterEach } from 'tap';
import { parseJsonnet } from './app.js';

test('Parse Jsonnet',async ({same,end}) =>{
const result = await parseJsonnet();
same(result,{
context: '',
history: 'Chat History: ',
maxTokens: 100,
preset: 'You will be given context that may or may not be related to the question. If the context is related to the question, use it to answer the question.\n' +
" Otherwise, say that you don't know the answer, and attempt to answer it anyways using an 'In General' format\n" +
' Follow Up Input: {question}\n' +
' Context: {context}\n' +
' Chat History: {chat_history}\n',
prompt: 'Question: \n' +
'You will be given context that may or may not be related to the question. If the context ',
query: 'Question: ',
topK: 5
});
end;
});
23 changes: 23 additions & 0 deletions JS/jsonnet-demo/example.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

local maxTokens = if(std.extVar("keepMaxToken") == "true") then std.extVar("maxToken") else 10000;
local preset = |||
You will be given context that may or may not be related to the question. If the context is related to the question, use it to answer the question.
Otherwise, say that you don't know the answer, and attempt to answer it anyways using an 'In General' format
Follow Up Input: {question}
Context: {context}
Chat History: {chat_history}
|||;
local query = "Question: "+ std.extVar("query");
local context = if(std.extVar("keepContext") == "true") then std.extVar("context") else "";
local history = "Chat History: "+ if(std.extVar("keepChatHistory") == "true") then std.extVar("history") else "";
local prompt = std.join("\n", [query, preset, context, history]);
{
"maxTokens": maxTokens,
"topK": 5,
"query": query,
"preset" : preset,
"context": context,
"history": history,
"prompt": if(std.length(prompt) > maxTokens) then std.substr(prompt, 0, maxTokens) else prompt
}
1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/cmake-js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/color-support

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/nyc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/opener

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/rc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/rimraf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/tap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/tap-mocha-reporter

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/tap-parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions JS/jsonnet-demo/node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43d2333

Please sign in to comment.