Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Shape, prompt/promptStreaming should use AIAssistantPrompt rather than DOMString input #28

Closed
sushraja-msft opened this issue Aug 9, 2024 · 3 comments · Fixed by #32

Comments

@sushraja-msft
Copy link

sushraja-msft commented Aug 9, 2024

The prompt API feels inconsistent because the create option AIAssistantCreateOptions takes AIAssistantPrompt, while the AIAssistant interface takes a DOMString as input.

dictionary AIAssistantCreateOptions {
  AbortSignal signal;
  AICreateMonitorCallback monitor;

  DOMString systemPrompt;
  sequence<AIAssistantPrompt> initialPrompts;
  [EnforceRange] unsigned long topK;
  float temperature;
};

dictionary AIAssistantPrompt {
  AIAssistantPromptRole role;
  DOMString content;
};
interface AIAssistant : EventTarget {
  Promise<DOMString> prompt(DOMString input, optional AIAssistantPromptOptions options = {});
  ReadableStream promptStreaming(DOMString input, optional AIAssistantPromptOptions options = {});
}

Practically this means that the prompt / promptStreaming methods assume that the new input is necessarily for the user role.

This limits the API, in that when function calling or multiple agents want to add a response to the conversation, they cannot breakout of the user role.

It would be better to have

  Promise<DOMString> prompt(AIAssistantPrompt input, optional AIAssistantPromptOptions options = {});
  ReadableStream promptStreaming(AIAssistantPrompt input, optional AIAssistantPromptOptions options = {});

This would allow tool call responses to be added to the chat as an assistant role.
Supporting multiple agents is still not possible, but this can be managed with an AIAssistantPrompt such as

<assistant> response from ratingAgent: This response looks appropriate </assistant>

for a hypothetical use case where the previous assistant message was a request for a rating agent to review a message.

@domenic
Copy link
Collaborator

domenic commented Aug 14, 2024

I think this makes sense. Looking at various API documentation and playing with some cases, although the examples all assume an alternating user/assistant role, the format doesn't seem to require that.

I'll add overloads for adding multiple messages at once, and keep the simple string version for user.

@domenic
Copy link
Collaborator

domenic commented Aug 14, 2024

Additionally, I note that some APIs have "tool" and "function" as a role. We should consider adding that if we want to make tool-use a fully supported part of the API. But there are more considerations there, so I'll leave them out for now, and people can use hacks as you suggest.

domenic added a commit that referenced this issue Aug 14, 2024
domenic added a commit that referenced this issue Aug 14, 2024
@Yvem
Copy link

Yvem commented Sep 2, 2024

I agree that there is a surprise here.
I noticed the AIAssistantPromptRole = 'system' | 'user' | 'assistant' in the initialPrompts output property and wondered where it comes from since it's not in the input.
Clarification welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants