Commonbase Python SDK
Project description
Commonbase Python SDK
Commonbase allows developers to integrate with any popular LLM API provider without needing to change any code. The SDK helps with collecting data and feedback from the users and helps you fine-tune models for your specific use case.
Installation
pip install commonbase
Usage
A project ID is required for all Commonbase requests. You can find your project ID in the Commonbase Dashboard.
Text Completion
To create a basic text completion, use the Completion.create
class method with a prompt
argument.
import commonbase
project_id="XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
result = commonbase.Completion.create(project_id=project_id, prompt="Hello!")
print(result.choices[0].text)
Use Completion.stream
to stream a completion response.
import commonbase
project_id="XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
result = commonbase.Completion.stream(
project_id=project_id,
prompt="Write me a short essay about artificial intelligence."
)
for completion in result:
print(completion.choices[0].text, end="")
Chat
To create a chat completion, use the context
method to provide a list of chat messages.
You must also set the OpenAI configuration to chat
. In this mode, the prompt
argument
functions as a system message.
import commonbase
project_id="XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
result = commonbase.Completion.create(
project_id=project_id,
prompt="You are an assistant who helps users with tech problems.",
chat_context=commonbase.ChatContext([
commonbase.ChatMessage(role="user", content="My internet isn't working."),
commonbase.ChatMessage(role="assistant", content="Have you tried restarting your router?"),
commonbase.ChatMessage(role="user", content="Yes I've tried that."),
]),
provider_config=commonbase.ProviderConfig(
provider="cb-openai-eu", params=commonbase.OpenAIParams(type="chat")
),
)
print(result.choices[0].text)
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
Built Distribution
Hashes for commonbase-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e100804af5692dc2703fd1635f77589620bd638118fe2c4bcfbec9a6c24b0e45 |
|
MD5 | 34ab15c7bd13ebfa483b858efc10b25b |
|
BLAKE2b-256 | e06793499e32dbbe78e4601167e469ed42bd05dc352be2ca01f61cea1d920a80 |