Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions API_Call_Via_ChatGPT/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
*.pyc
31 changes: 19 additions & 12 deletions API_Call_Via_ChatGPT/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
# python chat.py
#########################################

import openai
from openai import OpenAI
import requests
from dotenv import load_dotenv
import os

# API end points
fdenquiry_url = 'http://127.0.0.1:8000/fdenquiry/'
fdmaturity_url = 'http://127.0.0.1:8000/fdmaturity/'

# Setup your own OpenAI API key
openai.api_key = "API_KEY"
# Setup OpenAI API
# Load the environment variables from .env file
load_dotenv()

client = OpenAI(
# Setup your own OpenAI API key
api_key= os.getenv("OPENAI_API_KEY")
)

class BankChat(object):
'''
Expand Down Expand Up @@ -76,34 +84,33 @@ def intent_detection(self, conversation):
chat_ml = [
{"role": "user", "content": self.INTENT_DETECTION_SETUP_PROMPT.format(conversation=conversation)}
]
response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=chat_ml,
temperature=0)

return response['choices'][0]['message']['content'].strip(" \n'")
return response.choices[0].message.content.strip(" \n'")

def fd_enquiry_details(self, conversation):
chat_ml = [
{"role": "user", "content": self.FD_ENQUIRY_DETAILS_PROMPT.format(conversation=conversation)}
]
response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=chat_ml,
temperature=0)

return response['choices'][0]['message']['content'].strip(" \n")
return response.choices[0].message.content.strip(" \n")

def fd_maturity_enquiry_details(self, conversation):
chat_ml = [
{"role": "user", "content": self.FD_MATURITY_ENQUIRY_DETAILS_PROMPT.format(conversation=conversation)}
]
response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=chat_ml,
temperature=0)

return response['choices'][0]['message']['content'].strip(" \n")
return response.choices[0].message.content.strip(" \n")

def conversation_chat(self):
conversation = "" # Captures the conversation between agent and the customer
Expand All @@ -116,12 +123,12 @@ def conversation_chat(self):
]

while True:
response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=chatml_messages
)

agent_response = response['choices'][0]['message']['content'].strip(" \n")
agent_response = response.choices[0].message.content.strip(" \n")

if "END_OF_CONVERSATION" in agent_response:
print("Agent: Thank you for connecting with us. Have a nice day!")
Expand Down