Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
davila7 committed Jan 28, 2024
1 parent f156f3d commit 551ec37
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/judini/codegpt/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ def create(self, agent_id, messages, stream=False):
"messages": messages
})

conn = http.client.HTTPSConnection("api-beta.codegpt.co")
url = "/api/v1/chat/completions"

conn.request("POST", url, body=payload, headers=headers)
res = conn.getresponse()
try:
data = res.read()
except Exception as e:
print(f"An error occurred: {e.__class__.__name__}")
print(f"Error details: {str(e)}")

content_data = ""
if stream is False:
data.decode("utf-8").replace('\n','').split('data: ')[1:]
for jd_str in data:
if jd_str:
try:
# data: {}
json_data = json.loads(jd_str)
for item in json_data['choices']:
content_data += item['delta']['content']
except:
# data: [DONE]
pass

return content_data
else:
try:
return data.decode("utf-8").replace('\n','').split('data: ')[1:]
except Exception as e:
print(f"An error occurred: {e.__class__.__name__}")
print(f"Error details: {str(e)}")
# conn = http.client.HTTPSConnection("api-beta.codegpt.co")
# url = "/api/v1/chat/completions"

# conn.request("POST", url, body=payload, headers=headers)
# res = conn.getresponse()
# try:
# data = res.read()
# except Exception as e:
# print(f"An error occurred: {e.__class__.__name__}")
# print(f"Error details: {str(e)}")

# content_data = ""
# if stream is False:
# data.decode("utf-8").replace('\n','').split('data: ')[1:]
# for jd_str in data:
# if jd_str:
# try:
# # data: {}
# json_data = json.loads(jd_str)
# for item in json_data['choices']:
# content_data += item['delta']['content']
# except:
# # data: [DONE]
# pass

# return content_data
# else:
# try:
# return data.decode("utf-8").replace('\n','').split('data: ')[1:]
# except Exception as e:
# print(f"An error occurred: {e.__class__.__name__}")
# print(f"Error details: {str(e)}")

0 comments on commit 551ec37

Please sign in to comment.