Skip to content

Commit

Permalink
✨ Feat(assistant): add (new) default templates (#200)
Browse files Browse the repository at this point in the history
* ✨ Feat(assistant): add (new) default templates

* ✨ Feat(assistant): allow inline files in default example template

* ✨ Feat(assistant): increase max tokens for default templates to 120k
  • Loading branch information
MasterKenth authored Dec 6, 2024
1 parent b969502 commit 967aef7
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 151 deletions.
37 changes: 37 additions & 0 deletions data/assistant-templates/_qaf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"id": "_qaf",
"meta": {
"name": "QAF",
"description": "QAF template - do not use directly",
"sample_questions": []
},
"max_tokens": -1,
"allow_inline_files": false,
"files_collection_id": "",
"streams": [
{
"pipeline": "rag_scoring"
},
{
"provider": "openai",
"settings": {
"model": "gpt-4o",
"temperature": 0
},
"messages": [
{
"role": "system",
"content": "You are a helpful AI assistant that helps people with answering questions.<br> If you can\"t find the answer in the search result below, just say (in Swedish) \"Tyvärr kan jag inte svara på det.\" Don't try to make up an answer.<br> If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context.<br> The questions are going to be asked in Swedish. Your response must always be in Swedish."
},
{
"role": "user",
"content": "{query}"
},
{
"role": "user",
"content": "Here are the results of the search:\n\n {rag_output}"
}
]
}
]
}
51 changes: 51 additions & 0 deletions data/assistant-templates/_rag_scoring.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"id": "_rag_scoring",
"meta": {
"name": "RAG scoring",
"description": "",
"sample_questions": []
},
"max_tokens": -1,
"allow_inline_files": false,
"files_collection_id": "",
"streams": [
{
"provider": "openai",
"settings": {
"model": "gpt-4o",
"temperature": 0,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "score_schema",
"schema": {
"type": "object",
"properties": {
"score": {
"type": "number"
}
}
}
}
}
},
"messages": [
{
"timestamp": "",
"role": "system",
"content": "You are a scoring systems that classifies documents from 0-100 based on how well they answer a query.",
"should_format": false
},
{
"insert": "history"
},
{
"timestamp": "",
"role": "user",
"content": "{query}",
"should_format": false
}
]
}
]
}
43 changes: 0 additions & 43 deletions data/assistant-templates/example-multi.json

This file was deleted.

19 changes: 13 additions & 6 deletions data/assistant-templates/example-rag.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"id": "rag_example",
"id": "example-rag",
"meta": {
"name": "RAG (document) Example",
"description": "This is an example assistant that showcases how to setup an assistant for answering questions about uploaded documents. \n\nMake sure to upload documents first.",
"name": "Example Assistant with RAG",
"description": "This is an *example assistant* for demonstration purposes. It is instructed to answer in Swedish 🇸🇪. It has RAG support enabled and will answer questions specifically about the document(s) in it's file collection.\n\n**NOTE: before first use document(s) must be uploaded and the resulting file collection must be selected in the assistant editor.**",
"sample_questions": []
},
"files_collection_id": "<set by uploading files in editor ui>",
"max_tokens": 120000,
"streams": [
{
"pipeline": "rag_scoring"
Expand All @@ -19,11 +19,18 @@
"messages": [
{
"role": "system",
"content": "Explain what this is and repeat back an excerpt of it."
"content": "You are a helpful AI assistant that helps people with answering questions.<br> If you can\"t find the answer in the search result below, just say (in Swedish) \"Tyvärr kan jag inte svara på det.\" Don't try to make up an answer.<br> If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context.<br> The questions are going to be asked in Swedish. Your response must always be in Swedish."
},
{
"insert": "history"
},
{
"role": "user",
"content": "{query}"
},
{
"role": "user",
"content": "{rag_output}"
"content": "Here are the results of the search:\n\n {rag_output}"
}
]
}
Expand Down
12 changes: 7 additions & 5 deletions data/assistant-templates/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"id": "example",
"meta": {
"name": "Example Assistant",
"description": "This is an *example assistant* for testing purposes. It has been instructed to answer Swedish questions about Helsingborg.",
"description": "This is an *example assistant* for demonstration purposes. It is instructed to answer in Swedish 🇸🇪.",
"sample_questions": [
"Hur kan jag kolla upp tidstabellen för bussar?",
"Vilka evenemang händer i sommar?",
"Var kan jag parkera?"
"Hur kan AI hjälpa mig i vardagen?",
"Vilken är Sveriges största stad?",
"Ge mig ett recept på äppelkaka."
]
},
"max_tokens": 120000,
"allow_inline_files": true,
"streams": [
{
"provider": "openai",
Expand All @@ -19,7 +21,7 @@
"messages": [
{
"role": "system",
"content": "You are a helpful AI assistant that helps people with answering questions related to municipality and Helsingborg City. The questions are going to be asked in Swedish. Your response must always be in Swedish."
"content": "You are a helpful AI assistant that helps people with answering questions. The questions are going to be asked in Swedish. Your response must always be in Swedish."
},
{
"insert": "history"
Expand Down
30 changes: 0 additions & 30 deletions data/assistant-templates/gpt-sw3-20b.json

This file was deleted.

30 changes: 0 additions & 30 deletions data/assistant-templates/llama-3.1-8b.json

This file was deleted.

35 changes: 0 additions & 35 deletions data/assistant-templates/planning-permission.json

This file was deleted.

16 changes: 14 additions & 2 deletions fai-rag-app/fai-backend/fai_backend/setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json
import os

import nltk
from beanie import init_beanie
from fastapi import FastAPI
from fastapi.routing import APIRoute
from motor.motor_asyncio import AsyncIOMotorClient

from fai_backend.assistant.models import AssistantChatHistoryModel, StoredQuestionModel
from fai_backend.assistant.models import AssistantChatHistoryModel, StoredQuestionModel, AssistantTemplate
from fai_backend.collection.models import CollectionMetadataModel
from fai_backend.config import settings
from fai_backend.projects.schema import ProjectMember, ProjectRole
Expand Down Expand Up @@ -50,11 +53,20 @@ def create_permissions(value: bool):
)
}

assistant_templates_dir = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../../../data/assistant-templates'))
initial_assistants = \
[
AssistantTemplate(**json.loads(open(os.path.join(assistant_templates_dir, f)).read()))
for f in os.listdir(assistant_templates_dir)
if f.endswith('.json')
] if os.path.exists(assistant_templates_dir) else []

initial_project = await projects_repo.create(
ProjectModel(
name='Project',
creator=settings.APP_ADMIN_EMAIL,
assistants=[],
assistants=initial_assistants,
members=[
ProjectMember(
email=settings.APP_ADMIN_EMAIL,
Expand Down

0 comments on commit 967aef7

Please sign in to comment.