Class: Kohagi::Result

Inherits:
Struct
  • Object
show all
Defined in:
lib/kohagi/result.rb

Overview

One output record: the echoed id and its vector, plus the optional --report-tokens fields. id is whatever JSON value was sent, unchanged.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#embeddingObject

Returns the value of attribute embedding

Returns:

  • (Object)

    the current value of embedding



8
9
10
# File 'lib/kohagi/result.rb', line 8

def embedding
  @embedding
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



8
9
10
# File 'lib/kohagi/result.rb', line 8

def id
  @id
end

#n_tokensObject

Returns the value of attribute n_tokens

Returns:

  • (Object)

    the current value of n_tokens



8
9
10
# File 'lib/kohagi/result.rb', line 8

def n_tokens
  @n_tokens
end

#truncatedObject

Returns the value of attribute truncated

Returns:

  • (Object)

    the current value of truncated



8
9
10
# File 'lib/kohagi/result.rb', line 8

def truncated
  @truncated
end

Class Method Details

.from_json(line) ⇒ Object

Parse one JSONL line from kohagi's stdout.



16
17
18
19
20
21
22
23
24
# File 'lib/kohagi/result.rb', line 16

def self.from_json(line)
  row = JSON.parse(line)
  new(
    id: row["id"],
    embedding: row["embedding"],
    n_tokens: row["n_tokens"],
    truncated: row["truncated"]
  )
end

Instance Method Details

#truncated?Boolean

True only when kohagi reported this text as truncated (needs report_tokens: true); nil/false otherwise.

Returns:

  • (Boolean)


11
12
13
# File 'lib/kohagi/result.rb', line 11

def truncated?
  truncated == true
end