srai-openai
A set of functions to better interact with openai
wraps the promtps for text, images, whisper and function in a convinient way:
Install
pip install srai-openai
Use
prompt text
from srai_openai.client_openai_chatgpt import ClientOpenaiChatgpt
client = ClientOpenaiChatgpt()
print(client.prompt_default("You are a helpfull assitent", "This is a test"))
prompt json response
from srai_openai.client_openai_chatgpt import ClientOpenaiChatgpt
import json
client = ClientOpenaiChatgpt()
result = client.prompt_default_json(
"You are a helpfull assistent", "I'm fine, thank you. How are you? Respond in valid json"
)
print(json.dumps(result, indent=4))
prompt image
from srai_openai.client_openai_chatgpt import ClientOpenaiChatgpt
import base64
client = ClientOpenaiChatgpt()
system_message_prompt = "You are a helpfull assistent"
user_message_prompt = "What is shown here?"
with open("image.png", "rb") as file:
image_base64 = base64.b64encode(file.read()).decode("utf-8")
print(client.prompt_default(system_message_prompt, user_message_prompt, image_base64=image_base64))
prompt with tool
from srai_openai.client_openai_chatgpt import ClientOpenaiChatgpt
from srai_openai.model.chatgpt_tool import ChatgptTool, create_chatgpt_tool
from typing import List, Literal
client = ClientOpenaiChatgpt()
system_message_content = "You are a helpfull assitent"
user_message_content = "What is the weather like today in New York?"
def get_weather(location: str, unit: Literal["celsius", "fahrenheit"] = "celsius") -> str:
"""Get the current weather in a given location.
Args:
location (str): Location to get the weather for.
unit (Literal["celsius", "fahrenheit"], optional): The unit to return the temperature in. Default is celsius.
Returns:
str: weather for the location
"""
return f"The weather in {location} is sunny today in {unit}."
list_tool: List[ChatgptTool] = [create_chatgpt_tool(get_weather)]
response = client.prompt_default_tool(system_message_content, user_message_content, list_tool)
print(response)
transcription
from srai_openai.client_openai_whisper import ClientOpenaiWhisper
client = ClientOpenaiWhisper()
transcription = client.transcription("test.mp3")
print(transcription["text"])
Changelog
Version 0.8.1
- Bug fix on the client
Version 0.8.0
- Reenabled serialization of prompt configs
Metadata
Release files for srai-openai 0.8.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| srai_openai-0.8.2.tar.gz | 8.8 kB | Without provenance | Details for srai_openai-0.8.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| srai_openai-0.8.2-py3-none-any.whl | Python 3 | none | any | Details for srai_openai-0.8.2-py3-none-any.whl |
Total release size: 18.9 kB
Release files / srai_openai-0.8.2.tar.gz
| Download URL | srai_openai-0.8.2.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37cb84ec2f9283ef403f4fc7650b29db7d854bb74952300c37beedb4d8b6db37
|
|
BLAKE2b-256 checksum How to use checksums |
3f3ed5503f4c530954d566285af0aafdf3be17f0bb000271d32e64dd916cfebe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.11
|
Release files / srai_openai-0.8.2-py3-none-any.whl
| Download URL | srai_openai-0.8.2-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
622bf4739af6c07c93e8312f32ede5a5e7b552bdeb7f7d30d7d5c5c2a8d92133
|
|
BLAKE2b-256 checksum How to use checksums |
111190e67f6bf92b122b665c01a3ea3fee125877007369632ada7f4ee4018055
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.11
|
Security for srai-openai 0.8.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.