Mercurial Hosting > lang
comparison src/lib/ai/claude/Ai_chat.luan @ 54:16e5c14eb800
AI tools
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 17 Aug 2025 17:47:02 +0900 |
parents | 27758f3b2d69 |
children | f5e72f2d1025 |
comparison
equal
deleted
inserted
replaced
53:6c78fd83518f | 54:16e5c14eb800 |
---|---|
71 end | 71 end |
72 end | 72 end |
73 end_for | 73 end_for |
74 end | 74 end |
75 | 75 |
76 local function get_chat(chat_id) | |
77 local Chat = require "site:/lib/Chat.luan" | |
78 local User = require "site:/lib/User.luan" | |
79 local chat = Chat.get_by_id(chat_id) or error() | |
80 local user = User.current() | |
81 local is_owner = user ~= nil and user.id == chat.user_id | |
82 is_owner or not chat.is_private or error "private" | |
83 return chat | |
84 end | |
85 | |
76 local functions = { | 86 local functions = { |
77 get_thread = { | 87 get_chat = { |
78 tool = { | 88 tool = { |
79 description = "Get the contents of a thread/chat with Claude on this website. The contents will be JSON in the format of the Claude API." | 89 description = "Get the contents of a chat/thread with Claude on this website. The contents will be JSON in the format of the Claude API." |
80 input_schema = { | 90 input_schema = { |
81 type = "object" | 91 type = "object" |
82 properties = { | 92 properties = { |
83 thread_id = { | 93 chat_id = { |
84 description = "The ID of the thread" | 94 description = "The ID of the chat" |
85 type = "string" | 95 type = "integer" |
86 } | 96 } |
87 } | 97 } |
88 } | 98 } |
89 } | 99 } |
90 fn = function(input) | 100 fn = function(input) |
91 local Chat = require "site:/lib/Chat.luan" | 101 local chat_id = input.chat_id or error() |
92 local User = require "site:/lib/User.luan" | 102 local chat = get_chat(chat_id) |
93 local thread_id = input.thread_id or error() | |
94 local chat = Chat.get_by_id(thread_id) or error() | |
95 local user = User.current() | |
96 local is_owner = user ~= nil and user.id == chat.user_id | |
97 is_owner or not chat.is_private or error "private" | |
98 return chat.ai_thread or error() | 103 return chat.ai_thread or error() |
104 end | |
105 } | |
106 get_tts_instructions = { | |
107 tool = { | |
108 description = "Get the text-to-speech instructions of a chat/thread on this website. These instruction are passed to OpenAI. If there are no instructions, the empty string is returned." | |
109 input_schema = { | |
110 type = "object" | |
111 properties = { | |
112 chat_id = { | |
113 description = "The ID of the chat" | |
114 type = "integer" | |
115 } | |
116 } | |
117 } | |
118 } | |
119 fn = function(input) | |
120 local chat_id = input.chat_id or error() | |
121 local chat = get_chat(chat_id) | |
122 return chat.tts_instructions or error() | |
99 end | 123 end |
100 } | 124 } |
101 } | 125 } |
102 local tools = {nil} | 126 local tools = {nil} |
103 for name, f in pairs(functions) do | 127 for name, f in pairs(functions) do |