Skip to content

Commit

Permalink
Chatbot baseprompt updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Mar 12, 2024
1 parent fc74f8d commit 73106ea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
6 changes: 6 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Releases

## 0.14.1 - Chatbot Baseprompt

* Fixed bug with baseprompt updates to respond to saved Settings or new sessions.
* Updated baseprompt to include date and guidance for complex and open-ended questions.
* Add `TZ` local timezone environmental variable to ensure correct date in baseprompt.

## 0.14.0 - Chatbot Controls

* Added ability to change LLM Temperature and MaxTokens in settings.
Expand Down
1 change: 1 addition & 0 deletions chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ docker run \
-p 5000:5000 \
-e PORT=5000 \
-e OPENAI_API_BASE="http://localhost:8000/v1" \
-e TZ="America/Los_Angeles" \
-v $PWD/.tinyllm:/app/.tinyllm \
--name chatbot \
--restart unless-stopped \
Expand Down
1 change: 1 addition & 0 deletions chatbot/run-openai.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ docker run \
-e ONESHOT="false" \
-e WEAVIATE_HOST="" \
-e WEAVIATE_LIBRARY="tinyllm" \
-e TZ="America/Los_Angeles" \
-v $PWD/.tinyllm:/app/.tinyllm \
--name chatbot \
--restart unless-stopped \
Expand Down
1 change: 1 addition & 0 deletions chatbot/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ docker run \
-e RAG_ONLY="false" \
-e WEAVIATE_HOST="" \
-e WEAVIATE_LIBRARY="tinyllm" \
-e TZ="America/Los_Angeles" \
-v $PWD/.tinyllm:/app/.tinyllm \
--name chatbot \
--restart unless-stopped \
Expand Down
22 changes: 10 additions & 12 deletions chatbot/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
import aiohttp

# TinyLLM Version
VERSION = "v0.14.0"
VERSION = "v0.14.1"

# Set up logging
logging.basicConfig(level=logging.INFO,
Expand Down Expand Up @@ -116,7 +116,7 @@ def log(text):
default_prompts = {}
default_prompts["greeting"] = "Hi"
default_prompts["agentname"] = "Jarvis"
default_prompts["baseprompt"] = "You are {agentname}, a highly intelligent assistant. Keep your answers brief and accurate."
default_prompts["baseprompt"] = "You are {agentname}, a highly intelligent assistant. The current date is {date}.\n\nYou should give concise responses to very simple questions, but provide thorough responses to more complex and open-ended questions."
default_prompts["weather"] = "You are a weather forecaster. Keep your answers brief and accurate. Current date is {date} and weather conditions:\n[DATA]{context_str}[/DATA]\nProvide a weather update, current weather alerts, conditions, precipitation and forecast for {location} and answer this: {prompt}."
default_prompts["stock"] = "You are a stock analyst. Keep your answers brief and accurate. Current date is {date}."
default_prompts["news"] = "You are a newscaster who specializes in providing headline news. Use only the following context provided by Google News to summarize the top 10 headlines for today. Do not display the pub date or timestamp. Rank headlines by most important to least important. Always include the news organization. Do not add any commentary.\nAlways use this format:\n#. [News Item] - [News Source]\nHere are some examples: \n1. The World is Round - Science\n2. The Election is over and Children have won - US News\n3. Storms Hit the Southern Coast - ABC\nContext: {context_str}\nAnswer:"
Expand Down Expand Up @@ -286,17 +286,15 @@ def reset_prompts():
load_prompts()
log(f"Loaded {len(prompts)} prompts.")

# Set base prompt and initialize the context array for conversation dialogue
if agentname == "":
agentname = prompts["agentname"]
current_date = datetime.datetime.now()
formatted_date = current_date.strftime("%B %-d, %Y")
values = {"agentname": agentname, "date": formatted_date}
baseprompt = expand_prompt(prompts["baseprompt"], values)

# Function to return base conversation prompt
def base_prompt(content=None):
global baseprompt
global baseprompt, agentname, USE_SYSTEM, prompts
if agentname == "":
agentname = prompts["agentname"]
current_date = datetime.datetime.now()
formatted_date = current_date.strftime("%B %-d, %Y")
values = {"agentname": agentname, "date": formatted_date}
baseprompt = expand_prompt(prompts["baseprompt"], values)
if not content:
content = baseprompt
if USE_SYSTEM:
Expand Down Expand Up @@ -572,7 +570,7 @@ async def get_prompts():
# POST requests to update prompts
@app.post('/saveprompts')
async def update_prompts(data: dict):
global prompts, baseprompt, sio, TEMPERATURE, MAXTOKENS
global prompts, baseprompt, sio, TEMPERATURE, MAXTOKENS, agentname
if PROMPT_RO:
return ({"Result": "Prompts are read-only"})
oldbaseprompt = prompts["baseprompt"]
Expand Down

0 comments on commit 73106ea

Please sign in to comment.