Skip to content

Commit 80019d3

Browse files
committed
chore: expose LLMs and embedder through hooks
1 parent d07c789 commit 80019d3

1 file changed

Lines changed: 53 additions & 23 deletions

File tree

models.py

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
1+
from typing import List
12
from cat.mad_hatter.decorators import tool, hook, plugin
2-
from pydantic import BaseModel
3-
from datetime import datetime, date
43

5-
class MySettings(BaseModel):
6-
required_int: int
7-
optional_int: int = 69
8-
required_str: str
9-
optional_str: str = "meow"
10-
required_date: date
11-
optional_date: date = 1679616000
4+
from .llm.anthropic import LLMAnthropicChatConfig
5+
from .llm.cohere import LLMCohereConfig
6+
from .llm.gemini import LLMGeminiChatConfig
7+
from .llm.hugging_face import LLMHuggingFaceEndpointConfig, LLMHuggingFaceTextGenInferenceConfig
8+
from .llm.openai import (
9+
LLMOpenAIChatConfig,
10+
LLMOpenAIConfig,
11+
LLMOpenAICompatibleConfig,
12+
LLMAzureOpenAIConfig,
13+
LLMAzureChatOpenAIConfig,
14+
)
15+
from .llm.ollama import LLMOllamaConfig
16+
17+
from .embedder.embedder import (
18+
EmbedderOpenAICompatibleConfig,
19+
EmbedderOpenAIConfig,
20+
EmbedderAzureOpenAIConfig,
21+
EmbedderCohereConfig,
22+
EmbedderQdrantFastEmbedConfig,
23+
EmbedderGeminiChatConfig,
24+
)
25+
26+
# TODO: Add settings to allow model management
27+
28+
llms = [
29+
LLMAnthropicChatConfig,
30+
LLMCohereConfig,
31+
LLMGeminiChatConfig,
32+
LLMHuggingFaceEndpointConfig,
33+
LLMHuggingFaceTextGenInferenceConfig,
34+
LLMOpenAIChatConfig,
35+
LLMOpenAIConfig,
36+
LLMOpenAICompatibleConfig,
37+
LLMAzureOpenAIConfig,
38+
LLMAzureChatOpenAIConfig,
39+
LLMOllamaConfig,
40+
]
1241

13-
@plugin
14-
def settings_model():
15-
return MySettings
42+
@hook
43+
def factory_allowed_llms(allowed, cat) -> List:
44+
allowed = allowed + llms
45+
return allowed
1646

17-
@tool
18-
def get_the_day(tool_input, cat):
19-
"""Get the day of the week. Input is always None."""
2047

21-
dt = datetime.now()
48+
embedders = [
49+
EmbedderOpenAICompatibleConfig,
50+
EmbedderOpenAIConfig,
51+
EmbedderAzureOpenAIConfig,
52+
EmbedderCohereConfig,
53+
EmbedderQdrantFastEmbedConfig,
54+
EmbedderGeminiChatConfig,
55+
]
2256

23-
return dt.strftime('%A')
2457

2558
@hook
26-
def before_cat_sends_message(message, cat):
27-
28-
prompt = f'Rephrase the following sentence in a grumpy way: {message["content"]}'
29-
message["content"] = cat.llm(prompt)
30-
31-
return message
59+
def factory_allowed_embedders(allowed, cat) -> List:
60+
allowed = allowed + embedders
61+
return allowed

0 commit comments

Comments
 (0)