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

Commit

Permalink
Update Azure API (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
luping-liu authored Jun 26, 2023
1 parent 4e2ca19 commit cc07e2f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/revChatGPT/V3.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,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 @@ -736,3 +743,4 @@ def main() -> NoReturn:
except KeyboardInterrupt:
print("\nExiting...")
sys.exit()

0 comments on commit cc07e2f

Please sign in to comment.