Skip to content

Commit 585bdd7

Browse files
committed
feat(api): delete messages (#811)
1 parent fb228dc commit 585bdd7

File tree

12 files changed

+80
-10
lines changed

12 files changed

+80
-10
lines changed

.github/workflows/ci.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,22 @@ jobs:
2828
- name: Check types
2929
run: |
3030
yarn build
31+
test:
32+
name: test
33+
runs-on: ubuntu-latest
34+
if: github.repository == 'openai/openai-node'
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Set up Node
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: '18'
43+
44+
- name: Bootstrap
45+
run: ./scripts/bootstrap
46+
47+
- name: Run tests
48+
run: ./scripts/test
3149

32-

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
yarn-error.log
33
codegen.log
4+
Brewfile.lock.json
45
dist
56
/deno
67
/*.tgz

.stats.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 63
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-0839c14b2b61dad4e830884410cfc3695546682ced009e50583c8bb5c44512d7.yml
1+
configured_endpoints: 64
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-97c9a5f089049dc9eb5cee9475558049003e37e42202cab39e59d75e08b4c613.yml

Brewfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
brew "node"

api.md

+1
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ Methods:
365365
- <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>
366366
- <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>
367367
- <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>
368+
- <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>
368369

369370
# Batches
370371

scripts/bootstrap

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ set -e
44

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

7+
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
8+
brew bundle check >/dev/null 2>&1 || {
9+
echo "==> Installing Homebrew dependencies…"
10+
brew bundle
11+
}
12+
fi
13+
14+
echo "==> Installing Node dependencies…"
15+
716
PACKAGE_MANAGER=$(command -v yarn >/dev/null 2>&1 && echo "yarn" || echo "npm")
817

918
$PACKAGE_MANAGER install

scripts/mock

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

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

7-
if [ -n "$1" ]; then
7+
if [[ -n "$1" && "$1" != '--'* ]]; then
88
URL="$1"
99
shift
1010
else
@@ -17,11 +17,14 @@ if [ -z "$URL" ]; then
1717
exit 1
1818
fi
1919

20+
echo "==> Starting mock server with URL ${URL}"
21+
2022
# Run prism mock on the given spec
2123
if [ "$1" == "--daemon" ]; then
2224
npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock "$URL" &> .prism.log &
2325

2426
# Wait for server to come online
27+
echo -n "Waiting for server"
2528
while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
2629
echo -n "."
2730
sleep 0.1

scripts/test

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,20 @@ if ! is_overriding_api_base_url && ! prism_is_running ; then
3030
trap 'kill_server_on_port 4010' EXIT
3131

3232
# Start the dev server
33-
./scripts/mock --daemon &> /dev/null
33+
./scripts/mock --daemon
3434
fi
3535

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

4649
exit 1
@@ -50,4 +53,5 @@ else
5053
fi
5154

5255
# Run tests
56+
echo "==> Running tests"
5357
./node_modules/.bin/jest

src/resources/batches.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ export interface BatchCreateParams {
214214
completion_window: '24h';
215215

216216
/**
217-
* The endpoint to be used for all requests in the batch. Currently only
218-
* `/v1/chat/completions` is supported.
217+
* The endpoint to be used for all requests in the batch. Currently
218+
* `/v1/chat/completions` and `/v1/embeddings` are supported.
219219
*/
220-
endpoint: '/v1/chat/completions';
220+
endpoint: '/v1/chat/completions' | '/v1/embeddings';
221221

222222
/**
223223
* The ID of an uploaded file that contains requests for the new batch.

src/resources/beta/threads/messages.ts

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ export class Messages extends APIResource {
7272
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
7373
});
7474
}
75+
76+
/**
77+
* Deletes a message.
78+
*/
79+
del(threadId: string, messageId: string, options?: Core.RequestOptions): Core.APIPromise<MessageDeleted> {
80+
return this._client.delete(`/threads/${threadId}/messages/${messageId}`, {
81+
...options,
82+
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
83+
});
84+
}
7585
}
7686

7787
export class MessagesPage extends CursorPage<Message> {}

src/resources/fine-tuning/jobs/jobs.ts

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ export interface FineTuningJob {
180180
*/
181181
validation_file: string | null;
182182

183+
/**
184+
* The Unix timestamp (in seconds) for when the fine-tuning job is estimated to
185+
* finish. The value will be null if the fine-tuning job is not running.
186+
*/
187+
estimated_finish?: number | null;
188+
183189
/**
184190
* A list of integrations to enable for this fine-tuning job.
185191
*/

tests/api-resources/beta/threads/messages.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,22 @@ describe('resource messages', () => {
9999
),
100100
).rejects.toThrow(OpenAI.NotFoundError);
101101
});
102+
103+
test('del', async () => {
104+
const responsePromise = openai.beta.threads.messages.del('string', 'string');
105+
const rawResponse = await responsePromise.asResponse();
106+
expect(rawResponse).toBeInstanceOf(Response);
107+
const response = await responsePromise;
108+
expect(response).not.toBeInstanceOf(Response);
109+
const dataAndResponse = await responsePromise.withResponse();
110+
expect(dataAndResponse.data).toBe(response);
111+
expect(dataAndResponse.response).toBe(rawResponse);
112+
});
113+
114+
test('del: request options instead of params are passed correctly', async () => {
115+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
116+
await expect(
117+
openai.beta.threads.messages.del('string', 'string', { path: '/_stainless_unknown_path' }),
118+
).rejects.toThrow(OpenAI.NotFoundError);
119+
});
102120
});

0 commit comments

Comments
 (0)