@jpoly1219/context-extractor 0.1.1 → 0.2.0
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 +47 -13
- package/package.json +1 -1
package/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
Extract relevant context from a codebase using a type-directed approach.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### npm
|
6
8
|
|
7
9
|
Recommended.
|
8
10
|
|
@@ -10,7 +12,7 @@ Recommended.
|
|
10
12
|
npm i @jpoly1219/context-extractor
|
11
13
|
```
|
12
14
|
|
13
|
-
|
15
|
+
### Manual
|
14
16
|
|
15
17
|
Not recommended. If the above steps do not work, please leave a GitHub issue.
|
16
18
|
|
@@ -68,7 +70,7 @@ dune build
|
|
68
70
|
|
69
71
|
Ignore the wildcard build errors. The command is meant to setup the modules and imports.
|
70
72
|
|
71
|
-
Almost there! Create a `
|
73
|
+
Almost there! Create a `config.json` file following the steps at the **config.json** section below in the README.
|
72
74
|
|
73
75
|
Finally, build and run.
|
74
76
|
|
@@ -84,29 +86,50 @@ node dist/runner.js
|
|
84
86
|
1. Determine the type of the hole.
|
85
87
|
2. Extract relevant types.
|
86
88
|
3. Extract relevant headers.
|
89
|
+
4. Optionally complete the hole with an LLM.
|
87
90
|
|
88
|
-
This library exposes
|
91
|
+
This library exposes two methods `extractContext` and `completeWithLLM`, which have the following definitions:
|
89
92
|
|
90
93
|
```ts
|
91
|
-
const
|
94
|
+
const extractContext = async (
|
95
|
+
language: Language,
|
96
|
+
sketchPath: string,
|
97
|
+
repoPath: string,
|
98
|
+
): Promise<Context | null>;
|
99
|
+
|
100
|
+
const completeWithLLM = async (
|
101
|
+
ctx: Context,
|
92
102
|
language: Language,
|
93
103
|
sketchPath: string,
|
94
|
-
|
95
|
-
)
|
104
|
+
configPath: string
|
105
|
+
): Promise<string>;
|
96
106
|
|
97
107
|
enum Language {
|
98
108
|
TypeScript,
|
99
|
-
OCaml
|
109
|
+
OCaml
|
110
|
+
}
|
111
|
+
|
112
|
+
interface Context {
|
113
|
+
holeType: string,
|
114
|
+
relevantTypes: Map<Filepath, RelevantType[]>,
|
115
|
+
relevantHeaders: Map<Filepath, RelevantHeader[]>
|
100
116
|
}
|
117
|
+
|
118
|
+
type Filepath = string;
|
119
|
+
type RelevantType = string;
|
120
|
+
type RelevantHeader = string;
|
101
121
|
```
|
102
122
|
|
103
|
-
`sketchPath` is the full path to your
|
104
|
-
`
|
123
|
+
- `sketchPath` is the full path to your sketch file with the typed hole construct (`_()` for TypeScript, `_` for OCaml). This is NOT prefixed with `file://`.
|
124
|
+
- `repoPath` is the full path to your repository root.
|
125
|
+
- `configPath` is the full path to your `config.json`.
|
126
|
+
- `null` values will only be set if something goes wrong internally.
|
127
|
+
- `ctx` is the result from `extractContext`.
|
105
128
|
|
106
|
-
###
|
129
|
+
### config.json
|
107
130
|
|
108
131
|
The extractor calls OpenAI for code completion.
|
109
|
-
For this you need a `
|
132
|
+
For this you need a `config.json` file that holds your specific OpenAI parameters.
|
110
133
|
|
111
134
|
The json has the following format:
|
112
135
|
|
@@ -123,8 +146,19 @@ The json has the following format:
|
|
123
146
|
}
|
124
147
|
```
|
125
148
|
|
149
|
+
Internally, this is how the credentials are populated when creating a new OpenAI client.
|
150
|
+
|
151
|
+
```ts
|
152
|
+
const openai = new OpenAI({
|
153
|
+
apiKey,
|
154
|
+
baseURL: `${apiBase}/openai/deployments/${deployment}`,
|
155
|
+
defaultQuery: { "api-version": apiVersion },
|
156
|
+
defaultHeaders: { "api-key": apiKey }
|
157
|
+
})
|
158
|
+
```
|
159
|
+
|
126
160
|
## Trying out the VSCode extension
|
127
161
|
|
128
162
|
We have a Visual Studio Code extension that provides a frontend to this project.
|
129
163
|
|
130
|
-
The extension is not publicly available
|
164
|
+
The extension is not publicly available -- contact me at `jpoly@umich.edu` to request for a .vsix package.
|