ChatPortkey
ChatPortkey(=None,
system_prompt=None,
model=None,
api_key=None,
virtual_key='https://api.portkey.ai/v1',
base_url=None,
kwargs )
Chat with a model hosted on PortkeyAI
PortkeyAI provides an interface (AI Gateway) to connect through its Universal API to a variety of LLMs providers with a single endpoint.
Prerequisites
Portkey credentials
Follow the instructions at https://portkey.ai/docs/introduction/make-your-first-request to get started making requests to PortkeyAI. You will need to set the PORTKEY_API_KEY
environment variable to your Portkey API key, and optionally the PORTKEY_VIRTUAL_KEY
environment variable to your virtual key.
Examples
import os
from chatlas import ChatPortkey
= ChatPortkey(api_key=os.getenv("PORTKEY_API_KEY"))
chat "What is the capital of France?") chat.chat(
Parameters
Name | Type | Description | Default |
---|---|---|---|
system_prompt | Optional[str] | A system prompt to set the behavior of the assistant. | None |
model | Optional[str] | The model to use for the chat. The default, None, will pick a reasonable default, and warn you about it. We strongly recommend explicitly choosing a model for all but the most casual use. | None |
api_key | Optional[str] | The API key to use for authentication. You generally should not supply this directly, but instead set the PORTKEY_API_KEY environment variable. |
None |
virtual_key | Optional[str] | An (optional) virtual identifier, storing the LLM provider’s API key. See documentation. You generally should not supply this directly, but instead set the PORTKEY_VIRTUAL_KEY environment variable. |
None |
base_url | str | The base URL for the Portkey API. The default is suitable for most users. | 'https://api.portkey.ai/v1' |
kwargs | Optional['ChatClientArgs'] | Additional arguments to pass to the OpenAIProvider, such as headers or other client configuration options. | None |
Returns
Name | Type | Description |
---|---|---|
Chat | A chat object that retains the state of the conversation. |
Notes
This function is a lightweight wrapper around ChatOpenAI
with the defaults tweaked for PortkeyAI.