srai-openai


Namesrai-openai JSON
Version 0.8.2 PyPI version JSON
download
home_pagehttps://github.com/southriverai/srai-openai
SummaryA set of functions to better interact with openai.
upload_time2024-08-19 07:28:00
maintainerNone
docs_urlNone
authorJaap Oosterbroek
requires_python<4.0,>=3.10
licenseMIT
keywords srai tools
VCS
bugtrack_url
requirements srai-core openai tiktoken docstring_parser
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```python
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
```python
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
```python
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
```python
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
```python
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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/southriverai/srai-openai",
    "name": "srai-openai",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "SRAI, TOOLS",
    "author": "Jaap Oosterbroek",
    "author_email": "jaap.oosterbroek@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3f/3e/d5503f4c530954d566285af0aafdf3be17f0bb000271d32e64dd916cfebe/srai_openai-0.8.2.tar.gz",
    "platform": null,
    "description": "# srai-openai\nA set of functions to better interact with openai\n\nwraps the promtps for text, images, whisper and function in a convinient way:\n\n\n## Install\npip install srai-openai\n\n## Use\n\n### prompt text\n```python\nfrom srai_openai.client_openai_chatgpt import ClientOpenaiChatgpt\nclient = ClientOpenaiChatgpt()\nprint(client.prompt_default(\"You are a helpfull assitent\", \"This is a test\"))\n```\n\n\n### prompt json response\n```python\nfrom srai_openai.client_openai_chatgpt import ClientOpenaiChatgpt\nimport json\nclient = ClientOpenaiChatgpt()\nresult = client.prompt_default_json(\n    \"You are a helpfull assistent\", \"I'm fine, thank you. How are you? Respond in valid json\"\n)\nprint(json.dumps(result, indent=4))\n```\n\n### prompt image\n```python\nfrom srai_openai.client_openai_chatgpt import ClientOpenaiChatgpt\nimport base64\nclient = ClientOpenaiChatgpt()\nsystem_message_prompt = \"You are a helpfull assistent\"\nuser_message_prompt = \"What is shown here?\"\nwith open(\"image.png\", \"rb\") as file:\n    image_base64 = base64.b64encode(file.read()).decode(\"utf-8\")\nprint(client.prompt_default(system_message_prompt, user_message_prompt, image_base64=image_base64))\n```\n\n### prompt with tool\n```python\nfrom srai_openai.client_openai_chatgpt import ClientOpenaiChatgpt\nfrom srai_openai.model.chatgpt_tool import ChatgptTool, create_chatgpt_tool\nfrom typing import List, Literal\n\nclient = ClientOpenaiChatgpt()\nsystem_message_content = \"You are a helpfull assitent\"\nuser_message_content = \"What is the weather like today in New York?\"\n\ndef get_weather(location: str, unit: Literal[\"celsius\", \"fahrenheit\"] = \"celsius\") -> str:\n    \"\"\"Get the current weather in a given location.\n\n    Args:\n        location (str): Location to get the weather for.\n        unit (Literal[\"celsius\", \"fahrenheit\"], optional): The unit to return the temperature in. Default is celsius.\n    Returns:\n        str: weather for the location\n    \"\"\"\n    return f\"The weather in {location} is sunny today in {unit}.\"\n\nlist_tool: List[ChatgptTool] = [create_chatgpt_tool(get_weather)]\nresponse = client.prompt_default_tool(system_message_content, user_message_content, list_tool)\nprint(response)\n```\n\n### transcription\n```python\nfrom srai_openai.client_openai_whisper import ClientOpenaiWhisper\nclient = ClientOpenaiWhisper()\ntranscription = client.transcription(\"test.mp3\")\nprint(transcription[\"text\"])\n```\n\n## Changelog\nVersion 0.8.1\n- Bug fix on the client\n\nVersion 0.8.0\n- Reenabled serialization of prompt configs\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A set of functions to better interact with openai.",
    "version": "0.8.2",
    "project_urls": {
        "Homepage": "https://github.com/southriverai/srai-openai",
        "Repository": "https://github.com/southriverai/srai-openai"
    },
    "split_keywords": [
        "srai",
        " tools"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "111190e67f6bf92b122b665c01a3ea3fee125877007369632ada7f4ee4018055",
                "md5": "1d804aa35b13406eee89d052de2bcd09",
                "sha256": "622bf4739af6c07c93e8312f32ede5a5e7b552bdeb7f7d30d7d5c5c2a8d92133"
            },
            "downloads": -1,
            "filename": "srai_openai-0.8.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1d804aa35b13406eee89d052de2bcd09",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 10123,
            "upload_time": "2024-08-19T07:27:58",
            "upload_time_iso_8601": "2024-08-19T07:27:58.578876Z",
            "url": "https://files.pythonhosted.org/packages/11/11/90e67f6bf92b122b665c01a3ea3fee125877007369632ada7f4ee4018055/srai_openai-0.8.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f3ed5503f4c530954d566285af0aafdf3be17f0bb000271d32e64dd916cfebe",
                "md5": "869cd8d6381d1fc8080a508fb648343c",
                "sha256": "37cb84ec2f9283ef403f4fc7650b29db7d854bb74952300c37beedb4d8b6db37"
            },
            "downloads": -1,
            "filename": "srai_openai-0.8.2.tar.gz",
            "has_sig": false,
            "md5_digest": "869cd8d6381d1fc8080a508fb648343c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 8766,
            "upload_time": "2024-08-19T07:28:00",
            "upload_time_iso_8601": "2024-08-19T07:28:00.169992Z",
            "url": "https://files.pythonhosted.org/packages/3f/3e/d5503f4c530954d566285af0aafdf3be17f0bb000271d32e64dd916cfebe/srai_openai-0.8.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-19 07:28:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "southriverai",
    "github_project": "srai-openai",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [
        {
            "name": "srai-core",
            "specs": [
                [
                    ">=",
                    "0.12.0"
                ]
            ]
        },
        {
            "name": "openai",
            "specs": [
                [
                    "==",
                    "1.35.5"
                ]
            ]
        },
        {
            "name": "tiktoken",
            "specs": [
                [
                    "==",
                    "0.6.0"
                ]
            ]
        },
        {
            "name": "docstring_parser",
            "specs": [
                [
                    "==",
                    "0.16"
                ]
            ]
        }
    ],
    "lcname": "srai-openai"
}
        
Elapsed time: 0.30981s