@jpoly1219/context-extractor 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/README.md +47 -13
  2. 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
- ## npm Installation
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
- ## Manual Installation
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 `credentials.json` file following the steps at the **credentials.json** section below in the README.
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 the API `extractWithNew`, which has the following definition:
91
+ This library exposes two methods `extractContext` and `completeWithLLM`, which have the following definitions:
89
92
 
90
93
  ```ts
91
- const extractWithNew = async (
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
- credentialsPath: string
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 `sketch.ts` or `sketch.ml` file.
104
- `credentialsPath` is the full path to your `credentials.json`.
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
- ### credentials.json
129
+ ### config.json
107
130
 
108
131
  The extractor calls OpenAI for code completion.
109
- For this you need a `credentials.json` file that holds your specific OpenAI parameters.
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, so you would need to request for a .vsix package.
164
+ The extension is not publicly available -- contact me at `jpoly@umich.edu` to request for a .vsix package.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jpoly1219/context-extractor",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Extract relevant context from an incomplete program sketch.",
5
5
  "repository": {
6
6
  "type": "git",