Skip to content

Commit 85a84a1

Browse files
feat(api): manual updates
1 parent ed21f62 commit 85a84a1

9 files changed

Lines changed: 105 additions & 830 deletions

File tree

‎.stats.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 36
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-654e47d50a02e8b12f4f035b1a8ec6e864557fed57b744c909ca85127739cc30.yml
1+
configured_endpoints: 29
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2e40370ce4d7d019b30d43020674bb02aaaf2a67a8916772084815c874f99950.yml
33
openapi_spec_hash: a44b7d4172c8c7cd395237738867d5cb
4-
config_hash: 7ec4851ee8d93177947e95df5ae897b5
4+
config_hash: 472cc1adb51663e5b3d8dce16f6d29d9

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ context-dev [resource] <command> [flags...]
4848
```
4949

5050
```sh
51-
context-dev brand retrieve \
51+
context-dev web extract \
5252
--api-key 'My API Key' \
53-
--domain REPLACE_ME
53+
--schema '{type: bar, properties: bar, required: bar, additionalProperties: bar}' \
54+
--url https://example.com
5455
```
5556

5657
For details about specific commands, use the `--help` flag.

‎pkg/cmd/ai.go‎

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -14,118 +14,6 @@ import (
1414
"github.com/urfave/cli/v3"
1515
)
1616

17-
var aiAIQuery = requestflag.WithInnerFlags(cli.Command{
18-
Name: "ai-query",
19-
Usage: "Use AI to extract specific data points from a brand's website. The AI will crawl\nthe website and extract the requested information based on the provided data\npoints.",
20-
Suggest: true,
21-
Flags: []cli.Flag{
22-
&requestflag.Flag[[]map[string]any]{
23-
Name: "data-to-extract",
24-
Usage: "Array of data points to extract from the website",
25-
Required: true,
26-
BodyPath: "data_to_extract",
27-
},
28-
&requestflag.Flag[string]{
29-
Name: "domain",
30-
Usage: "The domain name to analyze",
31-
Required: true,
32-
BodyPath: "domain",
33-
},
34-
&requestflag.Flag[map[string]any]{
35-
Name: "specific-pages",
36-
Usage: "Optional object specifying which pages to analyze",
37-
BodyPath: "specific_pages",
38-
},
39-
&requestflag.Flag[int64]{
40-
Name: "timeout-ms",
41-
Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).",
42-
BodyPath: "timeoutMS",
43-
},
44-
},
45-
Action: handleAIAIQuery,
46-
HideHelpCommand: true,
47-
}, map[string][]requestflag.HasOuterFlag{
48-
"data-to-extract": {
49-
&requestflag.InnerFlag[string]{
50-
Name: "data-to-extract.datapoint-description",
51-
Usage: "Description of what to extract",
52-
InnerField: "datapoint_description",
53-
},
54-
&requestflag.InnerFlag[string]{
55-
Name: "data-to-extract.datapoint-example",
56-
Usage: "Example of the expected value",
57-
InnerField: "datapoint_example",
58-
},
59-
&requestflag.InnerFlag[string]{
60-
Name: "data-to-extract.datapoint-name",
61-
Usage: "Name of the data point to extract",
62-
InnerField: "datapoint_name",
63-
},
64-
&requestflag.InnerFlag[string]{
65-
Name: "data-to-extract.datapoint-type",
66-
Usage: "Type of the data point",
67-
InnerField: "datapoint_type",
68-
},
69-
&requestflag.InnerFlag[string]{
70-
Name: "data-to-extract.datapoint-list-type",
71-
Usage: "Type of items in the list when datapoint_type is 'list'. Defaults to 'string'. Use 'object' to extract an array of objects matching a schema.",
72-
InnerField: "datapoint_list_type",
73-
},
74-
&requestflag.InnerFlag[map[string]any]{
75-
Name: "data-to-extract.datapoint-object-schema",
76-
Usage: "Schema definition for objects when datapoint_list_type is 'object'. Provide a map of field names to their scalar types.",
77-
InnerField: "datapoint_object_schema",
78-
},
79-
},
80-
"specific-pages": {
81-
&requestflag.InnerFlag[bool]{
82-
Name: "specific-pages.about-us",
83-
Usage: "Whether to analyze the about us page",
84-
InnerField: "about_us",
85-
},
86-
&requestflag.InnerFlag[bool]{
87-
Name: "specific-pages.blog",
88-
Usage: "Whether to analyze the blog",
89-
InnerField: "blog",
90-
},
91-
&requestflag.InnerFlag[bool]{
92-
Name: "specific-pages.careers",
93-
Usage: "Whether to analyze the careers page",
94-
InnerField: "careers",
95-
},
96-
&requestflag.InnerFlag[bool]{
97-
Name: "specific-pages.contact-us",
98-
Usage: "Whether to analyze the contact us page",
99-
InnerField: "contact_us",
100-
},
101-
&requestflag.InnerFlag[bool]{
102-
Name: "specific-pages.faq",
103-
Usage: "Whether to analyze the FAQ page",
104-
InnerField: "faq",
105-
},
106-
&requestflag.InnerFlag[bool]{
107-
Name: "specific-pages.home-page",
108-
Usage: "Whether to analyze the home page",
109-
InnerField: "home_page",
110-
},
111-
&requestflag.InnerFlag[bool]{
112-
Name: "specific-pages.pricing",
113-
Usage: "Whether to analyze the pricing page",
114-
InnerField: "pricing",
115-
},
116-
&requestflag.InnerFlag[bool]{
117-
Name: "specific-pages.privacy-policy",
118-
Usage: "Whether to analyze the privacy policy page",
119-
InnerField: "privacy_policy",
120-
},
121-
&requestflag.InnerFlag[bool]{
122-
Name: "specific-pages.terms-and-conditions",
123-
Usage: "Whether to analyze the terms and conditions page",
124-
InnerField: "terms_and_conditions",
125-
},
126-
},
127-
})
128-
12917
var aiExtractProduct = cli.Command{
13018
Name: "extract-product",
13119
Usage: "Given a single URL, determines if it is a product page and extracts the product\ninformation.",
@@ -189,47 +77,6 @@ var aiExtractProducts = cli.Command{
18977
HideHelpCommand: true,
19078
}
19179

192-
func handleAIAIQuery(ctx context.Context, cmd *cli.Command) error {
193-
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
194-
unusedArgs := cmd.Args().Slice()
195-
196-
if len(unusedArgs) > 0 {
197-
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
198-
}
199-
200-
options, err := flagOptions(
201-
cmd,
202-
apiquery.NestedQueryFormatBrackets,
203-
apiquery.ArrayQueryFormatComma,
204-
ApplicationJSON,
205-
false,
206-
)
207-
if err != nil {
208-
return err
209-
}
210-
211-
params := contextdev.AIAIQueryParams{}
212-
213-
var res []byte
214-
options = append(options, option.WithResponseBodyInto(&res))
215-
_, err = client.AI.AIQuery(ctx, params, options...)
216-
if err != nil {
217-
return err
218-
}
219-
220-
obj := gjson.ParseBytes(res)
221-
format := cmd.Root().String("format")
222-
explicitFormat := cmd.Root().IsSet("format")
223-
transform := cmd.Root().String("transform")
224-
return ShowJSON(obj, ShowJSONOpts{
225-
ExplicitFormat: explicitFormat,
226-
Format: format,
227-
RawOutput: cmd.Root().Bool("raw-output"),
228-
Title: "ai ai-query",
229-
Transform: transform,
230-
})
231-
}
232-
23380
func handleAIExtractProduct(ctx context.Context, cmd *cli.Command) error {
23481
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
23582
unusedArgs := cmd.Args().Slice()

‎pkg/cmd/ai_test.go‎

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,84 +6,8 @@ import (
66
"testing"
77

88
"github.com/context-dot-dev/context-dev-cli/internal/mocktest"
9-
"github.com/context-dot-dev/context-dev-cli/internal/requestflag"
109
)
1110

12-
func TestAIAIQuery(t *testing.T) {
13-
t.Skip("Mock server tests are disabled")
14-
t.Run("regular flags", func(t *testing.T) {
15-
mocktest.TestRunMockTestWithFlags(
16-
t,
17-
"--api-key", "string",
18-
"ai", "ai-query",
19-
"--data-to-extract", "{datapoint_description: datapoint_description, datapoint_example: datapoint_example, datapoint_name: datapoint_name, datapoint_type: text, datapoint_list_type: string, datapoint_object_schema: {testimonial_text: string, testimonial_author: string}}",
20-
"--domain", "domain",
21-
"--specific-pages", "{about_us: true, blog: true, careers: true, contact_us: true, faq: true, home_page: true, pricing: true, privacy_policy: true, terms_and_conditions: true}",
22-
"--timeout-ms", "1000",
23-
)
24-
})
25-
26-
t.Run("inner flags", func(t *testing.T) {
27-
// Check that inner flags have been set up correctly
28-
requestflag.CheckInnerFlags(aiAIQuery)
29-
30-
// Alternative argument passing style using inner flags
31-
mocktest.TestRunMockTestWithFlags(
32-
t,
33-
"--api-key", "string",
34-
"ai", "ai-query",
35-
"--data-to-extract.datapoint-description", "datapoint_description",
36-
"--data-to-extract.datapoint-example", "datapoint_example",
37-
"--data-to-extract.datapoint-name", "datapoint_name",
38-
"--data-to-extract.datapoint-type", "text",
39-
"--data-to-extract.datapoint-list-type", "string",
40-
"--data-to-extract.datapoint-object-schema", "{testimonial_text: string, testimonial_author: string}",
41-
"--domain", "domain",
42-
"--specific-pages.about-us=true",
43-
"--specific-pages.blog=true",
44-
"--specific-pages.careers=true",
45-
"--specific-pages.contact-us=true",
46-
"--specific-pages.faq=true",
47-
"--specific-pages.home-page=true",
48-
"--specific-pages.pricing=true",
49-
"--specific-pages.privacy-policy=true",
50-
"--specific-pages.terms-and-conditions=true",
51-
"--timeout-ms", "1000",
52-
)
53-
})
54-
55-
t.Run("piping data", func(t *testing.T) {
56-
// Test piping YAML data over stdin
57-
pipeData := []byte("" +
58-
"data_to_extract:\n" +
59-
" - datapoint_description: datapoint_description\n" +
60-
" datapoint_example: datapoint_example\n" +
61-
" datapoint_name: datapoint_name\n" +
62-
" datapoint_type: text\n" +
63-
" datapoint_list_type: string\n" +
64-
" datapoint_object_schema:\n" +
65-
" testimonial_text: string\n" +
66-
" testimonial_author: string\n" +
67-
"domain: domain\n" +
68-
"specific_pages:\n" +
69-
" about_us: true\n" +
70-
" blog: true\n" +
71-
" careers: true\n" +
72-
" contact_us: true\n" +
73-
" faq: true\n" +
74-
" home_page: true\n" +
75-
" pricing: true\n" +
76-
" privacy_policy: true\n" +
77-
" terms_and_conditions: true\n" +
78-
"timeoutMS: 1000\n")
79-
mocktest.TestRunMockTestWithPipeAndFlags(
80-
t, pipeData,
81-
"--api-key", "string",
82-
"ai", "ai-query",
83-
)
84-
})
85-
}
86-
8711
func TestAIExtractProduct(t *testing.T) {
8812
t.Skip("Mock server tests are disabled")
8913
t.Run("regular flags", func(t *testing.T) {

0 commit comments

Comments
 (0)