LLM Mesh Core#
This page groups the native LLM Mesh objects and query/response builders around the main DSSLLM entry point.
Core objects#
- class dataikuapi.dss.llm.DSSLLM(client, project_key, llm_id)#
A handle to interact with a DSS-managed LLM.
Important
Do not create this class directly, use
dataikuapi.dss.project.DSSProject.get_llm()instead.- new_completion()#
Create a new completion query.
- Returns:
A handle on the generated completion query.
- Return type:
- new_completions()#
Create a new multi-completion query.
- Returns:
A handle on the generated multi-completion query.
- Return type:
- new_embeddings(text_overflow_mode='FAIL')#
Create a new embedding query.
- Parameters:
text_overflow_mode (str) – How to handle longer texts than what the model supports. Either ‘TRUNCATE’ or ‘FAIL’.
- Returns:
A handle on the generated embeddings query.
- Return type:
- new_images_generation()#
- new_reranking()#
Create a new reranking query.
- Returns:
A handle on the generated reranking query.
- Return type:
- as_langchain_llm(**data)#
Create a langchain-compatible LLM object for this LLM.
- Returns:
A langchain-compatible LLM object.
- Return type:
- as_langchain_chat_model(**data)#
Create a langchain-compatible chat LLM object for this LLM.
- Returns:
A langchain-compatible LLM object.
- Return type:
- as_langchain_embeddings(**data)#
Create a langchain-compatible embeddings object for this LLM.
- Returns:
A langchain-compatible embeddings object.
- Return type:
- class dataikuapi.dss.llm.DSSLLMListItem(client, project_key, data)#
An item in a list of llms
Important
Do not instantiate this class directly, instead use
dataikuapi.dss.project.DSSProject.list_llms().- to_llm()#
Convert the current item.
- Returns:
A handle for the llm.
- Return type:
- property id#
- Returns:
The id of the llm.
- Return type:
string
- property type#
- Returns:
The type of the LLM
- Return type:
string
- property description#
- Returns:
The description of the LLM
- Return type:
string
Text generation#
- class dataikuapi.dss.llm.DSSLLMCompletionQuery(llm)#
A handle to interact with a completion query. Completion queries allow you to send a prompt to a DSS-managed LLM and retrieve its response.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLM.new_completion()instead.- property settings#
- Returns:
The completion query settings.
- Return type:
dict
- new_guardrail(type)#
Start adding a guardrail to the request. You need to configure the returned object, and call add() to actually add it
- execute()#
Run the completion query and retrieve the LLM response.
- Returns:
The LLM response.
- Return type:
- execute_streamed(collect_response=False)#
Run the completion query and retrieve the LLM response as streamed chunks.
- Parameters:
collect_response (bool) – If True, the streamed chunks are also aggregated into a consolidated
DSSLLMCompletionResponseby the returned iterator.- Returns:
An iterator over the LLM response chunks
- Return type:
- new_multipart_message(role='user')#
Start adding a multipart-message to the completion query.
Use this to add image parts to the message.
- Parameters:
role (str) – The message role. Use
systemto set the LLM behavior,assistantto store predefined responses,userto provide requests or comments for the LLM to answer to. Defaults touser.- Return type:
- new_multipart_tool_output(tool_call_id, role='tool', output='')#
Start adding a multipart tool output to the completion query.
- Parameters:
tool_call_id (str) – The tool call id, as provided by the LLM in the conversation messages.
role (str) – The message role. Defaults to
tool.output (str) – The tool’s output. Defaults to an empty string.
- Return type:
- with_context(context)#
- with_json_output(schema=None, strict=None, compatible=None)#
Request the model to generate a valid JSON response, for models that support it.
Note that some models may require you to also explicitly request this in the user or system prompt to use this.
Caution
JSON output support is experimental for locally-running Hugging Face models.
- Parameters:
schema (dict) – (optional) If specified, request the model to produce a JSON response that adheres to the provided schema. Support varies across models/providers.
strict (bool) – (optional) If a schema is provided, whether to strictly enforce it. Support varies across models/providers.
compatible (bool) – (optional) Allow DSS to modify the schema in order to increase compatibility, depending on known limitations of the model/provider. Defaults to automatic.
- with_memory_fragment(memory_fragment)#
Add a memory fragment to the completion query.
- Parameters:
memory_fragment (dict) – The memory fragment returned by the model on the previous turn.
- with_message(message, role='user')#
Add a message to the completion query.
- Parameters:
message (str) – The message text.
role (str) – The message role. Use
systemto set the LLM behavior,assistantto store predefined responses,userto provide requests or comments for the LLM to answer to. Defaults touser.
- with_structured_output(model_type, strict=None, compatible=None)#
Instruct the model to generate a response as an instance of a specified Pydantic model.
This functionality depends on with_json_output and necessitates that the model supports JSON output with a schema.
Caution
Structured output support is experimental for locally-running Hugging Face models.
- Parameters:
model_type (pydantic.BaseModel) – A Pydantic model class used for structuring the response.
strict (bool) – (optional) see
with_json_output()compatible (bool) – (optional) see
with_json_output()
- with_tool_calls(tool_calls, role='assistant')#
Add tool calls to the completion query.
Caution
Tool calls support is experimental for locally-running Hugging Face models.
- Parameters:
tool_calls (list[dict]) – Calls to tools that the LLM requested to use.
role (str) – The message role. Defaults to
assistant.
- with_tool_output(tool_output, tool_call_id, role='tool')#
Add a tool message to the completion query.
- Parameters:
tool_output (str) – The tool output, as a string.
tool_call_id (str) – The tool call id, as provided by the LLM in the conversation messages.
role (str) – The message role. Defaults to
tool.
- with_tool_validation_requests(tool_validation_requests)#
Add tool validation requests to the completion query.
- Parameters:
tool_validation_requests (list[dict]) – Validation requests for tools that the agent requested to use.
- with_tool_validation_response(validation_request_id, validated=True, arguments=None)#
Add a tool validation response to the completion query.
- Parameters:
validation_request_id (str) – The validation request id, as provided by the agent in the conversation messages.
validated (bool) – Whether to validate or reject the tool call.
arguments (str) – Arguments to use for the tool call (if different from the validation request).
- class dataikuapi.dss.llm.DSSLLMCompletionResponse(raw_resp=None, text=None, finish_reason=None, response_parser=None, trace=None, query=None)#
Response to a completion
- property json#
- Returns:
LLM response parsed as a JSON object
- property parsed#
- property success#
- Returns:
The outcome of the completion query.
- Return type:
bool
- property text#
- Returns:
The raw text of the LLM response.
- Return type:
Union[str, None]
- property tool_calls#
- Returns:
The tool calls of the LLM response.
- Return type:
Union[list, None]
- property tool_validation_requests#
- Returns:
The tool validation requests of the agent response.
- Return type:
Union[list, None]
- property memory_fragment#
- Returns:
Data generated by the model that must be passed back in the next query.
- Return type:
Union[dict, None]
- property log_probs#
- Returns:
The log probs of the LLM response.
- Return type:
Union[list, None]
- property context_upsert#
- Returns:
The context upsert of the response (only for agents).
- Return type:
Union[dict, None]
- property trace#
- property total_usage#
- prepare_followup()#
Prepare a new completion query to follow up on this response, pre-filled with the relevant data from the response.
- Returns:
The prepared follow-up completion query.
- Return type:
- class dataikuapi.dss.llm.DSSLLMStreamedCompletionChunks(query, collect_response=False)#
An iterator over the chunks generated by the execution of a streamed completion query. The streamed chunks are of type
DSSLLMStreamedCompletionChunkandDSSLLMStreamedCompletionFooter. When collect_response=True, the streamed chunks are aggregated into a consolidatedDSSLLMCompletionResponse.Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLMCompletionQuery.execute_streamed()instead.- iter_chunks()#
- Returns:
An iterator over the LLM response chunks.
- Return type:
Iterator[Union[
DSSLLMStreamedCompletionChunk,DSSLLMStreamedCompletionFooter]]
- property response#
- Returns:
The consolidated LLM response obtained by the aggregation of all streamed chunks, if collect_response=True. Available only after all chunks have been collected.
- Return type:
- prepare_followup()#
Prepare a followup completion query from the consolidated response, pre-filled with the relevant data from the response. Available only when collect_response=True, after all chunks have been collected.
- Returns:
The prepared follow-up completion query.
- Return type:
Batch text generation#
- class dataikuapi.dss.llm.DSSLLMCompletionsQuery(llm)#
A handle to interact with a multi-completion query. Completion queries allow you to send a prompt to a DSS-managed LLM and retrieve its response.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLM.new_completion()instead.- property settings#
- Returns:
The completion query settings.
- Return type:
dict
- new_completion()#
- new_guardrail(type)#
Start adding a guardrail to the request. You need to configure the returned object, and call add() to actually add it
- execute()#
Run the completions query and retrieve the LLM response.
- Returns:
The LLM response.
- Return type:
- with_json_output(schema=None, strict=None, compatible=None)#
Request the model to generate a valid JSON response, for models that support it.
Note that some models may require you to also explicitly request this in the user or system prompt to use this.
Caution
JSON output support is experimental for locally-running Hugging Face models.
- Parameters:
schema (dict) – (optional) If specified, request the model to produce a JSON response that adheres to the provided schema. Support varies across models/providers.
strict (bool) – (optional) If a schema is provided, whether to strictly enforce it. Support varies across models/providers.
compatible (bool) – (optional) Allow DSS to modify the schema in order to increase compatibility, depending on known limitations of the model/provider. Defaults to automatic.
- with_structured_output(model_type, strict=None, compatible=None)#
Instruct the model to generate a response as an instance of a specified Pydantic model.
This functionality depends on with_json_output and necessitates that the model supports JSON output with a schema.
Caution
Structured output support is experimental for locally-running Hugging Face models.
- Parameters:
model_type (pydantic.BaseModel) – A Pydantic model class used for structuring the response.
strict (bool) – (optional) see
with_json_output()compatible (bool) – (optional) see
with_json_output()
- class dataikuapi.dss.llm.DSSLLMCompletionsQuerySingleQuery#
- new_multipart_message(role='user')#
Start adding a multipart-message to the completion query.
Use this to add image parts to the message.
- Parameters:
role (str) – The message role. Use
systemto set the LLM behavior,assistantto store predefined responses,userto provide requests or comments for the LLM to answer to. Defaults touser.- Return type:
- with_message(message, role='user')#
Add a message to the completion query.
- Parameters:
message (str) – The message text.
role (str) – The message role. Use
systemto set the LLM behavior,assistantto store predefined responses,userto provide requests or comments for the LLM to answer to. Defaults touser.
- with_memory_fragment(memory_fragment)#
Add a memory fragment to the completion query.
- Parameters:
memory_fragment (dict) – The memory fragment returned by the model on the previous turn.
- with_tool_calls(tool_calls, role='assistant')#
Add tool calls to the completion query.
Caution
Tool calls support is experimental for locally-running Hugging Face models.
- Parameters:
tool_calls (list[dict]) – Calls to tools that the LLM requested to use.
role (str) – The message role. Defaults to
assistant.
- with_tool_validation_requests(tool_validation_requests)#
Add tool validation requests to the completion query.
- Parameters:
tool_validation_requests (list[dict]) – Validation requests for tools that the agent requested to use.
- with_tool_validation_response(validation_request_id, validated=True, arguments=None)#
Add a tool validation response to the completion query.
- Parameters:
validation_request_id (str) – The validation request id, as provided by the agent in the conversation messages.
validated (bool) – Whether to validate or reject the tool call.
arguments (str) – Arguments to use for the tool call (if different from the validation request).
- new_multipart_tool_output(tool_call_id, role='tool', output='')#
Start adding a multipart tool output to the completion query.
- Parameters:
tool_call_id (str) – The tool call id, as provided by the LLM in the conversation messages.
role (str) – The message role. Defaults to
tool.output (str) – The tool’s output. Defaults to an empty string.
- Return type:
- with_tool_output(tool_output, tool_call_id, role='tool')#
Add a tool message to the completion query.
- Parameters:
tool_output (str) – The tool output, as a string.
tool_call_id (str) – The tool call id, as provided by the LLM in the conversation messages.
role (str) – The message role. Defaults to
tool.
- with_context(context)#
- class dataikuapi.dss.llm.DSSLLMCompletionsResponse(raw_resp, response_parser=None)#
A handle to interact with a multi-completion response.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLMCompletionsQuery.execute()instead.- property responses#
The array of responses
Multipart message and tool payload builders#
- class dataikuapi.dss.llm.DSSLLMCompletionQueryMultipartMessage(q, role)#
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLMCompletionQuery.new_multipart_message()ordataikuapi.dss.llm.DSSLLMCompletionsQuerySingleQuery.new_multipart_message().- add()#
Add this message to the completion query
- class dataikuapi.dss.llm.DSSLLMCompletionQueryMultipartToolOutput(q, tool_call_id, role, output)#
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLMCompletionQuery.new_multipart_tool_output()ordataikuapi.dss.llm.DSSLLMCompletionsQuerySingleQuery.new_multipart_tool_output().- add()#
Add this tool output to the completion query
Embeddings#
- class dataikuapi.dss.llm.DSSLLMEmbeddingsQuery(llm, text_overflow_mode)#
A handle to interact with an embedding query. Embedding queries allow you to transform text into embedding vectors using a DSS-managed model.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLM.new_embeddings()instead.- add_text(text)#
Add text to the embedding query.
- Parameters:
text (str) – Text to add to the query.
- add_image(image, text=None)#
Add an image to the embedding query.
- Parameters:
image – Image content as bytes or str (base64)
text – Optional text (requires a multimodal model)
- new_guardrail(type)#
Start adding a guardrail to the request. You need to configure the returned object, and call add() to actually add it
- execute()#
Run the embedding query.
- Returns:
The results of the embedding query.
- Return type:
- class dataikuapi.dss.llm.DSSLLMEmbeddingsResponse(raw_resp)#
A handle to interact with an embedding query result.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLMEmbeddingsQuery.execute()instead.- get_embeddings()#
Retrieve vectors resulting from the embeddings query.
- Returns:
A list of lists containing all embedding vectors.
- Return type:
list
Image generation#
- class dataikuapi.dss.llm.DSSLLMImageGenerationQuery(llm)#
A handle to interact with an image generation query.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLM.new_images_generation()instead.- with_prompt(prompt, weight=None)#
Add a prompt to the image generation query.
- Parameters:
prompt (str) – The prompt text.
weight (float) – Optional weight between 0 and 1 for the prompt.
- with_negative_prompt(prompt, weight=None)#
Add a negative prompt to the image generation query.
- Parameters:
prompt (str) – The prompt text.
weight (float) – Optional weight between 0 and 1 for the negative prompt.
- with_original_image(image, mode=None, weight=None)#
Add an image to the generation query.
To edit specific pixels of the original image. A mask can be applied by calling with_mask():
>>> query.with_original_image(image, mode="INPAINTING") # replace the pixels using a mask
To edit an image:
>>> query.with_original_image(image, mode="MASK_FREE") # edit the original image according to the prompt
>>> query.with_original_image(image, mode="VARY") # generates a variation of the original image
- Parameters:
image (Union[str, bytes]) – The original image as str in base 64 or bytes.
mode (str) – The edition mode. Modes support varies across models/providers.
weight (float) – The original image weight between 0 and 1.
- with_mask(mode, image=None)#
Add a mask for edition to the generation query. Call this method alongside with_original_image().
To edit parts of the image using a black mask (replace the black pixels):
>>> query.with_mask("MASK_IMAGE_BLACK", image=black_mask)
To edit parts of the image that are transparent (replace the transparent pixels):
>>> query.with_mask("ORIGINAL_IMAGE_ALPHA")
- Parameters:
mode (str) – The mask mode. Modes support varies across models/providers.
image (Union[str, bytes]) – The mask image to apply to the image edition. As str in base 64 or bytes.
- new_guardrail(type)#
Start adding a guardrail to the request. You need to configure the returned object, and call add() to actually add it
- property height#
- Returns:
The generated image height in pixels.
- Return type:
Optional[int]
- property width#
- Returns:
The generated image width in pixels.
- Return type:
Optional[int]
- property fidelity#
- Returns:
From 0.0 to 1.0, how strongly to adhere to prompt.
- Return type:
Optional[float]
- property quality#
- Returns:
Quality of the image to generate. Valid values depend on the targeted model.
- Return type:
Optional[str]
- property seed#
- Returns:
Seed of the image to generate, gives deterministic results when set.
- Return type:
Optional[int]
- property style#
- Returns:
Style of the image to generate. Valid values depend on the targeted model.
- Return type:
Optional[str]
- property images_to_generate#
- Returns:
Number of images to generate per query. Valid values depend on the targeted model.
- Return type:
Optional[int]
- property aspect_ratio#
- Returns:
The width/height aspect ratio or None if either is not set.
- Return type:
Optional[float]
- execute()#
Executes the image generation
- Return type:
- class dataikuapi.dss.llm.DSSLLMImageGenerationResponse(raw_resp)#
A handle to interact with an image generation response.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLMImageGenerationQuery.execute()instead.- property success#
- Returns:
The outcome of the image generation query.
- Return type:
bool
- first_image(as_type='bytes')#
- Parameters:
as_type (str) – The type of image to return, ‘bytes’ for bytes otherwise ‘str’ for base 64 str.
- Returns:
The first generated image as bytes or str depending on the as_type parameter.
- Return type:
Union[bytes,str]
- get_images(as_type='bytes')#
- Parameters:
as_type (str) – The type of images to return, ‘bytes’ for bytes otherwise ‘str’ for base 64 str.
- Returns:
The generated images as bytes or str depending on the as_type parameter.
- Return type:
Union[List[bytes], List[str]]
- property images#
- Returns:
The generated images in bytes format.
- Return type:
List[bytes]
- property trace#
- property total_usage#
Reranking#
- class dataikuapi.dss.llm.DSSLLMRerankingQuery(llm)#
A handle to interact with a reranking query. Reranking queries allow you to send a text query and a list of documents to a DSS-managed ranking model and retrieve the documents ranked according to their relevance to the query.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLM.new_reranking()instead.- with_query(text)#
Sets the reranking text query.
- Parameters:
text (str) – The reranking text query.
- with_document(text)#
Adds a text document to the list of documents to be reranked.
- Parameters:
text (str) – The text document to be reranked.
- execute()#
Run the reranking query and retrieve the LLM response.
- Returns:
The LLM response.
- Return type:
- class dataikuapi.dss.llm.DSSLLMRerankingResponse(raw_resp)#
A handle to interact with a ranking query result.
Important
Do not create this class directly, use
dataikuapi.dss.llm.DSSLLMRerankingQuery.execute()instead.- property success#
- Returns:
The outcome of the reranking query.
- Return type:
bool
- property error_message#
- Returns:
The error message if the reranking query failed, None otherwise.
- Return type:
Union[str, None]
- property documents#
- Returns:
The array of reranked documents.
- Return type:
- property trace#
- Returns:
The trace of the reranking query if available, None otherwise.
- Return type:
Union[dict, None]
