Skip to content

Instantly share code, notes, and snippets.

@ngould
Created April 25, 2024 14:53
Show Gist options
  • Save ngould/5a986be8c5f9d46340078bd359c0b19b to your computer and use it in GitHub Desktop.
Save ngould/5a986be8c5f9d46340078bd359c0b19b to your computer and use it in GitHub Desktop.
import os
import random
from openai import OpenAI
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
survey_options = [
"Help Scout",
"Intercom",
"Zendesk",
"Freshdesk",
"Front",
]
survey_questions = [
'Which product offers overall better ease of use?',
'Which company offers better customer support?',
'Which product is the best value for small businesses?',
'Which product has the most complete set of functionality for large enterprises?',
'Which product offers better integrations with other tools?',
'Which product offers the best reporting?',
'Which product offers the most advanced AI capabilities?',
'Which product do you perceive as the most up-and-coming?',
'Which product is best for in-app support?',
'Which product is best for email support?',
]
def ask_gpt(survey_question, survey_options):
# Define the initial prompt
random.shuffle(survey_options) # Shuffle to avoid biasing results based on order
tool_list = ", ".join(survey_options)
initial_prompt = ("You are a participant in a survey about customer support tools: "
f"Answer the question below, comparing the following options: {tool_list}.\n\n"
f"Question: {survey_question}")
print("Initial Prompt: ", initial_prompt)
# Start the conversation with GPT-3.5
messages=[
{"role": "user", "content": initial_prompt}
]
chat = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
max_tokens=500,
temperature=1.0,
)
# Print the initial response
initial_response = chat.choices[0].message.content
messages.append({"role": "assistant", "content": initial_response})
print("Response: ", initial_response)
# Define the follow-up prompt
follow_up_prompt = "Now choose one tool that best answers the question. Answer with just the name of the tool."
messages.append({"role": "user", "content": follow_up_prompt})
# Continue the conversation with the follow-up question
follow_up_chat = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=1.0,
)
# Print the follow-up response
follow_up_response = follow_up_chat.choices[0].message.content
return {
"initial_prompt": initial_prompt,
"initial_response": initial_response,
"follow_up_prompt": follow_up_prompt,
"follow_up_response": follow_up_response,
}
if __name__ == "__main__":
results = []
counter = 0
for question in survey_questions:
for i in range(100):
counter += 1
print(f"\n\nQUESTTION NUMBER: {counter}\n\n")
result = ask_gpt(question, survey_options)
results.append({
"survey_question": question,
"response": result['follow_up_response'],
})
# Write results to CSV
with open("survey_results.csv", "w") as file:
file.write("Survey Question,Response\n")
for result in results:
file.write(f"{result['survey_question']},{result['response']}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment