Guest User

llm-character-gen.bash

a guest
Jan 2nd, 2025
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. model="llama-3.2-3b-instruct"
  4.  
  5. #Gender is a 50/50.  No need for an LLM there.
  6. gender=$([ $((RANDOM % 2)) -eq 0 ] && echo "Male" || echo "Female")
  7.  
  8.  
  9. #Ancestry; Trying for a high variation here.
  10. ancestry=$(curl -s http://localhost:9090/v1/chat/completions   -H "Content-Type: application/json"   -d '{
  11.    "model": "${model}",
  12.    "messages": [
  13.      { "role": "system", "content": "You are a character generator.  You give the shortest possible answer you can." },
  14.      { "role": "user", "content": "Pick a random ancestry for the human character.  It can be any regular Earth ancestry.  Pick anywhere from the planet." }
  15.    ],
  16.    "temperature": 10,
  17.    "max_tokens": -1,
  18.    "stream": false
  19. }' | jq '.choices[].message.content' | sed -e 's/ \\n"//g' | tr -cd '[:alnum:][:space:]' )
  20.  
  21. #Last Name;  We feed ancestry and gender here so the last name should be less random.
  22. lastn=$(curl -s http://localhost:9090/v1/chat/completions   -H "Content-Type: application/json"   -d "{
  23.    \"model\": \"${model}\",
  24.    \"messages\": [
  25.      { \"role\": \"system\", \"content\": \"You are a character generator.  You give the shortest possible answer you can.\" },
  26.      { \"role\": \"user\", \"content\": \"Give the last name of a ${ancestry}, ${gender} character.\" }
  27.    ],
  28.    \"temperature\": 0.8,
  29.    \"max_tokens\": -1,
  30.    \"stream\": false
  31. }" | jq '.choices[].message.content' | sed -e 's/ \\n//g' | tr -cd '[:alnum:][:space:]' )
  32.  
  33. #First name.  Narrowing down what the LLM thinks the first name should be now that we know the ancestry, gender and last name.
  34. firstn=$(curl -s http://localhost:9090/v1/chat/completions   -H "Content-Type: application/json"   -d "{
  35.    \"model\": \"${model}\",
  36.    \"messages\": [
  37.      { \"role\": \"system\", \"content\": \"You are a character generator.  You give the shortest possible answer you can.\" },
  38.      { \"role\": \"user\", \"content\": \"Give the first name of a ${ancestry}, ${gender} character with the ${lastn} surname.\" }
  39.    ],
  40.    \"temperature\": 0.8,
  41.    \"max_tokens\": -1,
  42.    \"stream\": false
  43. }" | jq '.choices[].message.content' | sed -e 's/ \\n//g' | tr -cd '[:alnum:][:space:]' )
  44.  
  45. occu=$(curl -s http://localhost:9090/v1/chat/completions   -H "Content-Type: application/json"   -d "{
  46.    \"model\": \"${model}\",
  47.    \"messages\": [
  48.      { \"role\": \"system\", \"content\": \"You are a character generator.  You give the shortest answer possible.\" },
  49.      { \"role\": \"user\", \"content\": \"Give the modern occupation of ${firstn} ${lastn}, a ${gender} of ${ancestry} ancestry.\" }
  50.    ],
  51.    \"temperature\": 1.8,
  52.    \"max_tokens\": -1,
  53.    \"stream\": false
  54. }" | jq '.choices[].message.content' | sed -e 's/ \\n//g' | tr -cd '[:alnum:][:space:]' )
  55. hair=$(curl -s http://localhost:9090/v1/chat/completions   -H "Content-Type: application/json"   -d "{
  56.    \"model\": \"${model}\",
  57.    \"messages\": [
  58.      { \"role\": \"system\", \"content\": \"You are a character generator.  You give the shortest answer possible.\" },
  59.      { \"role\": \"user\", \"content\": \"We are considering ${firstn} ${lastn}, a ${gender} of ${ancestry} ancestry.  Their occupation is ${occu}.  What should their hair color be?\" }
  60.    ],
  61.    \"temperature\": 1.8,
  62.    \"max_tokens\": -1,
  63.    \"stream\": false
  64. }" | jq '.choices[].message.content' | sed -e 's/ \\n//g' | tr -cd '[:alnum:][:space:]' )
  65. echo "${ancestry}, ${gender}, ${firstn}, ${lastn}, ${occu}, ${hair} hair."
  66. curl -s http://localhost:9090/v1/chat/completions   -H "Content-Type: application/json"   -d "{
  67.    \"model\": \"${model}\",
  68.    \"messages\": [
  69.      { \"role\": \"system\", \"content\": \"You are a character generator.  You give the shortest answer possible.\" },
  70.      { \"role\": \"user\", \"content\": \"We are considering ${firstn} ${lastn}, a ${gender} of ${ancestry} ancestry.  Their occupation is ${occu}.  Their hair color is ${hair}.  Write a DALL-E description of them.\" }
  71.    ],
  72.    \"temperature\": 1.8,
  73.    \"max_tokens\": -1,
  74.    \"stream\": false
  75. }" | jq '.choices[].message.content'
  76.  
Advertisement
Add Comment
Please, Sign In to add comment