Skip to content

Commit c99373c

Browse files
feat: update via SDK Studio (#3)
1 parent 08d2551 commit c99373c

31 files changed

+155
-198
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ cd groq-node
5555
# With yarn
5656
yarn link
5757
cd ../my-package
58-
yarn link groq
58+
yarn link groq-sdk
5959

6060
# With pnpm
6161
pnpm link --global
6262
cd ../my-package
63-
pnpm link -—global groq
63+
pnpm link -—global groq-sdk
6464
```
6565

6666
## Running tests

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Groq Node API Library
22

3-
[![NPM version](https://img.shields.io/npm/v/groq.svg)](https://npmjs.org/package/groq)
3+
[![NPM version](https://img.shields.io/npm/v/groq-sdk.svg)](https://npmjs.org/package/groq-sdk)
44

55
This library provides convenient access to the Groq REST API from server-side TypeScript or JavaScript.
66

@@ -9,9 +9,9 @@ The REST API documentation can be found [on console.groq.com](https://console.gr
99
## Installation
1010

1111
```sh
12-
npm install --save groq
12+
npm install --save groq-sdk
1313
# or
14-
yarn add groq
14+
yarn add groq-sdk
1515
```
1616

1717
## Usage
@@ -20,7 +20,7 @@ The full API of this library can be found in [api.md](api.md).
2020

2121
<!-- prettier-ignore -->
2222
```js
23-
import Groq from 'groq';
23+
import Groq from 'groq-sdk';
2424

2525
const groq = new Groq();
2626

@@ -42,7 +42,7 @@ This library includes TypeScript definitions for all request params and response
4242

4343
<!-- prettier-ignore -->
4444
```ts
45-
import Groq from 'groq';
45+
import Groq from 'groq-sdk';
4646

4747
const groq = new Groq();
4848

@@ -196,19 +196,19 @@ add the following import before your first import `from "Groq"`:
196196
```ts
197197
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
198198
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
199-
import 'groq/shims/web';
200-
import Groq from 'groq';
199+
import 'groq-sdk/shims/web';
200+
import Groq from 'groq-sdk';
201201
```
202202

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).
204204
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).
205205

206206
You may also provide a custom `fetch` function when instantiating the client,
207207
which can be used to inspect or alter the `Request` or `Response` before/after each request:
208208

209209
```ts
210210
import { fetch } from 'undici'; // as one example
211-
import Groq from 'groq';
211+
import Groq from 'groq-sdk';
212212

213213
const client = new Groq({
214214
fetch: async (url: RequestInfo, init?: RequestInfo): Promise<Response> => {
@@ -265,7 +265,7 @@ TypeScript >= 4.5 is supported.
265265
The following runtimes are supported:
266266

267267
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
268-
- Deno v1.28.0 or higher, using `import Groq from "npm:groq"`.
268+
- Deno v1.28.0 or higher, using `import Groq from "npm:groq-sdk"`.
269269
- Bun 1.0 or later.
270270
- Cloudflare Workers.
271271
- Vercel Edge Runtime.

build

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node scripts/check-version.cjs
55

66
# Build into dist and will publish the package from there,
77
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
8-
# This way importing from `"groq/resources/foo"` works
8+
# This way importing from `"groq-sdk/resources/foo"` works
99
# even with `"moduleResolution": "node"`
1010

1111
rm -rf dist; mkdir dist
@@ -44,8 +44,8 @@ node scripts/postprocess-files.cjs
4444

4545
# make sure that nothing crashes when we require the output CJS or
4646
# import the output ESM
47-
(cd dist && node -e 'require("groq")')
48-
(cd dist && node -e 'import("groq")' --input-type=module)
47+
(cd dist && node -e 'require("groq-sdk")')
48+
(cd dist && node -e 'import("groq-sdk")' --input-type=module)
4949

5050
if command -v deno &> /dev/null && [ -e ./build-deno ]
5151
then

examples/chat_completion.js

+52-50
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,58 @@ const Groq = require('groq');
33
const groq = new Groq();
44

55
async function main() {
6-
groq.chat.completions.create({
7-
//
8-
// Required parameters
9-
//
10-
messages: [
11-
// Set an optional system message. This sets the behavior of the
12-
// assistant and can be used to provide specific instructions for
13-
// how it should behave throughout the conversation.
14-
{
15-
"role": "system",
16-
"content": "you are a helpful assistant."
17-
},
18-
// Set a user message for the assistant to respond to.
19-
{
20-
"role": "user",
21-
"content": "Explain the importance of low latency LLMs",
22-
}
23-
],
24-
25-
// The language model which will generate the completion.
26-
model: "mixtral-8x7b-32768",
27-
28-
//
29-
// Optional parameters
30-
//
31-
32-
// Controls randomness: lowering results in less random completions.
33-
// As the temperature approaches zero, the model will become deterministic
34-
// and repetitive.
35-
temperature: 0.5,
36-
37-
// The maximum number of tokens to generate. Requests can use up to
38-
// 2048 tokens shared between prompt and completion.
39-
max_tokens: 1024,
40-
41-
// Controls diversity via nucleus sampling: 0.5 means half of all
42-
// likelihood-weighted options are considered.
43-
top_p: 1,
44-
45-
// A stop sequence is a predefined or user-specified text string that
46-
// signals an AI to stop generating content, ensuring its responses
47-
// remain focused and concise. Examples include punctuation marks and
48-
// markers like "[end]".
49-
stop: null,
50-
51-
// If set, partial message deltas will be sent.
52-
stream: false,
53-
}).then((chatCompletion) => {
54-
process.stdout.write(chatCompletion.choices[0]?.message?.content || '');
55-
})
6+
groq.chat.completions
7+
.create({
8+
//
9+
// Required parameters
10+
//
11+
messages: [
12+
// Set an optional system message. This sets the behavior of the
13+
// assistant and can be used to provide specific instructions for
14+
// how it should behave throughout the conversation.
15+
{
16+
role: 'system',
17+
content: 'you are a helpful assistant.',
18+
},
19+
// Set a user message for the assistant to respond to.
20+
{
21+
role: 'user',
22+
content: 'Explain the importance of low latency LLMs',
23+
},
24+
],
25+
26+
// The language model which will generate the completion.
27+
model: 'mixtral-8x7b-32768',
28+
29+
//
30+
// Optional parameters
31+
//
32+
33+
// Controls randomness: lowering results in less random completions.
34+
// As the temperature approaches zero, the model will become deterministic
35+
// and repetitive.
36+
temperature: 0.5,
37+
38+
// The maximum number of tokens to generate. Requests can use up to
39+
// 2048 tokens shared between prompt and completion.
40+
max_tokens: 1024,
41+
42+
// Controls diversity via nucleus sampling: 0.5 means half of all
43+
// likelihood-weighted options are considered.
44+
top_p: 1,
45+
46+
// A stop sequence is a predefined or user-specified text string that
47+
// signals an AI to stop generating content, ensuring its responses
48+
// remain focused and concise. Examples include punctuation marks and
49+
// markers like "[end]".
50+
stop: null,
51+
52+
// If set, partial message deltas will be sent.
53+
stream: false,
54+
})
55+
.then((chatCompletion) => {
56+
process.stdout.write(chatCompletion.choices[0]?.message?.content || '');
57+
});
5658
}
5759

5860
main();

examples/chat_completion_stop.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ async function main() {
1212
// assistant and can be used to provide specific instructions for
1313
// how it should behave throughout the conversation.
1414
{
15-
"role": "system",
16-
"content": "you are a helpful assistant."
15+
role: 'system',
16+
content: 'you are a helpful assistant.',
1717
},
1818
// Set a user message for the assistant to respond to.
1919
{
20-
"role": "user",
21-
"content": "Start at 1 and count to 10. Separate each number with a comma and a space"
22-
}
20+
role: 'user',
21+
content: 'Start at 1 and count to 10. Separate each number with a comma and a space',
22+
},
2323
],
2424

2525
// The language model which will generate the completion.
26-
model: "mixtral-8x7b-32768",
26+
model: 'mixtral-8x7b-32768',
2727

2828
//
2929
// Optional parameters
@@ -50,7 +50,7 @@ async function main() {
5050
// For this example, we will use ", 6" so that the llm stops counting at 5.
5151
// If multiple stop values are needed, an array of string may be passed,
5252
// stop: [", 6", ", six", ", Six"]
53-
stop: ", 6",
53+
stop: ', 6',
5454

5555
// If set, partial message deltas will be sent.
5656
stream: true,

examples/chat_completion_streaming.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ async function main() {
1212
// assistant and can be used to provide specific instructions for
1313
// how it should behave throughout the conversation.
1414
{
15-
"role": "system",
16-
"content": "you are a helpful assistant."
15+
role: 'system',
16+
content: 'you are a helpful assistant.',
1717
},
1818
// Set a user message for the assistant to respond to.
1919
{
20-
"role": "user",
21-
"content": "Explain the importance of low latency LLMs",
22-
}
20+
role: 'user',
21+
content: 'Explain the importance of low latency LLMs',
22+
},
2323
],
2424

2525
// The language model which will generate the completion.
26-
model: "mixtral-8x7b-32768",
26+
model: 'mixtral-8x7b-32768',
2727

2828
//
2929
// Optional parameters

jest.config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const config: JestConfigWithTsJest = {
44
preset: 'ts-jest/presets/default-esm',
55
testEnvironment: 'node',
66
moduleNameMapper: {
7-
'^groq$': '<rootDir>/src/index.ts',
8-
'^groq/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
9-
'^groq/(.*)$': '<rootDir>/src/$1',
7+
'^groq-sdk$': '<rootDir>/src/index.ts',
8+
'^groq-sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
9+
'^groq-sdk/(.*)$': '<rootDir>/src/$1',
1010
},
1111
modulePathIgnorePatterns: [
1212
'<rootDir>/ecosystem-tests/',

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "groq",
2+
"name": "groq-sdk",
33
"version": "0.1.0",
44
"description": "The official TypeScript library for the Groq API",
55
"author": "Groq <[email protected]>",
@@ -60,8 +60,8 @@
6060
"./shims/web.mjs"
6161
],
6262
"imports": {
63-
"groq": ".",
64-
"groq/*": "./src/*"
63+
"groq-sdk": ".",
64+
"groq-sdk/*": "./src/*"
6565
},
6666
"exports": {
6767
"./_shims/auto/*": {

scripts/postprocess-files.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const path = require('path');
33
const { parse } = require('@typescript-eslint/parser');
44

5-
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'groq/'
5+
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'groq-sdk/'
66

77
const distDir =
88
process.env['DIST_PATH'] ?
@@ -142,7 +142,7 @@ async function postprocess() {
142142

143143
if (file.endsWith('.d.ts')) {
144144
// work around bad tsc behavior
145-
// if we have `import { type Readable } from 'groq/_shims/index'`,
145+
// if we have `import { type Readable } from 'groq-sdk/_shims/index'`,
146146
// tsc sometimes replaces `Readable` with `import("stream").Readable` inline
147147
// in the output .d.ts
148148
transformed = transformed.replace(/import\("stream"\).Readable/g, 'Readable');

src/_shims/README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 👋 Wondering what everything in here does?
22

3-
`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
44
edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM).
55

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.
77

88
It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
99
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.
1515

1616
The user can work around these issues by manually importing one of:
1717

18-
- `import 'groq/shims/node'`
19-
- `import 'groq/shims/web'`
18+
- `import 'groq-sdk/shims/node'`
19+
- `import 'groq-sdk/shims/web'`
2020

2121
All of the code here in `_shims` handles selecting the automatic default shims or manual overrides.
2222

2323
### How it works - Runtime
2424

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`.
2626

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.
2828

29-
All client code imports shims from `groq/_shims/index`, which:
29+
All client code imports shims from `groq-sdk/_shims/index`, which:
3030

3131
- 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`.
3434

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`.
3737

3838
### How it works - Type time
3939

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`.
4141

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`.
4444

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"`.

src/_shims/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
33
*/
44
import { manual } from './manual-types';
5-
import * as auto from 'groq/_shims/auto/types';
5+
import * as auto from 'groq-sdk/_shims/auto/types';
66
import { type RequestOptions } from '../core';
77

88
type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;

src/_shims/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
33
*/
44
const shims = require('./registry');
5-
const auto = require('groq/_shims/auto/runtime');
5+
const auto = require('groq-sdk/_shims/auto/runtime');
66
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
77
for (const property of Object.keys(shims)) {
88
Object.defineProperty(exports, property, {

0 commit comments

Comments
 (0)