Skip to content

Commit 9c7d349

Browse files
committed
update to v0.1.12
1 parent baea203 commit 9c7d349

7 files changed

Lines changed: 30 additions & 434 deletions

File tree

.github/workflows/python_publish.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ jobs:
6565
id-token: write # IMPORTANT: mandatory for sigstore
6666

6767
steps:
68+
- name: Check out code
69+
uses: actions/checkout@v2
70+
- name: Get the version
71+
id: get-version
72+
run: |
73+
VERSION=$(grep -Po 'version = \K.*' setup.cfg)
74+
echo "::set-output name=PACKAGE_VERSION::$VERSION"
6875
- name: Download all the dists
6976
uses: actions/download-artifact@v3
7077
with:
@@ -81,7 +88,7 @@ jobs:
8188
GITHUB_TOKEN: ${{ github.token }}
8289
run: >-
8390
gh release create
84-
'${{ github.ref_name }}'
91+
'${{ steps.get-version.outputs.PACKAGE_VERSION }}'
8592
--repo '${{ github.repository }}'
8693
--notes ""
8794
- name: Upload artifact signatures to GitHub Release
@@ -92,5 +99,5 @@ jobs:
9299
# sigstore-produced signatures and certificates.
93100
run: >-
94101
gh release upload
95-
'${{ github.ref_name }}' dist/**
102+
'${{ steps.get-version.outputs.PACKAGE_VERSION }}' dist/**
96103
--repo '${{ github.repository }}'

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.12] - 19-03-2024
9+
### Changed
10+
- Fix problem with `stream=True`
11+
- Remove `format` parameter: Now it will be always `text`.
12+
813
## [0.1.11] - 01-03-2024
914
### Changed
1015
- Remove unused packages

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = judini
3-
version = 0.1.11
3+
version = 0.1.12
44
author = Daniel Avila
55
author_email = daniel@judini.ai
66
description = CodeGPT python package

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="judini",
8-
version="0.1.11",
8+
version="0.1.12",
99
author="Judini Inc.",
1010
author_email="daniel@judini.ai",
1111
description="CodeGPT python package",

src/judini/codegpt.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def __init__(self,
4949
#######################
5050

5151
def chat_completion(self, agent_id: str, messages: List[Dict[str, str]],
52-
stream: bool = False, format: Literal['json', 'text'] = 'text'
53-
) -> str | Dict[str, str]:
52+
stream: bool = False) -> str:
5453
"""
5554
Initiates a chat with the specified agent and handles the streaming of
5655
responses.
@@ -63,15 +62,13 @@ def chat_completion(self, agent_id: str, messages: List[Dict[str, str]],
6362
object should have a `role` (which can be 'system', 'user',
6463
or 'assistant') and `content` which is the actual message.
6564
stream: Whether to stream the response or not.
66-
format: The format of the response. Can be either 'json' or 'text'.
6765
6866
Example:
6967
>>> from judini import CodeGPTPlus
7068
>>> codegpt = CodeGPTPlus(api_key, org_id)
7169
>>> agent_id = '00000000-0000-0000-0000-000000000000'
7270
>>> messages = [{'role': 'user', 'content': 'Hello, World!'}]
73-
>>> codegpt.chat_completion(agent_id, messages,
74-
... stream=True, format='text')
71+
>>> codegpt.chat_completion(agent_id, messages, stream=True)
7572
'Hello, World!'
7673
"""
7774

@@ -81,17 +78,15 @@ def chat_completion(self, agent_id: str, messages: List[Dict[str, str]],
8178
if not agent_id:
8279
raise ValueError('JUDINI: agent_id should not be empty')
8380

84-
if format not in ['json', 'text']:
85-
raise ValueError('JUDINI: format should be either "json"|"text"')
86-
81+
8782
headers = self.headers.copy()
88-
headers['media_type'] = 'text/event-stream'
83+
headers['accept'] = 'text/event-stream'
8984

9085
payload = json.dumps({
9186
"agentId": agent_id,
9287
"messages": messages,
9388
"stream": stream,
94-
"format": "json" # By default always json
89+
"format": "text"
9590
})
9691

9792
response = requests.post(f"{self.base_url}/chat/completions",
@@ -102,9 +97,9 @@ def chat_completion(self, agent_id: str, messages: List[Dict[str, str]],
10297
+ f' {response.text} {JUDINI_TUTORIAL}')
10398

10499
if stream:
105-
return handle_stream(response, format)
100+
return handle_stream(response)
106101
else:
107-
return handle_non_stream(response, format)
102+
return handle_non_stream(response)
108103

109104

110105
##############

src/judini/utils.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,20 @@
22
from typing import List, Dict, Literal, Generator, Any
33
import requests
44

5-
def handle_stream(response: requests.Response,
6-
format: Literal['json', 'text']) -> Generator[Any, Any, Any]:
5+
def handle_stream(response: requests.Response) -> Generator[Any, Any, Any]:
76
try:
8-
for chunk in response.iter_lines():
7+
for chunk in response.iter_content(chunk_size=64, decode_unicode=True):
98
if chunk:
10-
chunk_str = chunk.decode("utf-8")
11-
data_array = chunk_str.replace('\n','').split('data: ')[1:]
12-
for jd_str in data_array:
13-
if jd_str == '[DONE]':
14-
break
15-
json_data = json.loads(jd_str)
16-
if format == 'json':
17-
yield json_data
18-
elif format == 'text':
19-
for item in json_data['choices']:
20-
yield item['delta']['content']
9+
yield chunk
2110
except Exception as e:
22-
print(f"Error occurred: {e}")
11+
print(f"Error occurred: {e}", chunk)
2312
finally:
2413
response.close()
2514

26-
def handle_non_stream(response: requests.Response,
27-
format: Literal['json', 'text']) -> str | Dict[Any, Any]:
15+
def handle_non_stream(response: requests.Response) -> str:
2816
try:
29-
json_data = response.json()
30-
if format == 'json':
31-
return json_data
32-
elif format == 'text':
33-
return json_data['choices'][0]['message']['content']
17+
text = response.json()
18+
return text
3419
except Exception as e:
3520
print(f"Error occurred: {e}")
3621
finally:

0 commit comments

Comments
 (0)