oarepo_config.llm
oarepo_config.llm
Configuration for oarepo-checks.
configure_llm(api_token: str | None = None, *, enabled: bool = True, client_name: str = OAREPO_CHECKS_DEFAULT_CHAT_EINFRA_CLIENT, api_url: str = 'https://llm.ai.e-infra.cz/v1/chat/completions', model: str = 'nrp', fallback_community: str | None = None, as_default: bool = True) -> None
Set up the LLM client(s) used by oarepo-checks' AI-assisted record validation.
oarepo-checks can validate a record's metadata by sending it to a
Large Language Model and checking the response (its "llm" check,
shown to users as "AI validation") before a record may be published.
This registers one such LLM client (built-in support is for
chat.ai.e-infra.cz) that the check can use.
Call it once per LLM client/token you want available - each call reads
back and extends whatever a previous call already registered (via
get_constant_from_caller), it does not replace it. This also
means, when calling it more than once, that whichever call has
as_default=True last wins as the default client.
Requires the optional oarepo-checks package to be installed;
without it, calling this raises an ImportError explaining that the
package needs to be installed first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_token
|
str | None
|
Bearer token for the |
None
|
enabled
|
bool
|
Set to |
True
|
client_name
|
str
|
The key this client is registered under in
|
OAREPO_CHECKS_DEFAULT_CHAT_EINFRA_CLIENT
|
api_url
|
str
|
The |
'https://llm.ai.e-infra.cz/v1/chat/completions'
|
model
|
str
|
The model name the |
'nrp'
|
fallback_community
|
str | None
|
Slug of the community used for checks that
aren't tied to a specific community. If given, overrides
whatever a previous call already set; if not given, an
already-set value is kept, defaulting to
|
None
|
as_default
|
bool
|
Mark |
True
|
Invenio configuration variables set:
CHECKS_ENABLED- theenabledargument above.OAREPO_CHECKS_LLM_CLIENTS- only ifenabled; extended (not replaced) with aChatEInfraCliententry underclient_name, only ifapi_tokenwas given.OAREPO_CHECKS_DEFAULT_LLM_CLIENT- only ifenabledandas_default; set toclient_name.CHECKS_GENERIC_COMMUNITY- only ifenabled;fallback_communityif given, else an already-set value, else"llm-settings-community".
Example
Source code in oarepo_config/llm.py
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |