From fa742892ecefef7f733c6356930a2bd4f1a4afa3 Mon Sep 17 00:00:00 2001 From: <> Date: Thu, 7 Dec 2023 21:32:53 +0000 Subject: [PATCH] Deployed 430ee4d with MkDocs version: 1.5.3 --- .nojekyll | 0 404.html | 1190 +++ api/continuation/index.html | 2003 +++++ api/fsm/index.html | 2321 ++++++ api/index.html | 1292 ++++ api/json_schema/index.html | 2122 ++++++ api/models/index.html | 4309 +++++++++++ api/parsing/index.html | 2718 +++++++ api/prompts/index.html | 2739 +++++++ api/regex/index.html | 3086 ++++++++ api/sample/index.html | 1895 +++++ assets/_mkdocstrings.css | 64 + assets/images/favicon.png | Bin 0 -> 1870 bytes assets/images/logo.png | Bin 0 -> 372647 bytes assets/images/normal_computing.jpg | Bin 0 -> 64918 bytes assets/images/social/api/continuation.png | Bin 0 -> 55078 bytes assets/images/social/api/fsm.png | Bin 0 -> 50074 bytes assets/images/social/api/index.png | Bin 0 -> 49706 bytes assets/images/social/api/json_schema.png | Bin 0 -> 57239 bytes assets/images/social/api/models.png | Bin 0 -> 55089 bytes assets/images/social/api/parsing.png | Bin 0 -> 54855 bytes assets/images/social/api/prompts.png | Bin 0 -> 54649 bytes assets/images/social/api/regex.png | Bin 0 -> 53469 bytes assets/images/social/api/sample.png | Bin 0 -> 54877 bytes .../social/examples/chain_of_density.png | Bin 0 -> 69659 bytes .../social/examples/dating_profiles.png | Bin 0 -> 67165 bytes assets/images/social/examples/index.png | Bin 0 -> 55967 bytes assets/images/social/feedback.png | Bin 0 -> 55334 bytes assets/images/social/get_started.png | Bin 0 -> 56712 bytes assets/images/social/index.png | Bin 0 -> 55253 bytes assets/images/social/licence.png | Bin 0 -> 52941 bytes assets/images/social/reference/choices.png | Bin 0 -> 62552 bytes assets/images/social/reference/index.png | Bin 0 -> 53216 bytes assets/images/social/reference/json.png | Bin 0 -> 75109 bytes .../reference/openai_text_generation.png | Bin 0 -> 54581 bytes assets/images/social/reference/prompting.png | Bin 0 -> 55830 bytes assets/images/social/reference/regex.png | Bin 0 -> 63910 bytes assets/images/social/reference/types.png | Bin 0 -> 59938 bytes assets/javascripts/bundle.d7c377c4.min.js | 29 + assets/javascripts/bundle.d7c377c4.min.js.map | 7 + assets/javascripts/lunr/min/lunr.ar.min.js | 1 + assets/javascripts/lunr/min/lunr.da.min.js | 18 + assets/javascripts/lunr/min/lunr.de.min.js | 18 + assets/javascripts/lunr/min/lunr.du.min.js | 18 + assets/javascripts/lunr/min/lunr.el.min.js | 1 + assets/javascripts/lunr/min/lunr.es.min.js | 18 + assets/javascripts/lunr/min/lunr.fi.min.js | 18 + assets/javascripts/lunr/min/lunr.fr.min.js | 18 + assets/javascripts/lunr/min/lunr.he.min.js | 1 + assets/javascripts/lunr/min/lunr.hi.min.js | 1 + assets/javascripts/lunr/min/lunr.hu.min.js | 18 + assets/javascripts/lunr/min/lunr.hy.min.js | 1 + assets/javascripts/lunr/min/lunr.it.min.js | 18 + assets/javascripts/lunr/min/lunr.ja.min.js | 1 + assets/javascripts/lunr/min/lunr.jp.min.js | 1 + assets/javascripts/lunr/min/lunr.kn.min.js | 1 + assets/javascripts/lunr/min/lunr.ko.min.js | 1 + assets/javascripts/lunr/min/lunr.multi.min.js | 1 + assets/javascripts/lunr/min/lunr.nl.min.js | 18 + assets/javascripts/lunr/min/lunr.no.min.js | 18 + assets/javascripts/lunr/min/lunr.pt.min.js | 18 + assets/javascripts/lunr/min/lunr.ro.min.js | 18 + assets/javascripts/lunr/min/lunr.ru.min.js | 18 + assets/javascripts/lunr/min/lunr.sa.min.js | 1 + .../lunr/min/lunr.stemmer.support.min.js | 1 + assets/javascripts/lunr/min/lunr.sv.min.js | 18 + assets/javascripts/lunr/min/lunr.ta.min.js | 1 + assets/javascripts/lunr/min/lunr.te.min.js | 1 + assets/javascripts/lunr/min/lunr.th.min.js | 1 + assets/javascripts/lunr/min/lunr.tr.min.js | 18 + assets/javascripts/lunr/min/lunr.vi.min.js | 1 + assets/javascripts/lunr/min/lunr.zh.min.js | 1 + assets/javascripts/lunr/tinyseg.js | 206 + assets/javascripts/lunr/wordcut.js | 6708 +++++++++++++++++ .../workers/search.f886a092.min.js | 42 + .../workers/search.f886a092.min.js.map | 7 + assets/stylesheets/main.45e1311d.min.css | 1 + assets/stylesheets/main.45e1311d.min.css.map | 1 + assets/stylesheets/palette.06af60db.min.css | 1 + .../stylesheets/palette.06af60db.min.css.map | 1 + examples/chain_of_density/index.html | 1479 ++++ examples/dating_profiles/index.html | 1624 ++++ examples/images/chain_of_density.png | Bin 0 -> 515603 bytes examples/index.html | 1296 ++++ feedback/index.html | 1310 ++++ get_started/index.html | 1463 ++++ index.html | 1303 ++++ licence/index.html | 1505 ++++ objects.inv | Bin 0 -> 893 bytes overrides/index.html | 11 + overrides/main.html | 22 + reference/choices/index.html | 1302 ++++ reference/index.html | 1318 ++++ reference/json/index.html | 1419 ++++ reference/openai_text_generation/index.html | 1651 ++++ reference/prompting/index.html | 1518 ++++ reference/regex/index.html | 1302 ++++ reference/types/index.html | 1311 ++++ search/search_index.json | 1 + sitemap.xml | 3 + sitemap.xml.gz | Bin 0 -> 127 bytes stylesheets/extra.css | 37 + 102 files changed, 50904 insertions(+) create mode 100644 .nojekyll create mode 100644 404.html create mode 100644 api/continuation/index.html create mode 100644 api/fsm/index.html create mode 100644 api/index.html create mode 100644 api/json_schema/index.html create mode 100644 api/models/index.html create mode 100644 api/parsing/index.html create mode 100644 api/prompts/index.html create mode 100644 api/regex/index.html create mode 100644 api/sample/index.html create mode 100644 assets/_mkdocstrings.css create mode 100644 assets/images/favicon.png create mode 100644 assets/images/logo.png create mode 100644 assets/images/normal_computing.jpg create mode 100644 assets/images/social/api/continuation.png create mode 100644 assets/images/social/api/fsm.png create mode 100644 assets/images/social/api/index.png create mode 100644 assets/images/social/api/json_schema.png create mode 100644 assets/images/social/api/models.png create mode 100644 assets/images/social/api/parsing.png create mode 100644 assets/images/social/api/prompts.png create mode 100644 assets/images/social/api/regex.png create mode 100644 assets/images/social/api/sample.png create mode 100644 assets/images/social/examples/chain_of_density.png create mode 100644 assets/images/social/examples/dating_profiles.png create mode 100644 assets/images/social/examples/index.png create mode 100644 assets/images/social/feedback.png create mode 100644 assets/images/social/get_started.png create mode 100644 assets/images/social/index.png create mode 100644 assets/images/social/licence.png create mode 100644 assets/images/social/reference/choices.png create mode 100644 assets/images/social/reference/index.png create mode 100644 assets/images/social/reference/json.png create mode 100644 assets/images/social/reference/openai_text_generation.png create mode 100644 assets/images/social/reference/prompting.png create mode 100644 assets/images/social/reference/regex.png create mode 100644 assets/images/social/reference/types.png create mode 100644 assets/javascripts/bundle.d7c377c4.min.js create mode 100644 assets/javascripts/bundle.d7c377c4.min.js.map create mode 100644 assets/javascripts/lunr/min/lunr.ar.min.js create mode 100644 assets/javascripts/lunr/min/lunr.da.min.js create mode 100644 assets/javascripts/lunr/min/lunr.de.min.js create mode 100644 assets/javascripts/lunr/min/lunr.du.min.js create mode 100644 assets/javascripts/lunr/min/lunr.el.min.js create mode 100644 assets/javascripts/lunr/min/lunr.es.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.he.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hu.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hy.min.js create mode 100644 assets/javascripts/lunr/min/lunr.it.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ja.min.js create mode 100644 assets/javascripts/lunr/min/lunr.jp.min.js create mode 100644 assets/javascripts/lunr/min/lunr.kn.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ko.min.js create mode 100644 assets/javascripts/lunr/min/lunr.multi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.nl.min.js create mode 100644 assets/javascripts/lunr/min/lunr.no.min.js create mode 100644 assets/javascripts/lunr/min/lunr.pt.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ro.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ru.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sa.min.js create mode 100644 assets/javascripts/lunr/min/lunr.stemmer.support.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sv.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ta.min.js create mode 100644 assets/javascripts/lunr/min/lunr.te.min.js create mode 100644 assets/javascripts/lunr/min/lunr.th.min.js create mode 100644 assets/javascripts/lunr/min/lunr.tr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.vi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.zh.min.js create mode 100644 assets/javascripts/lunr/tinyseg.js create mode 100644 assets/javascripts/lunr/wordcut.js create mode 100644 assets/javascripts/workers/search.f886a092.min.js create mode 100644 assets/javascripts/workers/search.f886a092.min.js.map create mode 100644 assets/stylesheets/main.45e1311d.min.css create mode 100644 assets/stylesheets/main.45e1311d.min.css.map create mode 100644 assets/stylesheets/palette.06af60db.min.css create mode 100644 assets/stylesheets/palette.06af60db.min.css.map create mode 100644 examples/chain_of_density/index.html create mode 100644 examples/dating_profiles/index.html create mode 100644 examples/images/chain_of_density.png create mode 100644 examples/index.html create mode 100644 feedback/index.html create mode 100644 get_started/index.html create mode 100644 index.html create mode 100644 licence/index.html create mode 100644 objects.inv create mode 100644 overrides/index.html create mode 100644 overrides/main.html create mode 100644 reference/choices/index.html create mode 100644 reference/index.html create mode 100644 reference/json/index.html create mode 100644 reference/openai_text_generation/index.html create mode 100644 reference/prompting/index.html create mode 100644 reference/regex/index.html create mode 100644 reference/types/index.html create mode 100644 search/search_index.json create mode 100644 sitemap.xml create mode 100644 sitemap.xml.gz create mode 100644 stylesheets/extra.css diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 000000000..e69de29bb diff --git a/404.html b/404.html new file mode 100644 index 000000000..1c323225e --- /dev/null +++ b/404.html @@ -0,0 +1,1190 @@ + + + +
+ + + + + + + + + + + + + + + + + + +Continuation
+
+
+
+ Bases: Sequence
Represents a completion generation model.
+Continuation
instances are unconstrained generation models that stop when
+an EOS token has been found or when the maximum number of tokens has been
+reached.
++ +++++import outlines.text as text +sequence = text.generate.continuation(model)("Say something")
+
outlines/text/generate/continuation.py
11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 |
|
is_finished(token_ids)
+
+Determine whether the sequences reached maximum length of end with +and EOS token.
+We only need to look for the EOS token in the last element rather than
+in the whole sequence. Indeed, (1) EOS is a single token (2)
+Sequence
's __call__
methods only passed the token_ids
of the
+sequences that haven't been marked as finished already.
token_ids + The input sequences.
+ +outlines/text/generate/continuation.py
postprocess_completions(completions)
+
+Remove the EOS token from the completion.
+ Sequences in `stop` take precedence over EOS. For instance, if
+ `stop=["
+
"]and the generated sequence is 'One
+Two<EOS>
+ Continuation.postprocess_completions
will return One
.
outlines/text/generate/continuation.py
continuation(model, max_tokens=None, *, sampler=None, stop=[])
+
+Generate text sequences.
+model
+ The language model to use to compute the next-token logits.
+max_tokens
+ The maximum number of tokens to generate.
+sampler
+ The function used to draw samples. Defaults to
+ outlines.text.generate.sample.multinomial
. See
+ outlines.text.generate.sample.Sampler
for the expected form of
+ such functions.
+stop
+ A string or list of strings which, when generated, stops
+ the generation for this sequence.
outlines/text/generate/continuation.py
create_fsm_index_end_to_end(fsm_info, vocabulary)
+
+Create an FSM state-to-vocabulary map/index through end-to-end token parsing.
+ +outlines/text/fsm.py
create_fsm_index_tokenizer(fsm, tokenizer)
+
+Construct an FMS index from a tokenizer.
+This uses the end-to-end approach of create_fsm_index_end_to_end
.
.. warning::
+`fsm` needs to be deterministically ordered so that future caching makes sense.
+
outlines/text/fsm.py
fsm_union(fsms)
+
+Construct an FSM representing the union of the FSMs in fsms
.
This is an updated version of interegular.fsm.FSM.union
made to return an
+extra map of component FSMs to the sets of state transitions that
+correspond to them in the new FSM.
outlines/text/fsm.py
304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 |
|
get_sub_fsms_from_seq(state_seq, fsms_to_trans_finals)
+
+Get the indices of the sub-FSMs in fsm
that could have matched the state sequence state_seq
.
state_seq + A state sequence. +fsms_to_trans_finals + A map from FSM indices to tuples containing sets of their state transitions + and sets of the final/accept states.
+A generator returning tuples containing each sub-FSM index (in the order
+they were union-ed to construct fsm
) and booleans indicating whether or
+not there is another valid transition from the last state in the sequence
+for the associated sub-FSM (i.e. if the FSM can continue
+accepting/matching) and whether or not the sequence ends in a final state
+of the sub-FSM.
outlines/text/fsm.py
make_deterministic_fsm(fsm)
+
+Construct an equivalent FSM with deterministic state labels.
+ +outlines/text/fsm.py
151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 |
|
reduced_vocabulary(tokenizer)
+
+
+ cached
+
+
+Create a map from decoded vocabulary tokens to lists of equivalent token ids.
+ +outlines/text/fsm.py
build_regex_from_object(object)
+
+Turn a JSON schema into a regex that matches any JSON object that follows +this schema.
+JSON Schema is a declarative language that allows to annotate JSON documents +with types and descriptions. These schemas can be generated from any Python +datastructure that has type annotation: namedtuples, dataclasses, Pydantic +models. And by ensuring that the generation respects the schema we ensure +that the output can be parsed into these objects. +This function parses the provided schema and builds a generation schedule which +mixes deterministic generation (fixed strings), and sampling with constraints.
+schema + A string that represents a JSON Schema.
+A generation schedule. A list of strings that represent the JSON +schema's structure and regular expression that define the structure of +the fields.
+.. [0] JSON Schema. https://json-schema.org/
+ +outlines/text/json_schema.py
get_schema_from_signature(fn)
+
+Turn a function signature into a JSON schema.
+Every JSON object valid to the output JSON Schema can be passed
+to fn
using the ** unpacking syntax.
outlines/text/json_schema.py
to_regex(resolver, instance)
+
+Translate a JSON Schema instance into a regex that validates the schema.
+Many features of JSON schema are missing:
+- Support the fact that fields in an object are optional by default
+- Handle required
keyword
+- Handle additionalProperties
keyword
+- Handle types defined as a list
+- Handle constraints on numbers
+- Handle special patterns: date
, uri
, etc.
+- Handle optional fields (not in required
)
This does not support recursive definitions.
+resolver + An object that resolves references to other instances within a schema +instance + The instance to translate
+ +outlines/text/json_schema.py
77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 |
|
Transformer
+
+
+Represents a transformers
model.
outlines/models/transformers.py
forward(input_ids, attention_mask, past_key_values=None)
+
+Compute a forward pass through the transformer model.
+input_ids + The input token ids. Must be one or two dimensional. +attention_mask + The attention mask. Must be one or two dimensional. +past_key_values + A tuple of tuples containing the cached key and value tensors for each + attention head.
+The computed logits and the new cached key and value tensors.
+ +outlines/models/transformers.py
TransformerTokenizer
+
+
+
+ Bases: Tokenizer
Represents a tokenizer for models in the transformers
library.
outlines/models/transformers.py
get_llama_tokenizer_types()
+
+Get all the Llama tokenizer types/classes that need work-arounds.
+When they can't be imported, a dummy class is created.
+ +outlines/models/transformers.py
transformers(model_name, device=None, model_kwargs={}, tokenizer_kwargs={})
+
+Instantiate a model from the transformers
library and its tokenizer.
model_name
+ The name of the model as listed on Hugging Face's model page.
+device
+ The device(s) on which the model should be loaded. This overrides
+ the device_map
entry in model_kwargs
when provided.
+model_kwargs
+ A dictionary that contains the keyword arguments to pass to the
+ from_pretrained
method when loading the model.
+tokenizer_kwargs
+ A dictionary that contains the keyword arguments to pass to the
+ from_pretrained
method when loading the tokenizer.
A TransformersModel
model instance.
outlines/models/transformers.py
Integration with OpenAI's API.
+ + + +OpenAI
+
+
+An object that represents the OpenAI API.
+ +outlines/models/openai.py
74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 |
|
__call__(prompt, max_tokens=None, *, temperature=1.0, samples=1, stop_at=None)
+
+Call the OpenAI API to generate text.
+prompt + A string or list of strings that will be used to prompt the model +max_tokens + The maximum number of tokens to generate +temperature + The value of the temperature used to sample tokens +samples + The number of completions to generate for each prompt +stop_at + Up to 4 words where the API will stop the completion.
+ +outlines/models/openai.py
__init__(model_name, api_key=None, max_retries=6, timeout=None, system_prompt=None, config=None)
+
+Create an OpenAI
instance.
model_name
+ Model to use, as defined in OpenAI's documentation
+api_key
+ Secret key to use with the OpenAI API. One can also set the
+ OPENAI_API_KEY
environment variable, or the value of
+ openai.api_key
.
+max_retries
+ The maximum number of retries when calls to the API fail.
+timeout
+ Duration after which the request times out.
+system_prompt
+ The content of the system message that precedes the user's prompt.
+config
+ An instance of OpenAIConfig
. Can be useful to specify some
+ parameters that cannot be set by calling this class' methods.
outlines/models/openai.py
77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 |
|
generate_choice(prompt, choices, max_tokens=None)
+
+Call the OpenAI API to generate one of several choices.
+prompt + A string or list of strings that will be used to prompt the model +choices + The list of strings between which we ask the model to choose +max_tokens + The maximum number of tokens to generate
+ +outlines/models/openai.py
184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 |
|
OpenAIConfig
+
+
+
+ dataclass
+
+
+Represents the parameters of the OpenAI API.
+The information was last fetched on 2023/11/20. We document below the +properties that are specific to the OpenAI API. Not all these properties are +supported by Outlines.
+model_name
+ The name of the model. Available models can be found on OpenAI's website.
+frequence_penalty
+ Number between 2.0 and -2.0. Positive values penalize new tokens based on
+ their existing frequency in the text,
+logit_bias
+ Modifies the likelihood of specified tokens to appear in the completion.
+ Number between -100 (forbid) and +100 (only allows).
+n
+ The number of completions to return for each prompt.
+presence_penalty
+ Similar to frequency penalty.
+response_format
+ Specifies the format the model must output. {"type": "json_object"}
+ enables JSON mode.
+seed
+ Two completions with the same seed
value should return the same
+ completion. This is however not guaranteed.
+stop
+ Up to 4 words where the API will stop the completion.
+temperature
+ Number between 0 and 2. Higher values make the output more random, while
+ lower values make it more deterministic.
+top_p
+ Number between 0 and 1. Parameter for nucleus sampling.
+user
+ A unique identifier for the end-user.
outlines/models/openai.py
build_optimistic_mask(transposed, max_mask_size=300)
+
+We build the largest mask possible.
+Tokens are added from left to right, so if the encoded choices are e.g.
+[[1,2], [3,4]]
, 1
and 3
will be added before 2
and 4
.
transposed + A list of lists that contain the nth token of each choice.
+ +outlines/models/openai.py
error_handler(api_call_fn)
+
+Handle OpenAI API errors and missing API key.
+ +outlines/models/openai.py
find_longest_intersection(response, choice)
+
+Find the longest intersection between the response and the choice.
+ +outlines/models/openai.py
find_response_choices_intersection(response, choices)
+
+Find the longest intersection between the response and the different +choices.
+Say the response is of the form [1, 2, 3, 4, 5]
and we have the choices
+[[1, 2], [1, 2, 3], [6, 7, 8]
then the function will return [1, 2, 3]
as the
+intersection, and [[]]
as the list of choices left.
response + The model's response +choices + The remaining possible choices
+A tuple that contains the longest intersection between the response and the +different choices, and the choices which start with this intersection, with the +intersection removed.
+ +outlines/models/openai.py
generate_chat(prompt, system_prompt, client, config)
+
+
+ async
+
+
+Call OpenAI's Chat Completion API.
+prompt
+ The prompt we use to start the generation. Passed to the model
+ with the "user" role.
+system_prompt
+ The system prompt, passed to the model with the "system" role
+ before the prompt.
+client
+ The API client
+config
+ An OpenAIConfig
instance.
A tuple that contains the model's response(s) and usage statistics.
+ +outlines/models/openai.py
PartialIndenter
+
+
+
+ Bases: Indenter
An Indenter
that doesn't reset its state every time process
is called.
outlines/text/parsing.py
PartialParserState
+
+
+
+ Bases: ParserState
outlines/text/parsing.py
345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 +425 +426 +427 +428 +429 +430 +431 +432 +433 +434 +435 +436 +437 +438 +439 +440 +441 +442 +443 +444 +445 +446 +447 +448 +449 +450 +451 +452 +453 +454 +455 +456 +457 +458 +459 |
|
feed_token_no_stack(token, is_end=False)
+
+This is a copy of ParserState.feed_token
with all the value stack
+steps removed. Since we're not exactly parsing in order to obtain a
+CST or anything similar, we can avoid the growing expense of tracking
+the parse tree.
outlines/text/parsing.py
PartialParsingFrontend
+
+
+
+ Bases: ParsingFrontend
outlines/text/parsing.py
161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 |
|
PartialScanner
+
+
+
+ Bases: Scanner
outlines/text/parsing.py
511 +512 +513 +514 +515 +516 +517 +518 +519 +520 +521 +522 +523 +524 +525 +526 +527 +528 +529 +530 +531 +532 +533 +534 +535 +536 +537 +538 +539 +540 +541 +542 +543 +544 +545 +546 +547 +548 +549 +550 +551 +552 +553 +554 +555 +556 +557 +558 +559 +560 +561 +562 +563 +564 +565 +566 +567 +568 +569 +570 +571 +572 +573 +574 +575 +576 +577 +578 +579 +580 +581 +582 +583 +584 +585 +586 +587 |
|
get_terminals_info(fsm_state_seq)
+
+Get the possible terminal symbols for an FSM state sequence.
+ +outlines/text/parsing.py
match(text, pos, last_fsm_state_seq=None)
+
+Determine an FSM match over text
starting at pos
and continuing last_fsm_state_seq
.
outlines/text/parsing.py
terminals_to_fsms(lp)
+
+Construct a dict
mapping terminal symbol names to their finite state machines.
outlines/text/parsing.py
Prompt
+
+
+
+ dataclass
+
+
+Represents a prompt function.
+We return a Prompt
class instead of a simple function so the
+template defined in prompt functions can be accessed.
outlines/text/prompts.py
__call__(*args, **kwargs)
+
+Render and return the template.
+The rendered template as a Python str
.
outlines/text/prompts.py
get_fn_description(fn)
+
+Returns the first line of a callable's docstring.
+ +outlines/text/prompts.py
get_fn_name(fn)
+
+Returns the name of a callable.
+ +outlines/text/prompts.py
get_fn_signature(fn)
+
+Return the signature of a callable.
+ +outlines/text/prompts.py
get_fn_source(fn)
+
+Return the source code of a callable.
+ +outlines/text/prompts.py
get_schema_dict(model)
+
+get_schema_pydantic(model)
+
+Return the schema of a Pydantic model.
+ +outlines/text/prompts.py
parse_pydantic_schema(raw_schema, definitions)
+
+Parse the output of Basemodel.[schema|model_json_schema]()
.
This recursively follows the references to other schemas in case +of nested models. Other schemas are stored under the "definitions" +key in the schema of the top-level model.
+ +outlines/text/prompts.py
prompt(fn)
+
+Decorate a function that contains a prompt template.
+This allows to define prompts in the docstring of a function and simplify their
+manipulation by providing some degree of encapsulation. It uses the render
+function internally to render templates.
++++++import outlines
+@outlines.prompt +def build_prompt(question): +... "I have a ${question}" +... +prompt = build_prompt("How are you?")
+
This API can also be helpful in an "agent" context where parts of the prompt +are set when the agent is initialized and never modified later. In this situation +we can partially apply the prompt function at initialization.
+++++++import outlines +import functools as ft +... +@outlines.prompt +... def solve_task(name: str, objective: str, task: str): +... '''Your name is {{name}}. +.. Your overall objective is to {{objective}}. +... Please solve the following task: {{task}} +... ''' +... +hal = ft.partial(solve_taks, "HAL", "Travel to Jupiter")
+
A Prompt
callable class which will render the template when called.
outlines/text/prompts.py
render(template, **values)
+
+Parse a Jinaj2 template and translate it into an Outlines graph.
+This function removes extra whitespaces and linebreaks from templates to +allow users to enter prompts more naturally than if they used Python's +constructs directly. See the examples for a detailed explanation.
+Outlines follow Jinja2's syntax
+++++++import outlines +outline = outlines.render("I like {{food}} and {{sport}}", food="tomatoes", sport="tennis") +I like tomatoes and tennis
+
If the first line of the template is empty, render
removes it
++++++from outlines import render
+tpl = ''' +... A new string''' +tpl +... '\nA new string' +render(tpl) +... 'a new string'
+
Similarly, render
ignores linebreaks introduced by placing the closing quotes
+underneath the text:
++++++tpl = ''' +... A new string +... ''' +tpl +... '\nA new string\n' +render(tpl) +... 'A new string'
+
If you want to insert a linebreak at the end of the rendered template, you will +need to leave an empty line at the end of the template:
+++++++tpl = ''' +... A new string +... +... ''' +tpl +... '\nA new string\n\n' +render(tpl) +... 'A new string\n'
+
render
removes the identation in docstrings. This is particularly important
+when using prompt functions
++++++tpl = ''' +... a string +... and another string''' +tpl +... '\n a string\n and another string' +render(tpl) +... 'a string\nand another string'
+
The indentation of the first line is assumed to be the same as the second line's
+++++++tpl = '''a string +... and another''' +tpl +... 'a string\n and another' +render(tpl) +... 'a string\nand another'
+
To get a different indentation for the first and the second line, we can start the +prompt on the string's second line:
+++++++tpl = ''' +... First line +... Second line''' +render(tpl) +... 'First Line\n Second Line'
+
template + A string that contains a template written with the Jinja2 syntax. +**values + Map from the variables in the template to their value.
+A string that contains the rendered template.
+ +outlines/text/prompts.py
94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 |
|
Regex
+
+
+
+ Bases: Continuation
Represents a regex-based generation model.
+Regex
instances are constrained generation models that only generate
+sequences matching a given regex.
++++++import outlines.text as text +generator = text.generate.regex(model, "(0|[1-9][0-9]+)")
+
Sequences can then be generated from a prompt as follows:
+++++++sequence_1 = generator("Return an integer between 0 and 10") +sequence_2 = generator("Rate the movie "Hackers" on a scale from 0 to 10")
+
.. note:
+ Reuse instances of these guided generators (e.g. generator
from the
+ above example) whenever possible, because constructing them has more
+ overhead than generating token sequences from them.
outlines/text/generate/regex.py
18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 |
|
__init__(model, regex_string, max_tokens=None, *, sampler=None, stop=[], allow_empty_tokens=True, initial_state=None, final_states=None, states_to_token_maps=None, empty_token_ids=None, format_fn=lambda : x)
+
+model
+ The instance of the model used to generate next-token probabilities.
+regex_string
+ The regex with which the token sampling process is guided/constrained.
+max_tokens
+ The maximum number of tokens to be sampled.
+sampler
+ The function used to draw samples. Defaults to
+ outlines.text.generate.sample.multinomial
. See
+ outlines.text.generate.sample.Sampler
for the expected form of
+ such functions.
+stop
+ Optional stopping string(s).
+allow_empty_tokens
+ Allow sampling of tokens corresponding to empty strings.
+states_to_token_maps
+ Pre-computed map of FSM start states to maps between token ids and their
+ corresponding FSM end states.
+empty_token_ids
+ Pre-computed set of token ids for tokens that are empty strings.
+format_fn
+ The function to apply to the generated JSON.
outlines/text/generate/regex.py
39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 |
|
create_proposal(generated_token_ids, logits)
+
+Modify the next-token logits so that only valid tokens can be generated.
+generated_token_ids + The token ids generated so far. +logits + The next-token logits.
+ +outlines/text/generate/regex.py
122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 |
|
choice(model, choices, max_tokens=None, *, sampler=None, allow_empty_tokens=True)
+
+Choose between different sequences.
+.. note:
+ Reuse instances of these guided generators whenever possible,
+ because constructing them has more overhead than generating
+ token sequences from them. See the docstring for Regex
.
model
+ The language model to use to compute the next-token logits.
+max_tokens
+ The maximum number of tokens to generate.
+sampler
+ The function used to draw samples. Defaults to
+ outlines.text.generate.sample.multinomial
. See
+ outlines.text.generate.sample.Sampler
for the expected form of
+ such functions.
+allow_empty_tokens
+ Allow sampling of tokens corresponding to empty strings.
outlines/text/generate/regex.py
format(model, python_type, max_tokens=None, *, sampler=None, allow_empty_tokens=True)
+
+Generate integers.
+The regex used to constrain the generation optionally matches plus or minus
+signs and forbids leading zeros (even if the int
function in Python allows
+them).
.. note:
+ Reuse instances of these guided generators whenever possible,
+ because constructing them has more overhead than generating
+ token sequences from them. See the docstring for Regex
.
model
+ The language model to use to compute the next-token logits.
+python_type
+ The format in which the output is expected, defined as a Python type.
+max_tokens
+ The maximum number of tokens to generate.
+sampler
+ The function used to draw samples. Defaults to
+ outlines.text.generate.sample.multinomial
. See
+ outlines.text.generate.sample.Sampler
for the expected form of
+ such functions.
+allow_empty_tokens
+ Allow sampling of tokens corresponding to empty strings.
outlines/text/generate/regex.py
json(model, schema_object, max_tokens=None, *, sampler=None, allow_empty_tokens=True)
+
+Generate a text sequence that follows a JSON schema or Pydantic model.
+.. note:
+ Reuse instances of these guided generators whenever possible,
+ because constructing them has more overhead than generating
+ token sequences from them. See the docstring for Regex
.
model
+ The language model to use to compute the next-token logits.
+schema
+ The JSON schema, Pydantic model or function (signature) that guides the
+ generation.
+max_tokens
+ The maximum number of tokens to generate.
+sampler
+ The function used to draw samples. Defaults to
+ outlines.text.generate.sample.multinomial
. See
+ outlines.text.generate.sample.Sampler
for the expected form of
+ such functions.
+allow_empty_tokens
+ Allow sampling of tokens corresponding to empty strings.
outlines/text/generate/regex.py
regex(model, regex_string, max_tokens=None, *, sampler=None, allow_empty_tokens=True)
+
+Generate text sequences that match the input regex.
+.. note:
+ Reuse instances of these guided generators whenever possible,
+ because constructing them has more overhead than generating
+ token sequences from them. See the docstring for Regex
.
model
+ The language model to use to compute the next-token logits.
+regex_string
+ The regular expression that generated expressions must match.
+max_tokens
+ The maximum number of tokens to generate.
+sampler
+ The function used to draw samples. Defaults to
+ outlines.text.generate.sample.multinomial
. See
+ outlines.text.generate.sample.Sampler
for the expected form of
+ such functions.
+allow_empty_tokens
+ Allow sampling of tokens corresponding to empty strings.
outlines/text/generate/regex.py
greedy(logits, samples, *_)
+
+Greedy Sampling algorithm.
+Greedy sampling consists in choosing the token with the largest +likelihood at every step.
+logits
+ A tensor of shape (n_seqs, vocab_size,)
that represents the
+ probability distribution of the next token over the vocabulary.
+samples
+ The number of sequences to produce. In this case, the top-samples
+ logit values are returned.
+rng
+ A random number generator.
The ids of the sampled tokens having shape (samples, n_seqs)
.
outlines/text/generate/sample.py
multinomial(logits, samples, rng)
+
+Multinomial sampling algorithm.
+Multinomial sampling consists in randomly sampling the next token assuming +its distribution is a Categorical distribution parametrized by the +next-token logits.
+logits
+ A tensor of shape (n_seqs, vocab_size,)
that represents the
+ probability distribution of the next token over the vocabulary.
+samples
+ The number of sequences to sample.
+rng
+ A random number generator.
The ids of the sampled tokens having shape (samples, n_seqs)
.
outlines/text/generate/sample.py
vectorized_random_choice(rng, p, samples=1)
+
+Vectorized implementation of np.random.choice
.
np.random.choice
does not support arrays of probability. This implements
+the equivalent of this function where the p
argument can be a matrix.
torch.searchsorted
may be more efficient, but it is not implemented for
+every backend, for instance MPS.
rng
+ Torch random number Generator instance
+p
+ An array of probability of shape (num_probability_vectors, num_items)
+ that must sum to 1.
+samples
+ The number of samples to take for each probability vector.
An array of shape (num_samples, batch_size)
outlines/text/generate/sample.py