Spaces:
Sleeping
Sleeping
File size: 2,190 Bytes
7d6d833 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import time
class Presenter():
def __init__(self, general_context, client, model):
"""
Initialise le présentateur du débat,
qui reçoit les promps du joueur pour relancer
le débat
contient des méthodes hard codées pour
lancer le débat et le clore dans le cas où
un candidat a quitté le débat ou si
tout le public est parti
"""
self.client = client
self.model = model
self.general_context = general_context
self.own_history = []
def play_card(self, card, last_sentence_said, previous_speaker, next_speaker, max_tokens=500):
"""
card is a dictionnary
candidates input: contains the last sentences said by
the candidates
card:{card topic : attitude} and comes from
the player if the latter decided to play a card.
"""
input_instruction = f"""You are the moderator
of the TV debate. You have to ask a question to the candidates
{next_speaker.name}. Note that the candidate is in the following attitude : {next_speaker.attitudes}.
Here is thesubject of the question you have to ask: {card.description}.
To give a bit of context, here is the last answer of the candidate {previous_speaker.name}: {last_sentence_said}.
Keep it brief.
"""
messages = [
{
"role": "system",
"content": (
f"General context: {self.general_context}\n"
),
},
{
"role": "user",
"content": (
f"Instructions: {input_instruction}\n"
),
},
]
# Call the chat completion API
time.sleep(1)
chat_response = self.client.chat.complete(
model=self.model,
messages=messages,
max_tokens=max_tokens, # Adjust this value as needed
)
# Extract and return the assistant's response
out=chat_response.choices[0].message.content
self.own_history.append({'user' : out})
return out
|