Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
custom chatbotid
  • Loading branch information
kwekewk committed Apr 13, 2023
1 parent 24ad26e commit 3d7dd87
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
49 changes: 31 additions & 18 deletions ora/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,29 @@
from requests import post
from time import time
from random import randint
from uuid import uuid4

class Completion:
def create(
model : CompletionModel,
def create(
prompt: str,
model : CompletionModel = None,
chatbot_id: str = None,
user_id: str = None,
includeHistory: bool = True,
conversationId: str or None = None) -> OraResponse:


if model is None:
model = CompletionModel.create()

extra = {
'conversationId': conversationId} if conversationId else {}

response = post('https://ora.sh/api/conversation',

if user_id is None:
user_id = model.createdBy.replace("auto:", "") if model else str(uuid4())



response = post('https://ora.sh/api/conversation',
headers = {
"host" : "ora.sh",
"authorization" : f"Bearer AY0{randint(1111, 9999)}",
Expand All @@ -23,27 +34,29 @@ def create(
"referer" : "https://ora.sh/chat/",
},
json = extra | {
'chatbotId': model.id,
'chatbotId': chatbot_id if chatbot_id else model.id,
'input' : prompt,
'userId' : model.createdBy,
'model' : 'gpt-3.5-turbo',
'userId' : user_id if user_id else model.createdBy,
'model' : 'gpt-4',
'provider' : 'OPEN_AI',
'includeHistory': includeHistory}).json()


print(response)

return OraResponse({
'id' : response['conversationId'],
'object' : 'text_completion',
'id' : response['conversationId'],
'object' : 'text_completion',
'created': int(time()),
'model' : model.slug,
'model' : model.slug if model else None,
'choices': [{
'text' : response['response'],
'index' : 0,
'logprobs' : None,
'text' : response['response'],
'index' : 0,
'logprobs' : None,
'finish_reason' : 'stop'
}],
'usage': {
'prompt_tokens' : len(prompt),
'completion_tokens' : len(response['response']),
'prompt_tokens' : len(prompt),
'completion_tokens' : len(response['response']),
'total_tokens' : len(prompt) + len(response['response'])
}
})
})
20 changes: 12 additions & 8 deletions ora/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ class CompletionModel:
def create(
system_prompt: str = 'You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible',
description : str = 'ChatGPT Openai Language Model',
name : str = 'gpt-3.5'):
name : str = 'gpt-3.5',
chatbot_id: str = None):

CompletionModel.system_prompt = system_prompt
CompletionModel.description = description
CompletionModel.slug = name

response = post('https://ora.sh/api/assistant', json = {
'prompt' : system_prompt,
'userId' : f'auto:{uuid4()}',
'name' : name,
'description': description})

if chatbot_id:
CompletionModel.id = chatbot_id
else:
response = post('https://ora.sh/api/assistant', json = {
'prompt' : system_prompt,
'userId' : f'auto:{uuid4()}',
'name' : name,
'description': description})

CompletionModel.id = response.json()['id']
CompletionModel.createdBy = response.json()['createdBy']
CompletionModel.createdAt = response.json()['createdAt']

return CompletionModel


0 comments on commit 3d7dd87

Please sign in to comment.