-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace openai usage with xpert api
- Loading branch information
1 parent
7fe3b76
commit f039b99
Showing
7 changed files
with
57 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Your project description goes here. | ||
""" | ||
|
||
__version__ = "4.20.14" | ||
__version__ = "4.21.0" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Xpert client | ||
""" | ||
|
||
import json | ||
|
||
import requests | ||
|
||
from django.conf import settings | ||
|
||
CONNECT_TIMOUET_SECONDS = 5 | ||
READ_TIMEOUT_SECONDS = 20 | ||
|
||
|
||
def chat_completion(prompt, role): | ||
""" | ||
Generate response using xpert api. | ||
Arguments: | ||
prompt (str): ChatGPT prompt | ||
role (str): ChatGPT role to assume for the prompt. | ||
Returns: | ||
(str): Prompt response from OpenAI. | ||
""" | ||
headers = { | ||
'Content-Type': 'application/json', | ||
'x-api-key': settings.CHAT_COMPLETION_API_KEY | ||
} | ||
|
||
body = {'message_list': [{'role': role, 'content': prompt},]} | ||
|
||
response = requests.post( | ||
settings.CHAT_COMPLETION_API, | ||
headers=headers, | ||
data=json.dumps(body), | ||
timeout=(CONNECT_TIMOUET_SECONDS, READ_TIMEOUT_SECONDS) | ||
) | ||
|
||
return response.json().get('content') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters