Skip to content

Commit

Permalink
feat(api): delete messages (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed May 1, 2024
1 parent fb228dc commit 585bdd7
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 10 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,22 @@ jobs:
- name: Check types
run: |
yarn build
test:
name: test
runs-on: ubuntu-latest
if: github.repository == 'openai/openai-node'

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

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
yarn-error.log
codegen.log
Brewfile.lock.json
dist
/deno
/*.tgz
Expand Down
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 63
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-0839c14b2b61dad4e830884410cfc3695546682ced009e50583c8bb5c44512d7.yml
configured_endpoints: 64
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-97c9a5f089049dc9eb5cee9475558049003e37e42202cab39e59d75e08b4c613.yml
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew "node"
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ Methods:
- <code title="get /threads/{thread_id}/messages/{message_id}">client.beta.threads.messages.<a href="./src/resources/beta/threads/messages.ts">retrieve</a>(threadId, messageId) -> Message</code>
- <code title="post /threads/{thread_id}/messages/{message_id}">client.beta.threads.messages.<a href="./src/resources/beta/threads/messages.ts">update</a>(threadId, messageId, { ...params }) -> Message</code>
- <code title="get /threads/{thread_id}/messages">client.beta.threads.messages.<a href="./src/resources/beta/threads/messages.ts">list</a>(threadId, { ...params }) -> MessagesPage</code>
- <code title="delete /threads/{thread_id}/messages/{message_id}">client.beta.threads.messages.<a href="./src/resources/beta/threads/messages.ts">del</a>(threadId, messageId) -> MessageDeleted</code>

# Batches

Expand Down
9 changes: 9 additions & 0 deletions scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ 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
5 changes: 4 additions & 1 deletion scripts/mock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

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

if [ -n "$1" ]; then
if [[ -n "$1" && "$1" != '--'* ]]; then
URL="$1"
shift
else
Expand All @@ -17,11 +17,14 @@ if [ -z "$URL" ]; then
exit 1
fi

echo "==> Starting mock server with URL ${URL}"

# Run prism mock on the given spec
if [ "$1" == "--daemon" ]; then
npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock "$URL" &> .prism.log &

# Wait for server to come online
echo -n "Waiting for server"
while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
echo -n "."
sleep 0.1
Expand Down
10 changes: 7 additions & 3 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ if ! is_overriding_api_base_url && ! prism_is_running ; then
trap 'kill_server_on_port 4010' EXIT

# Start the dev server
./scripts/mock --daemon &> /dev/null
./scripts/mock --daemon
fi

if ! prism_is_running ; then
if is_overriding_api_base_url ; then
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}"
echo
elif ! prism_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
echo -e "spec to the prism command:"
echo
echo -e " \$ ${YELLOW}npm exec prism mock path/to/your.openapi.yml${NC}"
echo -e " \$ ${YELLOW}npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock path/to/your.openapi.yml${NC}"
echo

exit 1
Expand All @@ -50,4 +53,5 @@ else
fi

# Run tests
echo "==> Running tests"
./node_modules/.bin/jest
6 changes: 3 additions & 3 deletions src/resources/batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ export interface BatchCreateParams {
completion_window: '24h';

/**
* The endpoint to be used for all requests in the batch. Currently only
* `/v1/chat/completions` is supported.
* The endpoint to be used for all requests in the batch. Currently
* `/v1/chat/completions` and `/v1/embeddings` are supported.
*/
endpoint: '/v1/chat/completions';
endpoint: '/v1/chat/completions' | '/v1/embeddings';

/**
* The ID of an uploaded file that contains requests for the new batch.
Expand Down
10 changes: 10 additions & 0 deletions src/resources/beta/threads/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export class Messages extends APIResource {
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
});
}

/**
* Deletes a message.
*/
del(threadId: string, messageId: string, options?: Core.RequestOptions): Core.APIPromise<MessageDeleted> {
return this._client.delete(`/threads/${threadId}/messages/${messageId}`, {
...options,
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
});
}
}

export class MessagesPage extends CursorPage<Message> {}
Expand Down
6 changes: 6 additions & 0 deletions src/resources/fine-tuning/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ export interface FineTuningJob {
*/
validation_file: string | null;

/**
* The Unix timestamp (in seconds) for when the fine-tuning job is estimated to
* finish. The value will be null if the fine-tuning job is not running.
*/
estimated_finish?: number | null;

/**
* A list of integrations to enable for this fine-tuning job.
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/api-resources/beta/threads/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,22 @@ describe('resource messages', () => {
),
).rejects.toThrow(OpenAI.NotFoundError);
});

test('del', async () => {
const responsePromise = openai.beta.threads.messages.del('string', 'string');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('del: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
openai.beta.threads.messages.del('string', 'string', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(OpenAI.NotFoundError);
});
});

0 comments on commit 585bdd7

Please sign in to comment.