From 3a42978a4e533842381cfeabc06c110e0e290f40 Mon Sep 17 00:00:00 2001 From: Sreejan <121751299+SreejanPersonal@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:53:43 +0530 Subject: [PATCH] Add files via upload --- CHANGELOG.md | 8 +++++++- README.md | 23 +++++++++++++++++++++-- pyproject.toml | 2 +- src/openai_unofficial/__init__.py | 2 +- src/openai_unofficial/main.py | 3 +-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f754c7f..b868ebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.1.0] - 2024-11-07 +## [0.1.1] - 2024-11-08 +### Added +- Updated the README file for better visual understanding. +### Fixed +- Resolved bugs in the streaming functionality. + +## [0.1.0] - 2024-11-07 ### Added - Initial release diff --git a/README.md b/README.md index d5088fe..425ad24 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Python Versions](https://img.shields.io/pypi/pyversions/openai-unofficial.svg)](https://pypi.org/project/openai-unofficial/) [![Downloads](https://static.pepy.tech/badge/openai-unofficial)](https://pepy.tech/project/openai-unofficial) -An unofficial Free & Unlimited Python SDK for the OpenAI API, providing seamless integration and easy-to-use methods for interacting with OpenAI's latest powerful AI models, including GPT-4o (Including gpt-4o-audio-preview & gpt-4o-realtime-preview Models), GPT-4, GPT-3.5 Turbo, DALL·E 3, Whisper & Text-to-Speech (TTS) models +An Free & Unlimited unofficial Python SDK for the OpenAI API, providing seamless integration and easy-to-use methods for interacting with OpenAI's latest powerful AI models, including GPT-4o (Including gpt-4o-audio-preview & gpt-4o-realtime-preview Models), GPT-4, GPT-3.5 Turbo, DALL·E 3, Whisper & Text-to-Speech (TTS) models for Free ## Table of Contents @@ -98,6 +98,8 @@ print("ChatBot:", response.choices[0].message.content) ### Chat Completion with Image Input ```python +from openai_unofficial import OpenAIUnofficial + client = OpenAIUnofficial() response = client.chat.completions.create( messages=[{ @@ -117,6 +119,23 @@ response = client.chat.completions.create( print("Response:", response.choices[0].message.content) ``` +### Streaming Chat Completion + +```python +from openai_unofficial import OpenAIUnofficial + +client = OpenAIUnofficial() +completion_stream = client.chat.completions.create( + messages=[{"role": "user", "content": "Write a short story in 3 sentences."}], + model="gpt-4o-mini-2024-07-18", + stream=True +) +for chunk in completion_stream: + content = chunk.choices[0].delta.content + if content: + print(content, end='', flush=True) +``` + ### Audio Generation with TTS Model ```python @@ -247,4 +266,4 @@ Here's a partial list of models that the SDK currently supports. For Complete li - `text-embedding-3-small` - `text-embedding-3-large` ---- +--- \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 123743c..ad120e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "openai-unofficial" -version = "0.1.0" +version = "0.1.1" authors = [ { name="DevsDoCode", email="devsdocode@gmail.com" }, ] diff --git a/src/openai_unofficial/__init__.py b/src/openai_unofficial/__init__.py index d1d5f1e..0e733c7 100644 --- a/src/openai_unofficial/__init__.py +++ b/src/openai_unofficial/__init__.py @@ -1,4 +1,4 @@ from .main import OpenAIUnofficial -__version__ = "0.1.0" +__version__ = "0.1.1" __all__ = ["OpenAIUnofficial"] \ No newline at end of file diff --git a/src/openai_unofficial/main.py b/src/openai_unofficial/main.py index bce918a..167a8a1 100644 --- a/src/openai_unofficial/main.py +++ b/src/openai_unofficial/main.py @@ -227,8 +227,7 @@ def _handle_streaming_response(self, response: requests.Response) -> Iterator[Ch line_str = line_str[len('data: '):] data = json.loads(line_str) yield ChatCompletionChunk(data) - except json.JSONDecodeError as e: - logger.warning(f"Failed to parse streaming response: {e}") + except: continue class Audio: