Debian Codegraph @

src/anthropic/resources/beta/skills/skills.py

raw
1 from __future__ import annotations
2
3 from typing import List, Mapping, Optional, cast
4
5 import httpx2
6
7 from .versions import (
8 Versions,
9 AsyncVersions,
10 VersionsWithRawResponse,
11 AsyncVersionsWithRawResponse,
12 VersionsWithStreamingResponse,
13 AsyncVersionsWithStreamingResponse,
14 )
15 from ...._files import deepcopy_with_paths
16 from ...._types import (
17 Body,
18 Omit,
19 Query,
20 Headers,
21 NotGiven,
22 FileTypes,
23 SequenceNotStr,
24 omit,
25 not_given,
26 )
27 from ...._utils import is_given, extract_files, path_template, strip_not_given
28 from ...._compat import cached_property
29 from ...._resource import SyncAPIResource, AsyncAPIResource
30 from ...._response import (
31 to_raw_response_wrapper,
32 to_streamed_response_wrapper,
33 async_to_raw_response_wrapper,
34 async_to_streamed_response_wrapper,
35 )
36 from ....pagination import SyncPageCursor, AsyncPageCursor
37 from ...._base_client import AsyncPaginator, make_request_options
38 from ....types.beta.beta_skill import BetaSkill
39 from ....types.anthropic_beta_param import AnthropicBetaParam
40 from ....types.beta.beta_deleted_skill import BetaDeletedSkill
41
42 __all__ = ["Skills", "AsyncSkills"]
43
44
45 class Skills(SyncAPIResource):
46 @cached_property
47 def versions(self) -> Versions:
48 return Versions(self._client)
49
50 @cached_property
51 def with_raw_response(self) -> SkillsWithRawResponse:
52 """
53 This property can be used as a prefix for any HTTP method call to return
54 the raw response object instead of the parsed content.
55
56 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
57 """
58 return SkillsWithRawResponse(self)
59
60 @cached_property
61 def with_streaming_response(self) -> SkillsWithStreamingResponse:
62 """
63 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
64
65 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
66 """
67 return SkillsWithStreamingResponse(self)
68
69 def create(
70 self,
71 *,
72 files: SequenceNotStr[FileTypes],
73 display_name: Optional[str] | Omit = omit,
74 betas: List[AnthropicBetaParam] | Omit = omit,
75 workspace_id: str | Omit = omit,
76 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
77 # The extra values given here take precedence over values defined on the client or passed to this method.
78 extra_headers: Headers | None = None,
79 extra_query: Query | None = None,
80 extra_body: Body | None = None,
81 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
82 ) -> BetaSkill:
83 """
84 Create Skill
85
86 Args:
87 files: Files to upload for the skill.
88
89 All files must be in the same top-level directory and must include a SKILL.md
90 file at the root of that directory.
91
92 display_name: Human-readable, single-line label for the Skill. Maximum 255 characters. Always
93 set: derived from the SKILL.md frontmatter `name` when omitted at creation. Not
94 unique.
95
96 betas: Optional header to specify the beta version(s) you want to use.
97
98 workspace_id: Optional header to select the Workspace for this request. The value is a
99 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
100
101 Only needed for credentials that can act on more than one Workspace. A
102 credential that belongs to a specific Workspace may omit it; if sent, it must
103 match that Workspace.
104
105 extra_headers: Send extra headers
106
107 extra_query: Add additional query parameters to the request
108
109 extra_body: Add additional JSON properties to the request
110
111 timeout: Override the client-level default timeout for this request, in seconds
112 """
113 extra_headers = {
114 **strip_not_given(
115 {
116 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
117 "anthropic-workspace-id": workspace_id,
118 }
119 ),
120 **(extra_headers or {}),
121 }
122 body = deepcopy_with_paths(
123 {
124 "files": files,
125 "display_name": display_name,
126 },
127 [["files", "<array>"]],
128 )
129 extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
130 # It should be noted that the actual Content-Type header that will be
131 # sent to the server will contain a `boundary` parameter, e.g.
132 # multipart/form-data; boundary=---abc--
133 extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
134 return self._post(
135 "/v1/skills?beta=true",
136 body=body,
137 files=extracted_files,
138 options=make_request_options(
139 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
140 ),
141 cast_to=BetaSkill,
142 )
143
144 def retrieve(
145 self,
146 skill_id: str,
147 *,
148 betas: List[AnthropicBetaParam] | Omit = omit,
149 workspace_id: str | Omit = omit,
150 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
151 # The extra values given here take precedence over values defined on the client or passed to this method.
152 extra_headers: Headers | None = None,
153 extra_query: Query | None = None,
154 extra_body: Body | None = None,
155 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
156 ) -> BetaSkill:
157 """
158 Get Skill
159
160 Args:
161 skill_id: Unique identifier for the skill.
162
163 The format and length of IDs may change over time.
164
165 betas: Optional header to specify the beta version(s) you want to use.
166
167 workspace_id: Optional header to select the Workspace for this request. The value is a
168 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
169
170 Only needed for credentials that can act on more than one Workspace. A
171 credential that belongs to a specific Workspace may omit it; if sent, it must
172 match that Workspace.
173
174 extra_headers: Send extra headers
175
176 extra_query: Add additional query parameters to the request
177
178 extra_body: Add additional JSON properties to the request
179
180 timeout: Override the client-level default timeout for this request, in seconds
181 """
182 if not skill_id:
183 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
184 extra_headers = {
185 **strip_not_given(
186 {
187 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
188 "anthropic-workspace-id": workspace_id,
189 }
190 ),
191 **(extra_headers or {}),
192 }
193 return self._get(
194 path_template("/v1/skills/{skill_id}?beta=true", skill_id=skill_id),
195 options=make_request_options(
196 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
197 ),
198 cast_to=BetaSkill,
199 )
200
201 def list(
202 self,
203 *,
204 limit: int | Omit = omit,
205 page: Optional[str] | Omit = omit,
206 source: Optional[str] | Omit = omit,
207 betas: List[AnthropicBetaParam] | Omit = omit,
208 workspace_id: str | Omit = omit,
209 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
210 # The extra values given here take precedence over values defined on the client or passed to this method.
211 extra_headers: Headers | None = None,
212 extra_query: Query | None = None,
213 extra_body: Body | None = None,
214 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
215 ) -> SyncPageCursor[BetaSkill]:
216 """
217 List Skills
218
219 Args:
220 limit: Number of results to return per page.
221
222 Ranges from `1` to `1000`. Defaults to `20`.
223
224 page: Pagination token for fetching a specific page of results.
225
226 Pass the value from a previous response's `next_page` field to get the next page
227 of results.
228
229 source: Filter skills by source.
230
231 If provided, only skills from the specified source will be returned:
232
233 - `"custom"`: only return user-created skills
234 - `"anthropic"`: only return Anthropic-created skills
235
236 betas: Optional header to specify the beta version(s) you want to use.
237
238 workspace_id: Optional header to select the Workspace for this request. The value is a
239 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
240
241 Only needed for credentials that can act on more than one Workspace. A
242 credential that belongs to a specific Workspace may omit it; if sent, it must
243 match that Workspace.
244
245 extra_headers: Send extra headers
246
247 extra_query: Add additional query parameters to the request
248
249 extra_body: Add additional JSON properties to the request
250
251 timeout: Override the client-level default timeout for this request, in seconds
252 """
253 extra_headers = {
254 **strip_not_given(
255 {
256 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
257 "anthropic-workspace-id": workspace_id,
258 }
259 ),
260 **(extra_headers or {}),
261 }
262 return self._get_api_list(
263 "/v1/skills?beta=true",
264 page=SyncPageCursor[BetaSkill],
265 options=make_request_options(
266 extra_headers=extra_headers,
267 extra_query=extra_query,
268 extra_body=extra_body,
269 timeout=timeout,
270 query={
271 "limit": limit,
272 "page": page,
273 "source": source,
274 },
275 ),
276 model=BetaSkill,
277 )
278
279 def delete(
280 self,
281 skill_id: str,
282 *,
283 betas: List[AnthropicBetaParam] | Omit = omit,
284 workspace_id: str | Omit = omit,
285 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
286 # The extra values given here take precedence over values defined on the client or passed to this method.
287 extra_headers: Headers | None = None,
288 extra_query: Query | None = None,
289 extra_body: Body | None = None,
290 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
291 ) -> BetaDeletedSkill:
292 """
293 Delete Skill
294
295 Args:
296 skill_id: Unique identifier for the skill.
297
298 The format and length of IDs may change over time.
299
300 betas: Optional header to specify the beta version(s) you want to use.
301
302 workspace_id: Optional header to select the Workspace for this request. The value is a
303 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
304
305 Only needed for credentials that can act on more than one Workspace. A
306 credential that belongs to a specific Workspace may omit it; if sent, it must
307 match that Workspace.
308
309 extra_headers: Send extra headers
310
311 extra_query: Add additional query parameters to the request
312
313 extra_body: Add additional JSON properties to the request
314
315 timeout: Override the client-level default timeout for this request, in seconds
316 """
317 if not skill_id:
318 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
319 extra_headers = {
320 **strip_not_given(
321 {
322 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
323 "anthropic-workspace-id": workspace_id,
324 }
325 ),
326 **(extra_headers or {}),
327 }
328 return self._delete(
329 path_template("/v1/skills/{skill_id}?beta=true", skill_id=skill_id),
330 options=make_request_options(
331 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
332 ),
333 cast_to=BetaDeletedSkill,
334 )
335
336
337 class AsyncSkills(AsyncAPIResource):
338 @cached_property
339 def versions(self) -> AsyncVersions:
340 return AsyncVersions(self._client)
341
342 @cached_property
343 def with_raw_response(self) -> AsyncSkillsWithRawResponse:
344 """
345 This property can be used as a prefix for any HTTP method call to return
346 the raw response object instead of the parsed content.
347
348 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
349 """
350 return AsyncSkillsWithRawResponse(self)
351
352 @cached_property
353 def with_streaming_response(self) -> AsyncSkillsWithStreamingResponse:
354 """
355 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
356
357 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
358 """
359 return AsyncSkillsWithStreamingResponse(self)
360
361 async def create(
362 self,
363 *,
364 files: SequenceNotStr[FileTypes],
365 display_name: Optional[str] | Omit = omit,
366 betas: List[AnthropicBetaParam] | Omit = omit,
367 workspace_id: str | Omit = omit,
368 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
369 # The extra values given here take precedence over values defined on the client or passed to this method.
370 extra_headers: Headers | None = None,
371 extra_query: Query | None = None,
372 extra_body: Body | None = None,
373 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
374 ) -> BetaSkill:
375 """
376 Create Skill
377
378 Args:
379 files: Files to upload for the skill.
380
381 All files must be in the same top-level directory and must include a SKILL.md
382 file at the root of that directory.
383
384 display_name: Human-readable, single-line label for the Skill. Maximum 255 characters. Always
385 set: derived from the SKILL.md frontmatter `name` when omitted at creation. Not
386 unique.
387
388 betas: Optional header to specify the beta version(s) you want to use.
389
390 workspace_id: Optional header to select the Workspace for this request. The value is a
391 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
392
393 Only needed for credentials that can act on more than one Workspace. A
394 credential that belongs to a specific Workspace may omit it; if sent, it must
395 match that Workspace.
396
397 extra_headers: Send extra headers
398
399 extra_query: Add additional query parameters to the request
400
401 extra_body: Add additional JSON properties to the request
402
403 timeout: Override the client-level default timeout for this request, in seconds
404 """
405 extra_headers = {
406 **strip_not_given(
407 {
408 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
409 "anthropic-workspace-id": workspace_id,
410 }
411 ),
412 **(extra_headers or {}),
413 }
414 body = deepcopy_with_paths(
415 {
416 "files": files,
417 "display_name": display_name,
418 },
419 [["files", "<array>"]],
420 )
421 extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
422 # It should be noted that the actual Content-Type header that will be
423 # sent to the server will contain a `boundary` parameter, e.g.
424 # multipart/form-data; boundary=---abc--
425 extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
426 return await self._post(
427 "/v1/skills?beta=true",
428 body=body,
429 files=extracted_files,
430 options=make_request_options(
431 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
432 ),
433 cast_to=BetaSkill,
434 )
435
436 async def retrieve(
437 self,
438 skill_id: str,
439 *,
440 betas: List[AnthropicBetaParam] | Omit = omit,
441 workspace_id: str | Omit = omit,
442 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
443 # The extra values given here take precedence over values defined on the client or passed to this method.
444 extra_headers: Headers | None = None,
445 extra_query: Query | None = None,
446 extra_body: Body | None = None,
447 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
448 ) -> BetaSkill:
449 """
450 Get Skill
451
452 Args:
453 skill_id: Unique identifier for the skill.
454
455 The format and length of IDs may change over time.
456
457 betas: Optional header to specify the beta version(s) you want to use.
458
459 workspace_id: Optional header to select the Workspace for this request. The value is a
460 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
461
462 Only needed for credentials that can act on more than one Workspace. A
463 credential that belongs to a specific Workspace may omit it; if sent, it must
464 match that Workspace.
465
466 extra_headers: Send extra headers
467
468 extra_query: Add additional query parameters to the request
469
470 extra_body: Add additional JSON properties to the request
471
472 timeout: Override the client-level default timeout for this request, in seconds
473 """
474 if not skill_id:
475 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
476 extra_headers = {
477 **strip_not_given(
478 {
479 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
480 "anthropic-workspace-id": workspace_id,
481 }
482 ),
483 **(extra_headers or {}),
484 }
485 return await self._get(
486 path_template("/v1/skills/{skill_id}?beta=true", skill_id=skill_id),
487 options=make_request_options(
488 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
489 ),
490 cast_to=BetaSkill,
491 )
492
493 def list(
494 self,
495 *,
496 limit: int | Omit = omit,
497 page: Optional[str] | Omit = omit,
498 source: Optional[str] | Omit = omit,
499 betas: List[AnthropicBetaParam] | Omit = omit,
500 workspace_id: str | Omit = omit,
501 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
502 # The extra values given here take precedence over values defined on the client or passed to this method.
503 extra_headers: Headers | None = None,
504 extra_query: Query | None = None,
505 extra_body: Body | None = None,
506 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
507 ) -> AsyncPaginator[BetaSkill, AsyncPageCursor[BetaSkill]]:
508 """
509 List Skills
510
511 Args:
512 limit: Number of results to return per page.
513
514 Ranges from `1` to `1000`. Defaults to `20`.
515
516 page: Pagination token for fetching a specific page of results.
517
518 Pass the value from a previous response's `next_page` field to get the next page
519 of results.
520
521 source: Filter skills by source.
522
523 If provided, only skills from the specified source will be returned:
524
525 - `"custom"`: only return user-created skills
526 - `"anthropic"`: only return Anthropic-created skills
527
528 betas: Optional header to specify the beta version(s) you want to use.
529
530 workspace_id: Optional header to select the Workspace for this request. The value is a
531 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
532
533 Only needed for credentials that can act on more than one Workspace. A
534 credential that belongs to a specific Workspace may omit it; if sent, it must
535 match that Workspace.
536
537 extra_headers: Send extra headers
538
539 extra_query: Add additional query parameters to the request
540
541 extra_body: Add additional JSON properties to the request
542
543 timeout: Override the client-level default timeout for this request, in seconds
544 """
545 extra_headers = {
546 **strip_not_given(
547 {
548 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
549 "anthropic-workspace-id": workspace_id,
550 }
551 ),
552 **(extra_headers or {}),
553 }
554 return self._get_api_list(
555 "/v1/skills?beta=true",
556 page=AsyncPageCursor[BetaSkill],
557 options=make_request_options(
558 extra_headers=extra_headers,
559 extra_query=extra_query,
560 extra_body=extra_body,
561 timeout=timeout,
562 query={
563 "limit": limit,
564 "page": page,
565 "source": source,
566 },
567 ),
568 model=BetaSkill,
569 )
570
571 async def delete(
572 self,
573 skill_id: str,
574 *,
575 betas: List[AnthropicBetaParam] | Omit = omit,
576 workspace_id: str | Omit = omit,
577 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
578 # The extra values given here take precedence over values defined on the client or passed to this method.
579 extra_headers: Headers | None = None,
580 extra_query: Query | None = None,
581 extra_body: Body | None = None,
582 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
583 ) -> BetaDeletedSkill:
584 """
585 Delete Skill
586
587 Args:
588 skill_id: Unique identifier for the skill.
589
590 The format and length of IDs may change over time.
591
592 betas: Optional header to specify the beta version(s) you want to use.
593
594 workspace_id: Optional header to select the Workspace for this request. The value is a
595 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
596
597 Only needed for credentials that can act on more than one Workspace. A
598 credential that belongs to a specific Workspace may omit it; if sent, it must
599 match that Workspace.
600
601 extra_headers: Send extra headers
602
603 extra_query: Add additional query parameters to the request
604
605 extra_body: Add additional JSON properties to the request
606
607 timeout: Override the client-level default timeout for this request, in seconds
608 """
609 if not skill_id:
610 raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
611 extra_headers = {
612 **strip_not_given(
613 {
614 "anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given,
615 "anthropic-workspace-id": workspace_id,
616 }
617 ),
618 **(extra_headers or {}),
619 }
620 return await self._delete(
621 path_template("/v1/skills/{skill_id}?beta=true", skill_id=skill_id),
622 options=make_request_options(
623 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
624 ),
625 cast_to=BetaDeletedSkill,
626 )
627
628
629 class SkillsWithRawResponse:
630 def __init__(self, skills: Skills) -> None:
631 self._skills = skills
632
633 self.create = to_raw_response_wrapper(
634 skills.create,
635 )
636 self.retrieve = to_raw_response_wrapper(
637 skills.retrieve,
638 )
639 self.list = to_raw_response_wrapper(
640 skills.list,
641 )
642 self.delete = to_raw_response_wrapper(
643 skills.delete,
644 )
645
646 @cached_property
647 def versions(self) -> VersionsWithRawResponse:
648 return VersionsWithRawResponse(self._skills.versions)
649
650
651 class AsyncSkillsWithRawResponse:
652 def __init__(self, skills: AsyncSkills) -> None:
653 self._skills = skills
654
655 self.create = async_to_raw_response_wrapper(
656 skills.create,
657 )
658 self.retrieve = async_to_raw_response_wrapper(
659 skills.retrieve,
660 )
661 self.list = async_to_raw_response_wrapper(
662 skills.list,
663 )
664 self.delete = async_to_raw_response_wrapper(
665 skills.delete,
666 )
667
668 @cached_property
669 def versions(self) -> AsyncVersionsWithRawResponse:
670 return AsyncVersionsWithRawResponse(self._skills.versions)
671
672
673 class SkillsWithStreamingResponse:
674 def __init__(self, skills: Skills) -> None:
675 self._skills = skills
676
677 self.create = to_streamed_response_wrapper(
678 skills.create,
679 )
680 self.retrieve = to_streamed_response_wrapper(
681 skills.retrieve,
682 )
683 self.list = to_streamed_response_wrapper(
684 skills.list,
685 )
686 self.delete = to_streamed_response_wrapper(
687 skills.delete,
688 )
689
690 @cached_property
691 def versions(self) -> VersionsWithStreamingResponse:
692 return VersionsWithStreamingResponse(self._skills.versions)
693
694
695 class AsyncSkillsWithStreamingResponse:
696 def __init__(self, skills: AsyncSkills) -> None:
697 self._skills = skills
698
699 self.create = async_to_streamed_response_wrapper(
700 skills.create,
701 )
702 self.retrieve = async_to_streamed_response_wrapper(
703 skills.retrieve,
704 )
705 self.list = async_to_streamed_response_wrapper(
706 skills.list,
707 )
708 self.delete = async_to_streamed_response_wrapper(
709 skills.delete,
710 )
711
712 @cached_property
713 def versions(self) -> AsyncVersionsWithStreamingResponse:
714 return AsyncVersionsWithStreamingResponse(self._skills.versions)