You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library provides convenient access to the Groq REST API from server-side TypeScript or JavaScript.
6
6
@@ -9,9 +9,9 @@ The REST API documentation can be found [on console.groq.com](https://console.gr
9
9
## Installation
10
10
11
11
```sh
12
-
npm install --save groq
12
+
npm install --save groq-sdk
13
13
# or
14
-
yarn add groq
14
+
yarn add groq-sdk
15
15
```
16
16
17
17
## Usage
@@ -20,7 +20,7 @@ The full API of this library can be found in [api.md](api.md).
20
20
21
21
<!-- prettier-ignore -->
22
22
```js
23
-
importGroqfrom'groq';
23
+
importGroqfrom'groq-sdk';
24
24
25
25
constgroq=newGroq();
26
26
@@ -42,7 +42,7 @@ This library includes TypeScript definitions for all request params and response
42
42
43
43
<!-- prettier-ignore -->
44
44
```ts
45
-
importGroqfrom'groq';
45
+
importGroqfrom'groq-sdk';
46
46
47
47
const groq =newGroq();
48
48
@@ -196,19 +196,19 @@ add the following import before your first import `from "Groq"`:
196
196
```ts
197
197
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
198
198
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
199
-
import'groq/shims/web';
200
-
importGroqfrom'groq';
199
+
import'groq-sdk/shims/web';
200
+
importGroqfrom'groq-sdk';
201
201
```
202
202
203
-
To do the inverse, add `import "groq/shims/node"` (which does import polyfills).
203
+
To do the inverse, add `import "groq-sdk/shims/node"` (which does import polyfills).
204
204
This can also be useful if you are getting the wrong TypeScript types for `Response` - more details [here](https://github.com/groq/groq-node/tree/main/src/_shims#readme).
205
205
206
206
You may also provide a custom `fetch` function when instantiating the client,
207
207
which can be used to inspect or alter the `Request` or `Response` before/after each request:
`groq` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
3
+
`groq-sdk` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
4
4
edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM).
5
5
6
-
To do this, `groq` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.
6
+
To do this, `groq-sdk` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.
7
7
8
8
It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
9
9
automatically select the correct shims for each environment. However, conditional exports are a fairly new
@@ -15,32 +15,32 @@ getting the wrong raw `Response` type from `.asResponse()`, for example.
15
15
16
16
The user can work around these issues by manually importing one of:
17
17
18
-
-`import 'groq/shims/node'`
19
-
-`import 'groq/shims/web'`
18
+
-`import 'groq-sdk/shims/node'`
19
+
-`import 'groq-sdk/shims/web'`
20
20
21
21
All of the code here in `_shims` handles selecting the automatic default shims or manual overrides.
22
22
23
23
### How it works - Runtime
24
24
25
-
Runtime shims get installed by calling `setShims` exported by `groq/_shims/registry`.
25
+
Runtime shims get installed by calling `setShims` exported by `groq-sdk/_shims/registry`.
26
26
27
-
Manually importing `groq/shims/node` or `groq/shims/web`, calls `setShims` with the respective runtime shims.
27
+
Manually importing `groq-sdk/shims/node` or `groq-sdk/shims/web`, calls `setShims` with the respective runtime shims.
28
28
29
-
All client code imports shims from `groq/_shims/index`, which:
29
+
All client code imports shims from `groq-sdk/_shims/index`, which:
30
30
31
31
- checks if shims have been set manually
32
-
- if not, calls `setShims` with the shims from `groq/_shims/auto/runtime`
33
-
- re-exports the installed shims from `groq/_shims/registry`.
32
+
- if not, calls `setShims` with the shims from `groq-sdk/_shims/auto/runtime`
33
+
- re-exports the installed shims from `groq-sdk/_shims/registry`.
34
34
35
-
`groq/_shims/auto/runtime` exports web runtime shims.
36
-
If the `node` export condition is set, the export map replaces it with `groq/_shims/auto/runtime-node`.
35
+
`groq-sdk/_shims/auto/runtime` exports web runtime shims.
36
+
If the `node` export condition is set, the export map replaces it with `groq-sdk/_shims/auto/runtime-node`.
37
37
38
38
### How it works - Type time
39
39
40
-
All client code imports shim types from `groq/_shims/index`, which selects the manual types from `groq/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `groq/_shims/auto/types`.
40
+
All client code imports shim types from `groq-sdk/_shims/index`, which selects the manual types from `groq-sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `groq-sdk/_shims/auto/types`.
41
41
42
-
`groq/_shims/manual-types` exports an empty namespace.
43
-
Manually importing `groq/shims/node` or `groq/shims/web` merges declarations into this empty namespace, so they get picked up by `groq/_shims/index`.
42
+
`groq-sdk/_shims/manual-types` exports an empty namespace.
43
+
Manually importing `groq-sdk/shims/node` or `groq-sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `groq-sdk/_shims/index`.
44
44
45
-
`groq/_shims/auto/types` exports web type definitions.
46
-
If the `node` export condition is set, the export map replaces it with `groq/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
45
+
`groq-sdk/_shims/auto/types` exports web type definitions.
46
+
If the `node` export condition is set, the export map replaces it with `groq-sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
0 commit comments