Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Update Azure API #1440

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/revChatGPT/V3.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,18 @@ def ask_stream(
self.add_to_conversation(prompt, "user", convo_id=convo_id)
self.__truncate_conversation(convo_id=convo_id)
# Get response
if os.environ.get("API_URL") and os.environ.get("MODEL_NAME"):
# https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?tabs=command-line&pivots=rest-api
url = os.environ.get("API_URL") + "openai/deployments/" + os.environ.get("MODEL_NAME") +"/chat/completions?api-version=2023-05-15"
headers = {"Content-Type": "application/json", "api-key": self.api_key}
else:
url = "https://api.openai.com/v1/chat/completions"
headers = {"Authorization": f"Bearer {kwargs.get('api_key', self.api_key)}"}
response = self.session.post(
os.environ.get("API_URL") or "https://api.openai.com/v1/chat/completions",
headers={"Authorization": f"Bearer {kwargs.get('api_key', self.api_key)}"},
url,
headers=headers,
json={
"model": model or self.engine,
"model": os.environ.get("MODEL_NAME") or model or self.engine,
"messages": self.conversation[convo_id] if pass_history else [prompt],
"stream": True,
# kwargs
Expand Down Expand Up @@ -737,3 +744,4 @@ def main() -> NoReturn:
except KeyboardInterrupt:
print("\nExiting...")
sys.exit()