[Bug][api][python] A prompt variable named role is taken as the message role

Aperta Adatta ai principianti
#1,480 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java, python
Ambito
api, backend

Direzione di ricerca

Inizia con l’implementazione Python di Prompt.format_messages nel pacchetto prompts e segui i suoi chiamanti in react_agent.py e chat_model.py; confrontala con la firma Java di formatMessages. Riproduci i casi di prompt testuali e di messaggi dell’issue. Il lavoro è completato quando role raggiunge il template come variabile e il comportamento esistente dei ruoli dei messaggi rimane corretto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Search before asking
  • I searched in the issues and found nothing similar.
Description

Python Prompt.format_messages(role=MessageRole.SYSTEM, **kwargs) takes the message role as a keyword parameter, so a template variable named role can never reach the template:

  • A text prompt fails: Prompt.from_text("You are {role}.").format_messages(role="a pirate") raises a ValidationError for ChatMessage, because "a pirate" is used as the message role.
  • A messages prompt leaves {role} unsubstituted: the value is consumed as the role argument.
  • ReActAgent fails with TypeError: format_messages() got multiple values for keyword argument 'role' when its input has a role field, since it calls format_messages(role=MessageRole.USER, **input) (react_agent.py).
  • A chat model setup's prompt_args={"role": ...} reaches format_messages(**prompt_args) (chat_model.py) and hits the first two cases.

Java's formatMessages(MessageRole defaultRole, Map<String, String> kwargs) keeps the role separate from the variables, and the Prompt Javadoc example itself uses a {role} variable, so only Python is affected.

Expected: role is an ordinary template variable, as in Java.

How to reproduce
from flink_agents.api.chat_message import ChatMessage
from flink_agents.api.prompts.prompt import Prompt

Prompt.from_text("You are {role}.").format_messages(role="a pirate")
# ValidationError: 1 validation error for ChatMessage

Prompt.from_messages([ChatMessage.system("You are {role}.")]).format_messages(role="a pirate")
# [system: "You are {role}."]
Version and environment

main at 0f83f4b9, Python 3.11, macOS.

Are you willing to submit a PR?
  • I'm willing to submit a PR!
Lingua principale
Java
Stelle
497
Fork
193
Merge medio
2g 21h
PR unite (30g)
68

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/flink-agents

Tutte le issue di apache/flink-agents

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.