Ulad Melekh
Ulad Melekh

Reputation: 944

Dialogs in OpenAI

Afaik, there're two ways of interacting with text OpenAI api now: completions and chat. I want to build this:

  1. Application receives messages from user1 and user2 and sends messages to OpenAI like it's a dialog.
  2. OpenAI just listens and only replies if it sees some pattern in the conversation.

Is it possible to achieve somehow? Thank you.

Upvotes: 0

Views: 62

Answers (1)

Paul McMillan
Paul McMillan

Reputation: 20127

I'd suggest using the Chat interface. You can't set roles for multiple users yet, but send the model something like this:

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "Say something if you detect a pattern in the user messages. Otherwise say nothing."},
    {"role": "user", "content": "User1: I'm in charge."},
    {"role": "user", "content": "User2: I'mway inway hargecay."},
    {"role": "user", "content": "User1: stop repeating me"},
    {"role": "user", "content": "User2: opstay epeatingray emay."}
  ]
)
print(response.choices[0].message.content)
% python foo.py
User1 and User2 are both speaking in Pig Latin.

Upvotes: 1

Related Questions