VM-X AI Python SDK
Project description
VM-X SDK for Python
Description
VM-X AI SDK client for Python
Installation
pip install vm-x-ai-sdk
poetry add vm-x-ai-sdk
Usage
from vmxai import (
CompletionRequest,
RequestMessage,
RequestMessageToolCall,
RequestMessageToolCallFunction,
RequestToolFunction,
RequestTools,
VMXClient,
VMXClientOAuth,
)
client = VMXClient(
domain="env-abc123.clnt.dev.vm-x.ai",
environment_id="env-abc123",
workspace_id="ws-abc123",
# Authentication options
# OAuth Client credentials
auth=VMXClientOAuth(
client_id="abc123",
client_secret="abc123",
),
# Or API Key
api_key="abc123",
)
# Streaming
streaming_response = client.completion(
request=CompletionRequest(
resource="default",
workload="default",
messages=[
RequestMessage(
role="user",
content="Hey there!",
)
],
),
)
for message in streaming_response:
print(message.message, end="")
# Non-Streaming
response = client.completion(
request=CompletionRequest(
resource="default",
workload="default",
messages=[
RequestMessage(
role="user",
content="Hey there!",
)
],
),
stream=False,
)
print("\n")
print(response.message)
# Function Calling
function_response = client.completion(
request=CompletionRequest(
resource="default",
workload="default",
messages=[
RequestMessage(
role="user",
content="whats the temperature in Dallas, New York and San Diego?",
)
],
tools=[
RequestTools(
type="function",
function=RequestToolFunction(
name="get_weather",
description="Lookup the temperature",
parameters={
"type": "object",
"properties": {"city": {"description": "City you want to get the temperature"}},
"required": ["city"],
},
),
)
],
),
)
for message in function_response:
print(message, end="")
# Function Calling Callback
function_response_callback = client.completion(
request=CompletionRequest(
resource="default",
workload="default",
messages=[
RequestMessage(
role="user",
content="whats the temperature in Dallas, New York and San Diego?",
),
RequestMessage(
role="assistant",
tool_calls=[
RequestMessageToolCall(
id="call_NLcWB6VCdG6x9UW6xrGVTTTR",
type="function",
function=RequestMessageToolCallFunction(name="get_weather", arguments='{"city": "Dallas"}'),
),
RequestMessageToolCall(
id="call_6RDTuEDsaHvWr8XjwDXx4UjX",
type="function",
function=RequestMessageToolCallFunction(name="get_weather", arguments='{"city": "New York"}'),
),
RequestMessageToolCall(
id="call_NsFzeGVbAWl5bor6RrUDCvTv",
type="function",
function=RequestMessageToolCallFunction(name="get_weather", arguments='{"city": "San Diego"}'),
)
],
),
RequestMessage(
role="tool",
content="The temperature in Dallas is 81F",
tool_call_id="call_NLcWB6VCdG6x9UW6xrGVTTTR"
),
RequestMessage(
role="tool",
content="The temperature in New York is 78F",
tool_call_id="call_6RDTuEDsaHvWr8XjwDXx4UjX"
),
RequestMessage(
role="tool",
content="The temperature in San Diego is 68F",
tool_call_id="call_NsFzeGVbAWl5bor6RrUDCvTv"
),
],
tools=[
RequestTools(
type="function",
function=RequestToolFunction(
name="get_weather",
description="Lookup the temperature",
parameters={
"type": "object",
"properties": {"city": {"description": "City you want to get the temperature"}},
"required": ["city"],
},
),
)
],
),
)
for message in function_response_callback:
print(message.message, end="")
Change Log
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
vm_x_ai_sdk-0.4.1.tar.gz
(8.9 kB
view hashes)
Built Distribution
Close
Hashes for vm_x_ai_sdk-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ad94c4dcbfa4c9ed414e4210e99ac811cecc96efc5ae514aba5b26bb258197d |
|
MD5 | 65b31f9d67ab7c02294c52fcaff834e4 |
|
BLAKE2b-256 | ad982420ed397ab4c7c36187a3f35460eefbfa94a2c198d81eb0abeb198e2c7b |