Class: ContextDev::Resources::AI

Inherits:
Object
  • Object
show all
Defined in:
lib/context_dev/resources/ai.rb,
sig/context_dev/resources/ai.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ AI

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AI.

Parameters:



62
63
64
# File 'lib/context_dev/resources/ai.rb', line 62

def initialize(client:)
  @client = client
end

Instance Method Details

#extract_product(url:, max_age_ms: nil, timeout_ms: nil, request_options: {}) ⇒ ContextDev::Models::AIExtractProductResponse

Some parameter documentations has been truncated, see Models::AIExtractProductParams for more details.

Given a single URL, determines if it is a product page and extracts the product information.

Parameters:

  • url (String)

    The product page URL to extract product data from.

  • max_age_ms (Integer)

    Return a cached result if a prior scrape for the same parameters exists and is y

  • timeout_ms (Integer)

    Optional timeout in milliseconds for the request. If the request takes longer th

  • request_options (ContextDev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



25
26
27
28
29
30
31
32
33
34
# File 'lib/context_dev/resources/ai.rb', line 25

def extract_product(params)
  parsed, options = ContextDev::AIExtractProductParams.dump_request(params)
  @client.request(
    method: :post,
    path: "brand/ai/product",
    body: parsed,
    model: ContextDev::Models::AIExtractProductResponse,
    options: options
  )
end

#extract_products(body:, request_options: {}) ⇒ ContextDev::Models::AIExtractProductsResponse

Extract product information from a brand's website. We will analyze the website and return a list of products with details such as name, description, image, pricing, features, and more.



48
49
50
51
52
53
54
55
56
57
# File 'lib/context_dev/resources/ai.rb', line 48

def extract_products(params)
  parsed, options = ContextDev::AIExtractProductsParams.dump_request(params)
  @client.request(
    method: :post,
    path: "brand/ai/products",
    body: parsed[:body],
    model: ContextDev::Models::AIExtractProductsResponse,
    options: options
  )
end