A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://posit-dev.github.io/chatlas/reference/ChatOpenAI.html below:

chatopenai – chatlas

ChatOpenAI
ChatOpenAI(
    system_prompt=None,
    model=None,
    api_key=None,
    base_url='https://api.openai.com/v1',
    seed=MISSING,
    kwargs=None,
)

Chat with an OpenAI model.

OpenAI provides a number of chat based models under the ChatGPT moniker.

Prerequisites

Note that a ChatGPT Plus membership does not give you the ability to call models via the API. You will need to go to the developer platform to sign up (and pay for) a developer account that will give you an API key that you can use with this package.

Examples
import os
from chatlas import ChatOpenAI

chat = ChatOpenAI(api_key=os.getenv("OPENAI_API_KEY"))
chat.chat("What is the capital of France?")
Parameters system_prompt Optional[str] A system prompt to set the behavior of the assistant. None model 'Optional[ChatModel | 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 OPENAI_API_KEY environment variable. None base_url str The base URL to the endpoint; the default uses OpenAI. 'https://api.openai.com/v1' seed int | None | MISSING_TYPE Optional integer seed that ChatGPT uses to try and make output more reproducible. MISSING kwargs Optional['ChatClientArgs'] Additional arguments to pass to the openai.OpenAI() client constructor. None Returns Chat A chat object that retains the state of the conversation. Note

Pasting an API key into a chat constructor (e.g., ChatOpenAI(api_key="...")) is the simplest way to get started, and is fine for interactive use, but is problematic for code that may be shared with others.

Instead, consider using environment variables or a configuration file to manage your credentials. One popular way to manage credentials is to use a .env file to store your credentials, and then use the python-dotenv package to load them into your environment.

pip install python-dotenv
# .env
OPENAI_API_KEY=...
from chatlas import ChatOpenAI
from dotenv import load_dotenv

load_dotenv()
chat = ChatOpenAI()
chat.console()

Another, more general, solution is to load your environment variables into the shell before starting Python (maybe in a .bashrc, .zshrc, etc. file):

export OPENAI_API_KEY=...

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4