microsoft / TypeChat

TypeChat is a library that makes it easy to build natural language interfaces using types.
https://microsoft.github.io/TypeChat/
MIT License
8.16k stars 390 forks source link

Add support for prompt roles and prompt preambles #114

Closed ahejlsberg closed 11 months ago

ahejlsberg commented 1 year ago

This PR adds support for prompt roles, i.e. prompt sections tagged with "system", "user", or "assistant" roles. TypeChat uses the "user" role for prompts it generates and the "assistant" role for previous LLM responses (which will be part of the prompt in repair attempts). TypeChat currently doesn't use the "system" role.

This PR also adds support for specifying a prompt preamble when processing requests. This makes it easier to implement chat-like interactions and conversation history.

Githamza commented 10 months ago

How can I try it ? I have installed the last version (v0.0.10) of typechat but in node_modules/typechat, these additions does not exists

thenbe commented 10 months ago

@Githamza The version you downloaded from npm is 4 months old. Instead of installing it from npm:

  1. clone this repo to your pc
  2. build it from source
  3. see npm link or pnpm link to use your local version of typechat in other projects
Githamza commented 10 months ago

Thanks , I have a question ,the request parameter mandatory. If I would send a promptPreamble with system and user roles , what should I put in request param ? for me request content is the user role content ? Actually I send the same string in request param and also in the user role ( in it's content property )

olawalejuwonm commented 7 months ago

How can this be used please?

kad3nce commented 4 months ago

@olawalejuwonm, the key change is here: https://github.com/microsoft/TypeChat/pull/114/files#diff-1ece2a0b089b56f4aa22ef64be65b4305b5e890b560a39d9d12140f9a42d40f4R104

Add a user message preamble:

translator.translate(data, 'Hello there');

Add a system prompt:

translator.translate(data, [
  { role: 'system', content: 'You are an expert data anonymizer...' }
]);
olawalejuwonm commented 4 months ago

How do I pass the user content then?