collavre_completion_api 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/collavre_completion_api/api/v1/base_controller.rb +30 -0
- data/app/controllers/collavre_completion_api/api/v1/chat/completions_controller.rb +2 -15
- data/app/controllers/collavre_completion_api/api/v1/models_controller.rb +1 -1
- data/lib/collavre_completion_api/version.rb +1 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0766b36abd1a87f89283ed02a814e37d11c74cbda7fc4d4d8d3e22725bcd571
|
|
4
|
+
data.tar.gz: 3e020fecc799cd736ca0ed1b53d65347ddc6fab30992f942c751d492c1669c42
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98a13c15455b1881b8b758868768a9e9aa1a7331f659c6e9b469dfcf68a89bc0d9f8c455e0518a988ea2cbeee625637f44b16df28b73de9ce1a60288f74fdf33
|
|
7
|
+
data.tar.gz: dcade7f6d2f1d3d0c2c258228c0a0c1ff358cccf628d6342bbd8155af8380b53afb7216fbb2e0759a28ed09637d875641a919dfa867f5d6ba509c55421a91b66
|
|
@@ -47,6 +47,36 @@ module CollavreCompletionApi
|
|
|
47
47
|
Collavre::Current.user
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
# Model ID format: email username (before @)
|
|
51
|
+
# e.g., "devbot" for devbot@collavre.local
|
|
52
|
+
# Falls back to "collavre/{id}" if email is blank
|
|
53
|
+
def agent_model_id(agent)
|
|
54
|
+
if agent.email.present?
|
|
55
|
+
agent.email.split("@").first
|
|
56
|
+
else
|
|
57
|
+
"collavre/#{agent.id}"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Resolve agent from model parameter (email username or legacy collavre/id format)
|
|
62
|
+
def resolve_agent_by_model(model_param)
|
|
63
|
+
return nil if model_param.blank?
|
|
64
|
+
|
|
65
|
+
agent = if model_param.start_with?("collavre/")
|
|
66
|
+
# Legacy format: collavre/{id}
|
|
67
|
+
Collavre::User.find_by(id: model_param.sub("collavre/", ""))
|
|
68
|
+
else
|
|
69
|
+
# Email username format — sanitize to prevent LIKE wildcard injection
|
|
70
|
+
sanitized = ActiveRecord::Base.sanitize_sql_like(model_param)
|
|
71
|
+
Collavre::User.where("email LIKE ?", "#{sanitized}@%").first
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
return nil unless agent&.ai_user?
|
|
75
|
+
return nil unless agent.created_by_id == current_user.id || agent.searchable?
|
|
76
|
+
|
|
77
|
+
agent
|
|
78
|
+
end
|
|
79
|
+
|
|
50
80
|
def collavre_creative
|
|
51
81
|
@collavre_creative ||= begin
|
|
52
82
|
creative_id = request.headers["X-Collavre-Creative"]
|
|
@@ -39,7 +39,7 @@ module CollavreCompletionApi
|
|
|
39
39
|
context: { creative: collavre_creative, user: current_user }
|
|
40
40
|
)
|
|
41
41
|
|
|
42
|
-
model_name = params[:model] ||
|
|
42
|
+
model_name = params[:model] || agent_model_id(agent)
|
|
43
43
|
|
|
44
44
|
if stream
|
|
45
45
|
stream_response(client, contents, model_name)
|
|
@@ -51,20 +51,7 @@ module CollavreCompletionApi
|
|
|
51
51
|
private
|
|
52
52
|
|
|
53
53
|
def resolve_agent
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return nil unless model_param.start_with?("collavre/")
|
|
57
|
-
|
|
58
|
-
ai_id = model_param.sub("collavre/", "")
|
|
59
|
-
agent = Collavre::User.find_by(id: ai_id)
|
|
60
|
-
return nil unless agent&.ai_user?
|
|
61
|
-
return nil unless agent_accessible?(agent)
|
|
62
|
-
|
|
63
|
-
agent
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def agent_accessible?(agent)
|
|
67
|
-
agent.created_by_id == current_user.id || agent.searchable?
|
|
54
|
+
resolve_agent_by_model(params[:model].to_s)
|
|
68
55
|
end
|
|
69
56
|
|
|
70
57
|
def build_system_prompt(messages, agent)
|