@@ -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 ##############
0 commit comments