Initial pass at backend changes to support agents

- Add a db model for Agents, attaching them to conversations
- When an agent is added to a conversation, override the system prompt to tweak the instructions
- Agents can be configured with prompt modification, model specification, a profile picture, and other things
- Admin-configured models will not be editable by individual users
- Add unit tests to verify agent behavior. Unit tests demonstrate imperfect adherence to prompt specifications
This commit is contained in:
sabaimran
2024-03-11 12:45:24 +05:30
parent 1da453306e
commit 9b88976f36
14 changed files with 428 additions and 58 deletions

View File

@@ -12,6 +12,7 @@ from khoj.configure import (
configure_search_types,
)
from khoj.database.models import (
Agent,
GithubConfig,
GithubRepoConfig,
KhojApiUser,
@@ -181,6 +182,28 @@ def api_user4(default_user4):
)
@pytest.mark.django_db
@pytest.fixture
def offline_agent():
chat_model = ChatModelOptionsFactory()
return Agent.objects.create(
name="Accountant",
chat_model=chat_model,
tuning="You are a certified CPA. You are able to tell me how much I've spent based on my notes. Regardless of what I ask, you should always respond with the total amount I've spent. ALWAYS RESPOND WITH A SUMMARY TOTAL OF HOW MUCH MONEY I HAVE SPENT.",
)
@pytest.mark.django_db
@pytest.fixture
def openai_agent():
chat_model = ChatModelOptionsFactory(chat_model="gpt-3.5-turbo", model_type="openai")
return Agent.objects.create(
name="Accountant",
chat_model=chat_model,
tuning="You are a certified CPA. You are able to tell me how much I've spent based on my notes. Regardless of what I ask, you should always respond with the total amount I've spent.",
)
@pytest.fixture(scope="session")
def search_models(search_config: SearchConfig):
search_models = SearchModels()