simonw / llm-palm

Plugin for LLM adding support for Google's PaLM 2 model
Apache License 2.0
14 stars 4 forks source link

Update for conversation support #3

Closed simonw closed 1 year ago

simonw commented 1 year ago

Refs:

simonw commented 1 year ago

Docs for the chat() function I'm using: https://github.com/google/generative-ai-python/blob/62671ec8cfcf5e655e50c8baf42a33c773e0d620/google/generativeai/discuss.py#L248

Relevant types:

MessageOptions = Union[str, MessageDict, glm.Message]
MESSAGE_OPTIONS = (str, dict, glm.Message)

MessagesOptions = Union[
    MessageOptions,
    Iterable[MessageOptions],
]
MESSAGES_OPTIONS = (MESSAGE_OPTIONS, Iterable)
def chat(
    *,
    model: Optional[model_types.ModelNameOptions] = "models/chat-bison-001",
    context: Optional[str] = None,
    examples: Optional[discuss_types.ExamplesOptions] = None,
    messages: Optional[discuss_types.MessagesOptions] = None,
    temperature: Optional[float] = None,
    candidate_count: Optional[int] = None,
    top_p: Optional[float] = None,
    top_k: Optional[float] = None,
    prompt: Optional[discuss_types.MessagePromptOptions] = None,
    client: Optional[glm.DiscussServiceClient] = None,
) -> discuss_types.ChatResponse:

And docs:

        messages: A snapshot of the conversation history sorted chronologically.

            Turns alternate between two authors.

            If the total input size exceeds the model's `input_token_limit` the input
            will be truncated: The oldest items will be dropped from `messages`.
        prompt: You may pass a `types.MessagePromptOptions` **instead** of a
            setting `context`/`examples`/`messages`, but not both.
simonw commented 1 year ago

Got this to work:

llm -m palm 'What is the capital of France?'

The capital of France is Paris. It is the most populous city in France and the second most populous city in the European Union. Paris is a major center for business, finance, fashion, gastronomy, science, and arts. The city is home to many world-famous landmarks, including the Eiffel Tower, the Louvre Museum, and the Notre Dame Cathedral.

llm -c 'What do they like to eat there?'

French cuisine is known for its rich flavors, delicate textures, and beautiful presentation. Some of the most popular French dishes include:

  • Escargots: Snails cooked in garlic butter and herbs.
  • Coq au vin: Chicken stewed in red wine with mushrooms and bacon.
  • Boeuf bourguignon: Beef stewed in red wine with onions, carrots, and mushrooms.
  • Ratatouille: A Provençal dish of eggplant, zucchini, tomatoes, and other vegetables cooked in olive oil.
  • Soufflé: A light, airy dish made with eggs, flour, and milk.
  • Crêpes: Thin pancakes made from wheat flour, eggs, and milk.
  • Tarte Tatin: An upside-down apple tart.
  • Macarons: Small, round cookies made from almond flour, egg whites, and sugar.
  • Chocolate mousse: A light, airy dessert made from chocolate, eggs, and cream.
  • Île flottante: A dessert made from poached meringue floating in a custard sauce.
  • Profiteroles: Cream puffs filled with whipped cream or ice cream.
  • Crème brûlée: A custard dessert topped with a layer of caramelized sugar.

French cuisine is also known for its use of fresh ingredients, such as fruits, vegetables, and herbs. Many French dishes are made with seasonal ingredients, which means that the flavors of the food change throughout the year.

French cuisine is a complex and sophisticated cuisine that has been influenced by many different cultures over the years. It is a cuisine that is constantly evolving, and there are always new and innovative dishes being created.

llm -c 'Describe their flag'

The flag of France is a tricolor flag with three vertical bands of equal width, blue, white, and red. The blue band is on the hoist side (the side closest to the flagpole). The flag was adopted on February 15, 1794, during the French Revolution.

The colors of the French flag have a long and complex history. The blue and red colors were first used in the flag of the city of Paris in the 13th century. The white color was added to the flag in the 17th century to represent the House of Bourbon, the ruling dynasty of France at the time.

The colors of the French flag have been interpreted in many different ways. Some people believe that the blue represents the sky, the white represents the snow, and the red represents the blood of the French people who died in the French Revolution. Others believe that the colors represent the three estates of the French monarchy: the clergy (blue), the nobility (white), and the commoners (red).

The French flag is a symbol of French patriotism and national pride. It is flown at government buildings, schools, and other public places. The flag is also flown at sporting events and other occasions when France is represented.

The French flag is one of the most recognizable flags in the world. It is a symbol of France's rich history and culture. The flag is a source of pride for the French people and a reminder of the country's commitment to liberty, equality, and fraternity.

simonw commented 1 year ago

PaLM is pretty slow:

sqlite-utils "$(llm logs path)" 'select substr(response, 0, 20), duration_ms from responses order by id desc limit 3'
[{"substr(response, 0, 20)": "The flag of France ", "duration_ms": 6761},
 {"substr(response, 0, 20)": "French cuisine is k", "duration_ms": 17956},
 {"substr(response, 0, 20)": "The capital of Fran", "duration_ms": 4851},

So those prompts took 4.8s, 18s and 6.7s.