ChatGithub
ChatGithub(=None,
system_prompt=None,
turns=None,
model=None,
api_key='https://models.inference.ai.azure.com/',
base_url=MISSING,
seed=None,
kwargs )
Chat with a model hosted on the GitHub model marketplace.
GitHub (via Azure) hosts a wide variety of open source models, some of which are fined tuned for specific tasks.
Prerequisites
Sign up at https://github.com/marketplace/models to get an API key. You may need to apply for and be accepted into a beta access program.
ChatGithub
requires the openai
package (e.g., pip install openai
).
Examples
import os
from chatlas import ChatGithub
= ChatGithub(api_key=os.getenv("GITHUB_PAT"))
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 |
turns | Optional[list[Turn]] | A list of turns to start the chat with (i.e., continuing a previous conversation). If not provided, the conversation begins from scratch. Do not provide non-None values for both turns and system_prompt . Each message in the list should be a dictionary with at least role (usually system , user , or assistant , but tool is also possible). Normally there is also a content field, which is a string. |
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 GITHUB_PAT environment variable. |
None |
base_url | str | The base URL to the endpoint; the default uses Github’s API. | 'https://models.inference.ai.azure.com/' |
seed | Optional[int] | 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
Name | Type | Description |
---|---|---|
Chat | A chat object that retains the state of the conversation. |
Note
This function is a lightweight wrapper around ChatOpenAI
with the defaults tweaked for the GitHub model marketplace.
Note
Pasting an API key into a chat constructor (e.g., ChatGithub(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
GITHUB_PAT=...
from chatlas import ChatGithub
from dotenv import load_dotenv
load_dotenv()= ChatGithub()
chat 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 GITHUB_PAT=...