ollama/examples/typescript-mentors
Dr Nic Williams e8aaea030e
Update 'llama2' -> 'llama3' in most places (#4116)
* Update 'llama2' -> 'llama3' in most places

---------

Co-authored-by: Patrick Devine <patrick@infrahq.com>
2024-05-03 15:25:04 -04:00
..
.gitignore final rename 2023-10-12 11:23:41 -07:00
character-generator.ts Update 'llama2' -> 'llama3' in most places (#4116) 2024-05-03 15:25:04 -04:00
mentors.ts Update readmes, requirements, packagejsons, etc for all examples (#1452) 2023-12-22 09:10:41 -08:00
package.json Update readmes, requirements, packagejsons, etc for all examples (#1452) 2023-12-22 09:10:41 -08:00
README.md Update 'llama2' -> 'llama3' in most places (#4116) 2024-05-03 15:25:04 -04:00

Ask the Mentors

This example demonstrates how one would create a set of 'mentors' you can have a conversation with. The mentors are generated using the character-generator.ts file. This will use Stable Beluga 70b to create a bio and list of verbal ticks and common phrases used by each person. Then mentors.ts will take a question, and choose three of the 'mentors' and start a conversation with them. Occasionally, they will talk to each other, and other times they will just deliver a set of monologues. It's fun to see what they do and say.

Usage

  1. Add llama3 to have the mentors ask your questions:

    ollama pull llama3
    
  2. Install prerequisites:

    npm install
    
  3. Ask a question:

    npm start "what is a jackalope"
    

You can also add your own character to be chosen at random when you ask a question.

  1. Make sure you have the right model installed:

    ollama pull stablebeluga2:70b-q4_K_M
    
  2. Create a new character:

    npm run charactergen "Lorne Greene"
    

    You can choose any well-known person you like. This example will create lornegreene/Modelfile.

  3. Now you can create a model with this command:

    ollama create <username>/lornegreene -f lornegreene/Modelfile
    

    username is whatever name you set up when you signed up at https://ollama.com/signup.

  4. To add this to your mentors, you will have to update the code as follows. On line 8 of mentors.ts, add an object to the array, replacing <username> with the username you used above.

    {ns: "<username>", char: "Lorne Greene"}
    

Review the Code

There are two scripts you can run in this example. The first is the main script to ask the mentors a question. The other one lets you generate a character to add to the mentors. Both scripts are mostly about adjusting the prompts at each inference stage.

mentors.ts

In the main function, it starts by generating a list of mentors. This chooses 3 from a list of interesting characters. Then we ask for a question, and then things get interesting. We set the prompt for each of the 3 mentors a little differently. And the 2nd and 3rd mentors see what the previous folks said. The other functions in mentors sets the prompts for each mentor.

character-generator.ts

Character Generator simply customizes the prompt to build a character profile for any famous person. And most of the script is just tweaking the prompt. This uses Stable Beluga 2 70b parameters. The 70b models tend to do better writing a bio about a character than smaller models, and Stable Beluga seemed to do better than Llama 2. Since this is used at development time for the characters, it doesn't affect the runtime of asking the mentors for their input.