genai package#
- class genai.ApiClient[source]#
Bases:
object
Class which provides methods for making API requests. It provides methods for obtaining synchronous and asynchronous HTTP clients.
- Config#
alias of
BaseConfig
- __init__(*, credentials, config=None)[source]#
- Parameters:
credentials (Credentials) –
config (dict | BaseConfig | None) –
- get_async_http_client(rate_limit_options=None, retry_options=None, client_options=None, **kwargs)[source]#
Gets cached instance of AsyncHttpxClient (cache key is created from provided parameters).
- Raises:
ValueError – If both rate_limit_options and retry_options are provided.
RuntimeError – If the method is not called within an asynchronous environment.
- Parameters:
rate_limit_options (dict | None) –
retry_options (dict | None) –
client_options (dict | None) –
- Return type:
AsyncHttpxClient
- class genai.Client[source]#
Bases:
BaseService
[BaseConfig
,BaseServices
]The Client class provides an interface for interacting with various services through an API client. It can be initialized with either an api_client or credentials along with optional configurations and services.
Example:
from genai import Credentials, Client credentials = Credentials.from_env() client = Client(credentials=credentials)
- text#
An instance of the TextService class for text-related operations.
- request#
An instance of the RequestService class for making request-related operations.
- tune#
An instance of the TuneService class for tuning models.
- model#
An instance of the ModelService class for managing models.
- file#
An instance of the FileService class for managing files.
- prompt#
An instance of the PromptService class for working with prompts.
- system_prompt#
An instance of the SystemPromptService class for working with system prompts.
- user#
An instance of the UserService class for managing user-related operations.
- tag#
An instance of the TagService class for working with tags.
- folder#
An instance of the FolderService class for working with folder.
- task#
An instance of the TaskService class for working with tasks.
- Config#
alias of
BaseConfig
- Services#
alias of
BaseServices
- __init__(*, api_client: ApiClient, config: dict | BaseConfig | None = None, services: BaseServices | None = None) None [source]#
- __init__(*, credentials: Credentials, config: dict | BaseConfig | None = None, services: BaseServices | None = None) None
- Parameters:
credentials – The credentials used to authenticate the API client.
api_client – The API client used to make requests to the API.
config – The configuration for the API client.
services – The services object containing instances of various service classes.
- Raises:
ValueError – Either ‘api_client’ or ‘credentials’ needs to be passed.
Note
The api_client parameter must be provided either directly or through credentials. If no services parameter is provided, the client will use the default one.
- pydantic model genai.Credentials[source]#
Bases:
BaseModel
The Credentials class represents credentials required for accessing the GENAI API.
- - `api_key`
API key which can be retrieved from the UI.
- - `api_endpoint`
A string representing the GENAI API endpoint (default is BAM).
- Type:
optional
Examples
Create a Credentials instance with explicit api_endpoint:
credentials = Credentials(api_key="your_api_key", api_endpoint="https://bam-api.res.ibm.com")
Create a Credentials instance with default api_endpoint:
credentials = Credentials(api_key="your_api_key")
Create a Credentials instance from environment variables:
credentials = Credentials.from_env()
- Validators:
_validate_api_endpoint
»api_endpoint
- field api_endpoint: str [Required]#
GENAI API Endpoint
- Constraints:
min_length = 1
- Validated by:
_validate_api_endpoint
- field api_key: SecretStr [Required]#
The GENAI API Key
- __init__(api_key, api_endpoint=None, **kwargs)[source]#
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
api_key (str) –
api_endpoint (str | None) –
Subpackages#
- genai.deployment package
- genai.extensions package
- genai.file package
- genai.folder package
- genai.model package
- genai.prompt package
- genai.request package
- genai.schema package
AIMessage
ApiEndpoint
ApiKeyRegenerateCreateEndpoint
ApiKeyRegenerateCreateResponse
ApiKeyResult
ApiKeyRetrieveEndpoint
ApiKeyRetrieveResponse
BadRequestResponse
BaseErrorExtension
BaseErrorResponse
BaseMessage
BaseTokens
ChatRole
ConcurrencyLimit
DecodingMethod
DeploymentCreateEndpoint
DeploymentCreateResponse
DeploymentIdDeleteEndpoint
DeploymentIdRetrieveEndpoint
DeploymentIdRetrieveResponse
DeploymentResult
DeploymentRetrieveEndpoint
DeploymentRetrieveResponse
DeploymentStatus
EvaluationCreateEndpoint
EvaluationCreateResponse
EvaluationExperiment
EvaluationExperimentCreateEndpoint
EvaluationExperimentCreateResponse
EvaluationExperimentIdDeleteEndpoint
EvaluationExperimentIdRetrieveEndpoint
EvaluationExperimentIdRetrieveResponse
EvaluationExperimentRetrieveEndpoint
EvaluationExperimentRetrieveResponse
EvaluationExperimentSortBy
EvaluationFieldOperation
EvaluationFile
EvaluationIdDeleteEndpoint
EvaluationIdInstanceResultRetrieveEndpoint
EvaluationIdInstanceResultRetrieveResponse
EvaluationIdRetrieveEndpoint
EvaluationIdRetrieveResponse
EvaluationInstanceResult
EvaluationLimit
EvaluationLimitRetrieveEndpoint
EvaluationLimitRetrieveResponse
EvaluationOperationType
EvaluationParentTask
EvaluationPreviewCreateEndpoint
EvaluationPreviewCreateResponse
EvaluationPrompt
EvaluationResult
EvaluationResult.created_at
EvaluationResult.description
EvaluationResult.experiment_id
EvaluationResult.file
EvaluationResult.finished_at
EvaluationResult.id
EvaluationResult.model_id
EvaluationResult.name
EvaluationResult.parameters
EvaluationResult.prompt
EvaluationResult.result
EvaluationResult.started_at
EvaluationResult.status
EvaluationResult.status_message
EvaluationResult.task_id
EvaluationResult.template_id
EvaluationResult.template_name
EvaluationRetrieveEndpoint
EvaluationRetrieveResponse
EvaluationSortBy
EvaluationStatus
EvaluationTask
EvaluationTemplate
EvaluationTemplateIdRetrieveEndpoint
EvaluationTemplateIdRetrieveResponse
EvaluationTemplateRetrieveEndpoint
EvaluationTemplateRetrieveResponse
Extensions
Extensions1
Extensions2
Extensions3
Extensions4
Extensions5
FileCreateEndpoint
FileCreateResponse
FileDescendant
FileFormat
FileIdContentRetrieveEndpoint
FileIdDeleteEndpoint
FileIdPatchEndpoint
FileIdPatchResponse
FileIdRetrieveEndpoint
FileIdRetrieveResponse
FileListSortBy
FileMetadata
FileMetadataStats
FilePurpose
FileResult
FileRetrieveEndpoint
FileRetrieveResponse
FolderCreateEndpoint
FolderCreateResponse
FolderIdDeleteEndpoint
FolderIdPatchEndpoint
FolderIdPatchResponse
FolderIdRetrieveEndpoint
FolderIdRetrieveResponse
FolderIdUpdateEndpoint
FolderIdUpdateResponse
FolderResult
FolderRetrieveEndpoint
FolderRetrieveResponse
GeneratedToken
HAPOptions
HumanMessage
Input
InternalServerErrorResponse
LengthPenalty
MessageFile
Metric
Metrics
ModelFacet
ModelFacetType
ModelFamily
ModelIdRetrieveEndpoint
ModelIdRetrieveResponse
ModelIdRetrieveResult
ModelIdRetrieveResult.description
ModelIdRetrieveResult.developer
ModelIdRetrieveResult.disabled
ModelIdRetrieveResult.facets
ModelIdRetrieveResult.id
ModelIdRetrieveResult.is_live
ModelIdRetrieveResult.label
ModelIdRetrieveResult.model_family
ModelIdRetrieveResult.name
ModelIdRetrieveResult.preferred
ModelIdRetrieveResult.prompt_builder_example
ModelIdRetrieveResult.size
ModelIdRetrieveResult.source_model_id
ModelIdRetrieveResult.system_prompt
ModelIdRetrieveResult.system_prompt_id
ModelIdRetrieveResult.tags
ModelIdRetrieveResult.tasks
ModelIdRetrieveResult.token_limits
ModelIdRetrieveResult.warning
ModelRetrieveEndpoint
ModelRetrieveResponse
ModelRetrieveResults
ModelTokenLimits
ModelType
ModerationHAP
ModerationHAPInput
ModerationHAPOutput
ModerationImplicitHate
ModerationImplicitHateInput
ModerationImplicitHateOutput
ModerationParameters
ModerationPosition
ModerationSocialBias
ModerationSocialBiasInput
ModerationSocialBiasOutput
ModerationStigma
ModerationStigmaInput
ModerationStigmaOutput
ModerationTokens
NotFoundResponse
PromptCreateEndpoint
PromptCreateResponse
PromptIdDeleteEndpoint
PromptIdPatchEndpoint
PromptIdPatchResponse
PromptIdRetrieveEndpoint
PromptIdRetrieveResponse
PromptIdUpdateEndpoint
PromptIdUpdateResponse
PromptListSortBy
PromptListSource
PromptModerationParameters
PromptResult
PromptResult.author
PromptResult.created_at
PromptResult.data
PromptResult.description
PromptResult.folder_id
PromptResult.id
PromptResult.input
PromptResult.messages
PromptResult.metadata
PromptResult.model_id
PromptResult.moderations
PromptResult.name
PromptResult.output
PromptResult.parameters
PromptResult.prompt_id
PromptResult.public
PromptResult.tags
PromptResult.task
PromptResult.type
PromptResult.updated_at
PromptResult.usage_count
PromptResultAuthor
PromptResultTask
PromptRetrieveEndpoint
PromptRetrieveResponse
PromptTag
PromptTagType
PromptTemplateData
PromptType
RequestApiVersion
RequestChatConversationIdDeleteEndpoint
RequestChatConversationIdRetrieveEndpoint
RequestChatConversationIdRetrieveResponse
RequestChatConversationIdRetrieveResults
RequestChatConversationIdRetrieveResults.created_at
RequestChatConversationIdRetrieveResults.duration
RequestChatConversationIdRetrieveResults.id
RequestChatConversationIdRetrieveResults.parent_id
RequestChatConversationIdRetrieveResults.request
RequestChatConversationIdRetrieveResults.response
RequestChatConversationIdRetrieveResults.status
RequestChatConversationIdRetrieveResults.version
RequestChatConversationIdRetrieveResultsRequest
RequestChatConversationIdRetrieveResultsResponse
RequestEndpoint
RequestFeedbackCategory
RequestFeedbackCategory.CORRECT_CONTENT
RequestFeedbackCategory.CORRECT_STYLE
RequestFeedbackCategory.INACCURATE
RequestFeedbackCategory.KNOWLEDGE_GAP
RequestFeedbackCategory.NOT_RELEVANT
RequestFeedbackCategory.OFFENSIVE_HARMFUL
RequestFeedbackCategory.OTHER_CONTENT
RequestFeedbackCategory.OTHER_STYLE
RequestFeedbackCategory.TOO_LONG
RequestFeedbackCategory.TOO_SHORT
RequestFeedbackCategory.WRONG_FORMAT
RequestFeedbackCategory.WRONG_TONE
RequestFeedbackResult
RequestFeedbackVote
RequestIdDeleteEndpoint
RequestIdFeedbackCreateEndpoint
RequestIdFeedbackCreateResponse
RequestIdFeedbackRetrieveEndpoint
RequestIdFeedbackRetrieveResponse
RequestIdFeedbackUpdateEndpoint
RequestIdFeedbackUpdateResponse
RequestOrigin
RequestResultVersion
RequestRetrieveEndpoint
RequestRetrieveResponse
RequestRetrieveResults
RequestStatus
SocialBiasOptions
SortDirection
StopReason
StorageProviderLocation
SystemMessage
SystemPrompt
SystemPromptAuthor
SystemPromptCreateEndpoint
SystemPromptCreateResponse
SystemPromptIdDeleteEndpoint
SystemPromptIdRetrieveEndpoint
SystemPromptIdRetrieveResponse
SystemPromptIdUpdateEndpoint
SystemPromptIdUpdateResponse
SystemPromptRetrieveEndpoint
SystemPromptRetrieveResponse
SystemPromptType
Tag
TagRetrieveEndpoint
TagRetrieveResponse
TagType
TaskRetrieveEndpoint
TaskRetrieveResponse
Tasks
TextChatCreateEndpoint
TextChatCreateResponse
TextChatGenerationStreamResult
TextChatGenerationStreamResult.generated_text
TextChatGenerationStreamResult.generated_token_count
TextChatGenerationStreamResult.generated_tokens
TextChatGenerationStreamResult.input_text
TextChatGenerationStreamResult.input_token_count
TextChatGenerationStreamResult.input_tokens
TextChatGenerationStreamResult.seed
TextChatGenerationStreamResult.stop_reason
TextChatGenerationStreamResult.stop_sequence
TextChatOutputCreateEndpoint
TextChatOutputCreateResponse
TextChatStreamCreateEndpoint
TextChatStreamCreateResponse
TextClassificationCreateData
TextClassificationCreateEndpoint
TextClassificationCreateResponse
TextClassificationResult
TextClassificationType
TextCreateResponseModeration
TextEmbeddingCreateEndpoint
TextEmbeddingCreateResponse
TextEmbeddingLimit
TextEmbeddingLimitRetrieveEndpoint
TextEmbeddingLimitRetrieveResponse
TextEmbeddingParameters
TextExtractionLimitRetrieveEndpoint
TextGenerationComparisonCreateEndpoint
TextGenerationComparisonCreateRequestRequest
TextGenerationComparisonCreateRequestRequest.data
TextGenerationComparisonCreateRequestRequest.input
TextGenerationComparisonCreateRequestRequest.model_id
TextGenerationComparisonCreateRequestRequest.moderations
TextGenerationComparisonCreateRequestRequest.parameters
TextGenerationComparisonCreateRequestRequest.prompt_id
TextGenerationComparisonCreateRequestRequest.use_default
TextGenerationComparisonCreateResponse
TextGenerationComparisonCreateResults
TextGenerationComparisonCreateResultsParameters
TextGenerationComparisonCreateResultsParameters.length_penalty
TextGenerationComparisonCreateResultsParameters.model_id
TextGenerationComparisonCreateResultsParameters.repetition_penalty
TextGenerationComparisonCreateResultsParameters.temperature
TextGenerationComparisonCreateResultsParameters.top_k
TextGenerationComparisonCreateResultsParameters.top_p
TextGenerationComparisonCreateResultsParameters.typical_p
TextGenerationComparisonCreateResultsResult
TextGenerationComparisonParameters
TextGenerationComparisonParameters.length_penalty
TextGenerationComparisonParameters.model_id
TextGenerationComparisonParameters.repetition_penalty
TextGenerationComparisonParameters.temperature
TextGenerationComparisonParameters.top_k
TextGenerationComparisonParameters.top_p
TextGenerationComparisonParameters.typical_p
TextGenerationCreateEndpoint
TextGenerationCreateResponse
TextGenerationFeedbackCategory
TextGenerationFeedbackCategory.CORRECT_CONTENT
TextGenerationFeedbackCategory.CORRECT_STYLE
TextGenerationFeedbackCategory.INACCURATE
TextGenerationFeedbackCategory.KNOWLEDGE_GAP
TextGenerationFeedbackCategory.NOT_RELEVANT
TextGenerationFeedbackCategory.OFFENSIVE_HARMFUL
TextGenerationFeedbackCategory.OTHER_CONTENT
TextGenerationFeedbackCategory.OTHER_STYLE
TextGenerationFeedbackCategory.TOO_LONG
TextGenerationFeedbackCategory.TOO_SHORT
TextGenerationFeedbackCategory.WRONG_FORMAT
TextGenerationFeedbackCategory.WRONG_TONE
TextGenerationFeedbackResult
TextGenerationFeedbackResult.api_request
TextGenerationFeedbackResult.categories
TextGenerationFeedbackResult.comment
TextGenerationFeedbackResult.contact_consent
TextGenerationFeedbackResult.created_at
TextGenerationFeedbackResult.id
TextGenerationFeedbackResult.updated_at
TextGenerationFeedbackResult.vote
TextGenerationFeedbackVote
TextGenerationIdFeedbackCreateEndpoint
TextGenerationIdFeedbackCreateResponse
TextGenerationIdFeedbackRetrieveEndpoint
TextGenerationIdFeedbackRetrieveResponse
TextGenerationIdFeedbackUpdateEndpoint
TextGenerationIdFeedbackUpdateResponse
TextGenerationLimit
TextGenerationLimitRetrieveEndpoint
TextGenerationLimitRetrieveResponse
TextGenerationOutputCreateEndpoint
TextGenerationOutputCreateResponse
TextGenerationParameters
TextGenerationParameters.beam_width
TextGenerationParameters.decoding_method
TextGenerationParameters.include_stop_sequence
TextGenerationParameters.length_penalty
TextGenerationParameters.max_new_tokens
TextGenerationParameters.min_new_tokens
TextGenerationParameters.random_seed
TextGenerationParameters.repetition_penalty
TextGenerationParameters.return_options
TextGenerationParameters.stop_sequences
TextGenerationParameters.temperature
TextGenerationParameters.time_limit
TextGenerationParameters.top_k
TextGenerationParameters.top_p
TextGenerationParameters.truncate_input_tokens
TextGenerationParameters.typical_p
TextGenerationResult
TextGenerationResult.generated_text
TextGenerationResult.generated_token_count
TextGenerationResult.generated_tokens
TextGenerationResult.input_text
TextGenerationResult.input_token_count
TextGenerationResult.input_tokens
TextGenerationResult.moderations
TextGenerationResult.seed
TextGenerationResult.stop_reason
TextGenerationResult.stop_sequence
TextGenerationReturnOptions
TextGenerationStreamCreateEndpoint
TextGenerationStreamCreateResponse
TextGenerationStreamResult
TextGenerationStreamResult.generated_text
TextGenerationStreamResult.generated_token_count
TextGenerationStreamResult.generated_tokens
TextGenerationStreamResult.input_text
TextGenerationStreamResult.input_token_count
TextGenerationStreamResult.input_tokens
TextGenerationStreamResult.seed
TextGenerationStreamResult.stop_reason
TextGenerationStreamResult.stop_sequence
TextModeration
TextModerationCreateEndpoint
TextModerationCreateResponse
TextRerankCreateEndpoint
TextRerankCreateResponse
TextRerankParameters
TextRerankResult
TextRerankReturnOptions
TextSentenceSimilarityCreateEndpoint
TextSentenceSimilarityCreateResponse
TextSentenceSimilarityCreateResult
TextSentenceSimilarityParameters
TextTokenizationCreateEndpoint
TextTokenizationCreateResponse
TextTokenizationCreateResults
TextTokenizationParameters
TextTokenizationReturnOptions
TimeSerieForecastingCreateEndpoint
TimeSerieForecastingCreateResponse
TimeSerieLimitRetrieveEndpoint
TimeSerieLimitRetrieveResponse
TimeSeriesLimit
TooManyRequestsResponse
TrimMethod
TuneAssetType
TuneCreateEndpoint
TuneCreateResponse
TuneFromFileCreateEndpoint
TuneFromFileCreateResponse
TuneIdContentRetrieveEndpoint
TuneIdContentTypeRetrieveEndpoint
TuneIdDeleteEndpoint
TuneIdPatchEndpoint
TuneIdPatchResponse
TuneIdRetrieveEndpoint
TuneIdRetrieveResponse
TuneListSortBy
TuneParameters
TunePreflightCreateEndpoint
TunePreflightCreateResponse
TuneResult
TuneResult.contents
TuneResult.created_at
TuneResult.datapoints
TuneResult.evaluation_files
TuneResult.finished_at
TuneResult.id
TuneResult.last_used_at
TuneResult.model_id
TuneResult.model_name
TuneResult.name
TuneResult.parameters
TuneResult.preferred
TuneResult.started_at
TuneResult.status
TuneResult.status_message
TuneResult.task_id
TuneResult.task_name
TuneResult.training_files
TuneResult.tuning_type
TuneResult.validation_files
TuneResult.vectors
TuneResultContent
TuneResultDatapoint
TuneResultDatapointLossData
TuneResultDatapointValidationLoss
TuneResultDatapointValidationLossData
TuneResultFiles
TuneRetrieveEndpoint
TuneRetrieveResponse
TuneStatus
TunesResultDatapointLoss
TuningTypeRetrieveEndpoint
TuningTypeRetrieveResponse
TuningTypeRetrieveResults
UnauthorizedResponse
UnavailableResponse
UserApiKey
UserCreateEndpoint
UserCreateResponse
UserCreateResult
UserDeleteEndpoint
UserGenerationDefault
UserPatchEndpoint
UserPatchResponse
UserResult
UserRetrieveEndpoint
UserRetrieveResponse
- genai.system_prompt package
- genai.tag package
- genai.task package
- genai.text package
- genai.tune package
- genai.user package
Submodules#
- genai.client module
BaseConfig
BaseServices
BaseServices.DeploymentService
BaseServices.FileService
BaseServices.FolderService
BaseServices.ModelService
BaseServices.PromptService
BaseServices.RequestService
BaseServices.SystemPromptService
BaseServices.TagService
BaseServices.TaskService
BaseServices.TextService
BaseServices.TuneService
BaseServices.UserService
Client
- genai.credentials module
- genai.exceptions module
- genai.utils module