Skip to content

Commit

Permalink
chore(api): Internal SDK changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and gradenr committed May 22, 2024
1 parent 5de7753 commit e1a6688
Show file tree
Hide file tree
Showing 49 changed files with 398 additions and 244 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ RUN apt-get update && apt-get install -y \
yarnpkg \
&& apt-get clean autoclean

# Ensure UTF-8 encoding
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

# Yarn
RUN ln -sf /usr/bin/yarnpkg /usr/bin/yarn

Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,21 @@ jobs:
- name: Check types
run: |
yarn build
test:
name: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Bootstrap
run: ./scripts/bootstrap

- name: Run tests
run: ./scripts/test

2 changes: 1 addition & 1 deletion .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
if: github.repository == 'groq/groq-typescript' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Check release environment
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
node_modules
yarn-error.log
codegen.log
Brewfile.lock.json
dist
/deno
/*.tgz
.idea/

2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CHANGELOG.md
/ecosystem-tests
/ecosystem-tests/*/**
/node_modules
/deno

Expand Down
1 change: 1 addition & 0 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
configured_endpoints: 6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-0a3089666368ff1ff668f2a73ea3b40d8b20420d8403a18579a1168dd67f2220.yml
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew "node"
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pnpm link -—global groq-sdk
Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.

```bash
npx prism path/to/your/openapi.yml
npx prism mock path/to/your/openapi.yml
```

```bash
Expand Down
68 changes: 58 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This library provides convenient access to the Groq REST API from server-side Ty

The REST API documentation can be found [on console.groq.com](https://console.groq.com/docs). The full API of this library can be found in [api.md](api.md).

It is generated with [Stainless](https://www.stainlessapi.com/).

## Installation

```sh
Expand Down Expand Up @@ -47,7 +49,7 @@ const groq = new Groq();
async function main() {
const params: Groq.Chat.CompletionCreateParams = {
messages: [
{ role: 'system', content: 'You are a helpful assisstant.' },
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain the importance of low latency LLMs' },
],
model: 'mixtral-8x7b-32768',
Expand All @@ -72,7 +74,7 @@ async function main() {
const chatCompletion = await groq.chat.completions
.create({
messages: [
{ role: 'system', content: 'You are a helpful assisstant.' },
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain the importance of low latency LLMs' },
],
model: 'mixtral-8x7b-32768',
Expand Down Expand Up @@ -120,7 +122,7 @@ const groq = new Groq({
});

// Or, configure per-request:
await groq.chat.completions.create({ messages: [{ role: 'system', content: 'You are a helpful assisstant.' }, { role: 'user', content: 'Explain the importance of low latency LLMs' }], model: 'mixtral-8x7b-32768' }, {
await groq.chat.completions.create({ messages: [{ role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'Explain the importance of low latency LLMs' }], model: 'mixtral-8x7b-32768' }, {
maxRetries: 5,
});
```
Expand All @@ -137,7 +139,7 @@ const groq = new Groq({
});

// Override per-request:
await groq.chat.completions.create({ messages: [{ role: 'system', content: 'You are a helpful assisstant.' }, { role: 'user', content: 'Explain the importance of low latency LLMs' }], model: 'mixtral-8x7b-32768' }, {
await groq.chat.completions.create({ messages: [{ role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'Explain the importance of low latency LLMs' }], model: 'mixtral-8x7b-32768' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -161,7 +163,7 @@ const groq = new Groq();
const response = await groq.chat.completions
.create({
messages: [
{ role: 'system', content: 'You are a helpful assisstant.' },
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain the importance of low latency LLMs' },
],
model: 'mixtral-8x7b-32768',
Expand All @@ -173,7 +175,7 @@ console.log(response.statusText); // access the underlying Response object
const { data: chatCompletion, response: raw } = await groq.chat.completions
.create({
messages: [
{ role: 'system', content: 'You are a helpful assisstant.' },
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain the importance of low latency LLMs' },
],
model: 'mixtral-8x7b-32768',
Expand All @@ -183,7 +185,51 @@ console.log(raw.headers.get('X-My-Header'));
console.log(chatCompletion.id);
```

## Customizing the fetch client
### Making custom/undocumented requests

This library is typed for convenient access to the documented API. If you need to access undocumented
endpoints, params, or response properties, the library can still be used.

#### Undocumented endpoints

To make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.
Options on the client, such as retries, will be respected when making these requests.

```ts
await client.post('/some/path', {
body: { some_prop: 'foo' },
query: { some_query_arg: 'bar' },
});
```

#### Undocumented request params

To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
send will be sent as-is.

```ts
client.foo.create({
foo: 'my_param',
bar: 12,
// @ts-expect-error baz is not yet public
baz: 'undocumented option',
});
```

For requests with the `GET` verb, any extra params will be in the query, all other requests will send the
extra param in the body.

If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
options.

#### Undocumented response properties

To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
the response object, or cast the response object to the requisite type. Like the request params, we do not
validate or strip extra properties from the response from the API.

### Customizing the fetch client

By default, this library uses `node-fetch` in Node, and expects a global `fetch` function in other environments.

Expand All @@ -201,6 +247,8 @@ import Groq from 'groq-sdk';
To do the inverse, add `import "groq-sdk/shims/node"` (which does import polyfills).
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/groq/groq-typescript/tree/main/src/_shims#readme)).

### Logging and middleware

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

Expand All @@ -221,7 +269,7 @@ const client = new Groq({
Note that if given a `DEBUG=true` environment variable, this library will log all requests and responses automatically.
This is intended for debugging purposes only and may change in the future without notice.

## Configuring an HTTP(S) Agent (e.g., for proxies)
### Configuring an HTTP(S) Agent (e.g., for proxies)

By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.

Expand All @@ -241,7 +289,7 @@ const groq = new Groq({
await groq.chat.completions.create(
{
messages: [
{ role: 'system', content: 'You are a helpful assisstant.' },
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain the importance of low latency LLMs' },
],
model: 'mixtral-8x7b-32768',
Expand All @@ -252,7 +300,7 @@ await groq.chat.completions.create(
);
```

## Semantic Versioning
## Semantic versioning

This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:

Expand Down
27 changes: 27 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Security Policy

## Reporting Security Issues

This SDK is generated by [Stainless Software Inc](http://stainlessapi.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.

To report a security issue, please contact the Stainless team at [email protected].

## Responsible Disclosure

We appreciate the efforts of security researchers and individuals who help us maintain the security of
SDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible
disclosure practices by allowing us a reasonable amount of time to investigate and address the issue
before making any information public.

## Reporting Non-SDK Related Security Issues

If you encounter security issues that are not directly related to SDKs but pertain to the services
or products provided by Groq please follow the respective company's security reporting guidelines.

### Groq Terms and Policies

Please contact [email protected] for any questions or concerns regarding security of our services.

---

Thank you for helping us keep the SDKs and systems they interact with secure.
50 changes: 0 additions & 50 deletions bin/check-test-server

This file was deleted.

4 changes: 4 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { JestConfigWithTsJest } from 'ts-jest';
const config: JestConfigWithTsJest = {
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }],
},
moduleNameMapper: {
'^groq-sdk$': '<rootDir>/src/index.ts',
'^groq-sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
Expand All @@ -14,6 +17,7 @@ const config: JestConfigWithTsJest = {
'<rootDir>/deno/',
'<rootDir>/deno_tests/',
],
testPathIgnorePatterns: ['scripts'],
};

export default config;
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,35 @@
"type": "commonjs",
"repository": "github:groq/groq-typescript",
"license": "Apache-2.0",
"packageManager": "[email protected].21",
"packageManager": "[email protected].22",
"files": [
"*"
],
"private": false,
"scripts": {
"test": "bin/check-test-server && yarn jest",
"build": "bash ./build",
"test": "./scripts/test",
"build": "./scripts/build",
"prepack": "echo 'to pack, run yarn build && (cd dist; yarn pack)' && exit 1",
"prepublishOnly": "echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1",
"format": "prettier --write --cache --cache-strategy metadata . !dist",
"prepare": "if ./scripts/check-is-in-git-install.sh; then npm run build; fi",
"prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build; fi",
"tsn": "ts-node -r tsconfig-paths/register",
"lint": "eslint --ext ts,js .",
"lint": "./scripts/lint",
"fix": "eslint --fix --ext ts,js ."
},
"dependencies": {
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.4",
"abort-controller": "^3.0.0",
"agentkeepalive": "^4.2.1",
"digest-fetch": "^1.3.0",
"form-data-encoder": "1.7.2",
"formdata-node": "^4.3.2",
"node-fetch": "^2.6.7",
"web-streams-polyfill": "^3.2.1"
},
"devDependencies": {
"@swc/core": "^1.3.102",
"@swc/jest": "^0.2.29",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
Expand Down
18 changes: 18 additions & 0 deletions scripts/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
brew bundle check >/dev/null 2>&1 || {
echo "==> Installing Homebrew dependencies…"
brew bundle
}
fi

echo "==> Installing Node dependencies…"

PACKAGE_MANAGER=$(command -v yarn >/dev/null 2>&1 && echo "yarn" || echo "npm")

$PACKAGE_MANAGER install
Loading

0 comments on commit e1a6688

Please sign in to comment.