@jpoly1219/context-extractor 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -0
- package/package.json +30 -0
package/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# context-extractor
|
2
|
+
|
3
|
+
Extract relevant context from a codebase using a type-directed approach.
|
4
|
+
|
5
|
+
## npm Installation
|
6
|
+
|
7
|
+
Recommended.
|
8
|
+
|
9
|
+
```text
|
10
|
+
npm i @jpoly1219/context-extractor
|
11
|
+
```
|
12
|
+
|
13
|
+
## Manual Installation
|
14
|
+
|
15
|
+
Not recommended. If the above steps do not work, please leave a GitHub issue.
|
16
|
+
|
17
|
+
Install the following dependencies:
|
18
|
+
|
19
|
+
```text
|
20
|
+
npm install -g typescript-language-server typescript tsc
|
21
|
+
```
|
22
|
+
|
23
|
+
Clone the `ts-lsp-client` repo:
|
24
|
+
|
25
|
+
```text
|
26
|
+
git clone https://github.com/jpoly1219/ts-lsp-client
|
27
|
+
```
|
28
|
+
|
29
|
+
... and run these commands:
|
30
|
+
|
31
|
+
```text
|
32
|
+
cd ts-lsp-client
|
33
|
+
npm install
|
34
|
+
npm run build
|
35
|
+
```
|
36
|
+
|
37
|
+
Clone this repo.
|
38
|
+
|
39
|
+
```text
|
40
|
+
git clone https://github.com/jpoly1219/context-extractor.git
|
41
|
+
cd context-extractor
|
42
|
+
npm install
|
43
|
+
```
|
44
|
+
|
45
|
+
For OCaml support, you need to first go through the standard OCaml [setup](https://ocaml.org/docs/installing-ocaml).
|
46
|
+
|
47
|
+
Once that is done, you should be able to create a local switch in this repo.
|
48
|
+
|
49
|
+
```text
|
50
|
+
opam switch create ./
|
51
|
+
eval $(opam env)
|
52
|
+
```
|
53
|
+
|
54
|
+
After you activate the local switch, install the following dependencies:
|
55
|
+
|
56
|
+
<!-- TODO: Update dependencies. -->
|
57
|
+
|
58
|
+
```text
|
59
|
+
opam install dune ocaml-lsp-server ounit2
|
60
|
+
```
|
61
|
+
|
62
|
+
We provide you with five OCaml examples, located in `targets/ocaml` directory.
|
63
|
+
`cd` into each of them and run the following:
|
64
|
+
|
65
|
+
```text
|
66
|
+
dune build
|
67
|
+
```
|
68
|
+
|
69
|
+
Ignore the wildcard build errors. The command is meant to setup the modules and imports.
|
70
|
+
|
71
|
+
Almost there! Create a `credentials.json` file following the steps at the **credentials.json** section below in the README.
|
72
|
+
|
73
|
+
Finally, build and run.
|
74
|
+
|
75
|
+
```text
|
76
|
+
npm run build
|
77
|
+
node dist/runner.js
|
78
|
+
```
|
79
|
+
|
80
|
+
## How it works
|
81
|
+
|
82
|
+
`context-extractor` takes several steps to extract relevant types and headers:
|
83
|
+
|
84
|
+
1. Determine the type of the hole.
|
85
|
+
2. Extract relevant types.
|
86
|
+
3. Extract relevant headers.
|
87
|
+
|
88
|
+
This library exposes the API `extractWithNew`, which has the following definition:
|
89
|
+
|
90
|
+
```ts
|
91
|
+
const extractWithNew = async (
|
92
|
+
language: Language,
|
93
|
+
sketchPath: string,
|
94
|
+
credentialsPath: string
|
95
|
+
) => {};
|
96
|
+
|
97
|
+
enum Language {
|
98
|
+
TypeScript,
|
99
|
+
OCaml,
|
100
|
+
}
|
101
|
+
```
|
102
|
+
|
103
|
+
`sketchPath` is the full path to your `sketch.ts` or `sketch.ml` file.
|
104
|
+
`credentialsPath` is the full path to your `credentials.json`.
|
105
|
+
|
106
|
+
### credentials.json
|
107
|
+
|
108
|
+
The extractor calls OpenAI for code completion.
|
109
|
+
For this you need a `credentials.json` file that holds your specific OpenAI parameters.
|
110
|
+
|
111
|
+
The json has the following format:
|
112
|
+
|
113
|
+
<!-- TODO: This is probably difficult to understand. -->
|
114
|
+
|
115
|
+
```json
|
116
|
+
{
|
117
|
+
"apiBase": "<your-api-base-here>",
|
118
|
+
"deployment": "<your-deployment-here>",
|
119
|
+
"gptModel": "<your-gpt-model-here>",
|
120
|
+
"apiVersion": "<your-api-version-here>",
|
121
|
+
"apiKey": "<your-api-key-here>",
|
122
|
+
"temperature": 0.6
|
123
|
+
}
|
124
|
+
```
|
125
|
+
|
126
|
+
## Trying out the VSCode extension
|
127
|
+
|
128
|
+
We have a Visual Studio Code extension that provides a frontend to this project.
|
129
|
+
|
130
|
+
The extension is not publicly available, so you would need to request for a .vsix package.
|
package/package.json
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"name": "@jpoly1219/context-extractor",
|
3
|
+
"version": "0.1.1",
|
4
|
+
"description": "Extract relevant context from an incomplete program sketch.",
|
5
|
+
"repository": {
|
6
|
+
"type": "git",
|
7
|
+
"url": "https://github.com/jpoly1219/context-extractor.git"
|
8
|
+
},
|
9
|
+
"main": "dist/index.js",
|
10
|
+
"types": "dist/index.d.ts",
|
11
|
+
"files": [
|
12
|
+
"dist"
|
13
|
+
],
|
14
|
+
"scripts": {
|
15
|
+
"build": "npx tsc",
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
17
|
+
},
|
18
|
+
"author": "",
|
19
|
+
"license": "ISC",
|
20
|
+
"dependencies": {
|
21
|
+
"json-rpc-2.0": "^1.7.0",
|
22
|
+
"openai": "^4.30.0",
|
23
|
+
"pino": "^9.3.1",
|
24
|
+
"ts-node": "^10.9.2",
|
25
|
+
"tslib": "^2.6.3"
|
26
|
+
},
|
27
|
+
"devDependencies": {
|
28
|
+
"typescript": "^5.4.5"
|
29
|
+
}
|
30
|
+
}
|