Skip to content

Commit

Permalink
feat: sending previous message through assistant to gpt3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienHdz committed Oct 16, 2023
1 parent 9f6a2cc commit 2543f29
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions backend/avatar_assistant_api/api/generator/script_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,32 @@ def get_response_script(self, session_id: str, input_message: str) -> str:
# Check if a response for this session_id already exists in Redis
prev_response = redis_helper.get(session_id)

print(f"REDIS PREV_RESPONSE: {prev_response}")
messages = [
{
"role": "system",
"content": """You are a customer service representative of Cymbal.
Here is Cymbal policy: How many days do I have to return my purchase?
We offer free returns and exchanges within 30 days of your delivery,
with exceptions as described in our Returns Policy.
Certain items are designated as final sale and not eligible for returns or exchanges.
All on-sale purchases are final.""",
},
{"role": "user", "content": input_message},
]

# Append the previous response to the messages if it exists
if prev_response:
messages.append({"role": "assistant", "content": prev_response})

response = openai.ChatCompletion.create(
model=self.model,
max_tokens=self.max_token,
temperature=self.temperature,
messages=[
{
"role": "system",
"content": """You are a customer service representative of Cymbal.
Here is Cymbal policy: How many days do I have to return my purchase?
We offer free returns and exchanges within 30 days of your delivery, with exceptions as described in our Returns Policy. Certain items are designated as final sale and not eligible for returns or exchanges. All on-sale purchases are final.""",
},
{"role": "user", "content": input_message},
],
messages=messages,
)
response = response["choices"][0]["message"]["content"]

# Store previous response in Redis
# Store the latest response in Redis
redis_helper.set(session_id, response)

# If a previous response exists, print the latest response (optional, based on your requirements)
Expand Down

0 comments on commit 2543f29

Please sign in to comment.