mirror of
https://github.com/FlipsideCrypto/livequery-models.git
synced 2026-02-06 10:56:46 +00:00
update slack alerts
This commit is contained in:
parent
a49f40c7c6
commit
e95fafb0c2
@ -35,7 +35,7 @@
|
||||
ai_analysis,
|
||||
total_failures,
|
||||
failure_metadata
|
||||
FROM TABLE(github_actions.tf_failure_analysis_with_ai('{{ owner }}', '{{ repo }}', '{{ run_id }}', '{{ ai_provider }}'))
|
||||
FROM TABLE(github_actions.tf_failure_analysis_with_ai('{{ owner }}', '{{ repo }}', '{{ run_id }}', '{{ ai_provider }}', '{{ var("model_name", "") }}'))
|
||||
{% endset %}
|
||||
|
||||
{%- set failure_results = run_query(failure_query) -%}
|
||||
@ -118,13 +118,13 @@
|
||||
}]
|
||||
} -%}
|
||||
|
||||
{# Add customization for success messages #}
|
||||
{%- if username and username != 'GitHub Actions Bot' and username != 'none' -%}
|
||||
{# Add customization for success messages at root level #}
|
||||
{%- if username and username != 'none' -%}
|
||||
{%- do message_payload.update({'username': username}) -%}
|
||||
{%- endif -%}
|
||||
{%- if icon_url and icon_url != 'none' and icon_url != '' -%}
|
||||
{%- do message_payload.update({'icon_url': icon_url}) -%}
|
||||
{%- elif icon_emoji and icon_emoji != ':github:' and icon_emoji != 'none' -%}
|
||||
{%- elif icon_emoji and icon_emoji != 'none' -%}
|
||||
{%- do message_payload.update({'icon_emoji': icon_emoji}) -%}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
@ -174,13 +174,13 @@
|
||||
}]
|
||||
} -%}
|
||||
|
||||
{# Add customization for failure messages #}
|
||||
{%- if username and username != 'GitHub Actions Bot' and username != 'none' -%}
|
||||
{# Add customization for failure messages at root level #}
|
||||
{%- if username and username != 'none' -%}
|
||||
{%- do message_payload.update({'username': username}) -%}
|
||||
{%- endif -%}
|
||||
{%- if icon_url and icon_url != 'none' and icon_url != '' -%}
|
||||
{%- do message_payload.update({'icon_url': icon_url}) -%}
|
||||
{%- elif icon_emoji and icon_emoji != ':github:' and icon_emoji != 'none' -%}
|
||||
{%- elif icon_emoji and icon_emoji != 'none' -%}
|
||||
{%- do message_payload.update({'icon_emoji': icon_emoji}) -%}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
@ -237,21 +237,63 @@
|
||||
}]
|
||||
} -%}
|
||||
|
||||
{# Add customization to thread messages #}
|
||||
{%- if username and username != 'none' -%}
|
||||
{%- do job_summary.update({'username': username}) -%}
|
||||
{%- endif -%}
|
||||
{%- if icon_url and icon_url != 'none' and icon_url != '' -%}
|
||||
{%- do job_summary.update({'icon_url': icon_url}) -%}
|
||||
{%- elif icon_emoji and icon_emoji != 'none' -%}
|
||||
{%- do job_summary.update({'icon_emoji': icon_emoji}) -%}
|
||||
{%- endif -%}
|
||||
|
||||
{% set job_thread_query %}
|
||||
SELECT slack.post_reply('{{ slack_channel }}', '{{ main_thread_ts }}', PARSE_JSON($${{ job_summary | tojson }}$$), '{{ bot_secret_name }}') as result
|
||||
{% endset %}
|
||||
|
||||
{%- set job_result = run_query(job_thread_query) -%}
|
||||
|
||||
{# Post logs as additional thread reply if available #}
|
||||
{# Post logs as additional thread replies if available - split long logs #}
|
||||
{%- if logs_preview and logs_preview != '' -%}
|
||||
{%- set log_message = {'text': '```\n' ~ logs_preview[:2900] ~ '\n```'} -%}
|
||||
{%- set max_chunk_size = 2900 -%}
|
||||
{%- set log_chunks = [] -%}
|
||||
|
||||
{# Split logs into chunks #}
|
||||
{%- for i in range(0, logs_preview|length, max_chunk_size) -%}
|
||||
{%- set chunk = logs_preview[i:i+max_chunk_size] -%}
|
||||
{%- do log_chunks.append(chunk) -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{# Send each chunk as a separate thread message #}
|
||||
{%- for chunk_idx in range(log_chunks|length) -%}
|
||||
{%- set chunk = log_chunks[chunk_idx] -%}
|
||||
{%- set chunk_header = '' -%}
|
||||
|
||||
{# Add chunk header if multiple chunks #}
|
||||
{%- if log_chunks|length > 1 -%}
|
||||
{%- set chunk_header = '📋 Logs (' ~ (chunk_idx + 1) ~ '/' ~ log_chunks|length ~ '):\n' -%}
|
||||
{%- else -%}
|
||||
{%- set chunk_header = '📋 Logs:\n' -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set log_message = {'text': chunk_header ~ '```\n' ~ chunk ~ '\n```'} -%}
|
||||
|
||||
{% set log_thread_query %}
|
||||
SELECT slack.post_reply('{{ slack_channel }}', '{{ main_thread_ts }}', PARSE_JSON($${{ log_message | tojson }}$$), '{{ bot_secret_name }}') as result
|
||||
{% endset %}
|
||||
{# Add customization to log thread messages #}
|
||||
{%- if username and username != 'none' -%}
|
||||
{%- do log_message.update({'username': username}) -%}
|
||||
{%- endif -%}
|
||||
{%- if icon_url and icon_url != 'none' and icon_url != '' -%}
|
||||
{%- do log_message.update({'icon_url': icon_url}) -%}
|
||||
{%- elif icon_emoji and icon_emoji != 'none' -%}
|
||||
{%- do log_message.update({'icon_emoji': icon_emoji}) -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set log_result = run_query(log_thread_query) -%}
|
||||
{% set log_thread_query %}
|
||||
SELECT slack.post_reply('{{ slack_channel }}', '{{ main_thread_ts }}', PARSE_JSON($${{ log_message | tojson }}$$), '{{ bot_secret_name }}') as result
|
||||
{% endset %}
|
||||
|
||||
{%- set log_result = run_query(log_thread_query) -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
|
||||
{{ log("Posted thread for job: " ~ job_name, true) }}
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
options: |
|
||||
COMMENT = $$Send a batch of messages to Claude and get responses [API docs: Messages Batch](https://docs.anthropic.com/en/api/creating-message-batches)$$
|
||||
sql: |
|
||||
SELECT claude_utils.post(
|
||||
SELECT claude_utils.post_api(
|
||||
'/v1/messages/batches',
|
||||
MESSAGES
|
||||
) as response
|
||||
@ -26,7 +26,7 @@
|
||||
options: |
|
||||
COMMENT = $$Retrieve details of a specific Message Batch [API docs: Retrieve Message Batch](https://docs.anthropic.com/en/api/retrieving-message-batches)$$
|
||||
sql: |
|
||||
SELECT claude_utils.get(
|
||||
SELECT claude_utils.get_api(
|
||||
CONCAT('/v1/messages/batches/', MESSAGE_BATCH_ID)
|
||||
) as response
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
options: |
|
||||
COMMENT = $$Retrieve results of a Message Batch [API docs: Retrieve Message Batch Results](https://docs.anthropic.com/en/api/retrieving-message-batches)$$
|
||||
sql: |
|
||||
SELECT claude_utils.get(
|
||||
SELECT claude_utils.get_api(
|
||||
CONCAT('/v1/messages/batches/', MESSAGE_BATCH_ID, '/results')
|
||||
) as response
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
options: |
|
||||
COMMENT = $$List all Message Batches [API docs: List Message Batches](https://docs.anthropic.com/en/api/retrieving-message-batches)$$
|
||||
sql: |
|
||||
SELECT claude_utils.get(
|
||||
SELECT claude_utils.get_api(
|
||||
'/v1/messages/batches'
|
||||
) as response
|
||||
|
||||
@ -62,7 +62,7 @@
|
||||
options: |
|
||||
COMMENT = $$List all Message Batches [API docs: List Message Batches](https://docs.anthropic.com/en/api/retrieving-message-batches)$$
|
||||
sql: |
|
||||
SELECT claude_utils.get(
|
||||
SELECT claude_utils.get_api(
|
||||
CONCAT('/v1/messages/batches',
|
||||
'?before_id=', COALESCE(BEFORE_ID, ''),
|
||||
'&limit=', COALESCE(LIMIT::STRING, '')
|
||||
@ -78,7 +78,7 @@
|
||||
options: |
|
||||
COMMENT = $$List all Message Batches [API docs: List Message Batches](https://docs.anthropic.com/en/api/retrieving-message-batches)$$
|
||||
sql: |
|
||||
SELECT claude_utils.get(
|
||||
SELECT claude_utils.get_api(
|
||||
CONCAT('/v1/messages/batches',
|
||||
'?after_id=', COALESCE(AFTER_ID, ''),
|
||||
'&limit=', COALESCE(LIMIT::STRING, '')
|
||||
@ -92,7 +92,7 @@
|
||||
options: |
|
||||
COMMENT = $$Cancel a Message Batch [API docs: Cancel Message Batch](https://docs.anthropic.com/en/api/retrieving-message-batches)$$
|
||||
sql: |
|
||||
SELECT claude_utils.post(
|
||||
SELECT claude_utils.post_api(
|
||||
CONCAT('/v1/messages/batches/', MESSAGE_BATCH_ID, '/cancel'),
|
||||
{}
|
||||
) as response
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
options: |
|
||||
COMMENT = $$Send a message to Claude and get a response [API docs: Messages](https://docs.anthropic.com/claude/reference/messages_post)$$
|
||||
sql: |
|
||||
SELECT claude_utils.post(
|
||||
SELECT claude_utils.post_api(
|
||||
'/v1/messages',
|
||||
{
|
||||
'model': 'claude-3-5-sonnet-20241022',
|
||||
@ -31,7 +31,7 @@
|
||||
options: |
|
||||
COMMENT = $$Send a message to Claude and get a response [API docs: Messages](https://docs.anthropic.com/claude/reference/messages_post)$$
|
||||
sql: |
|
||||
SELECT claude_utils.post(
|
||||
SELECT claude_utils.post_api(
|
||||
'/v1/messages',
|
||||
{
|
||||
'model': COALESCE(MODEL, 'claude-3-5-sonnet-20241022'),
|
||||
@ -54,7 +54,7 @@
|
||||
options: |
|
||||
COMMENT = $$Send a message to Claude and get a response [API docs: Messages](https://docs.anthropic.com/claude/reference/messages_post)$$
|
||||
sql: |
|
||||
SELECT claude_utils.post(
|
||||
SELECT claude_utils.post_api(
|
||||
'/v1/messages',
|
||||
{
|
||||
'model': MODEL,
|
||||
@ -76,7 +76,7 @@
|
||||
options: |
|
||||
COMMENT = $$Count tokens in a message array before sending to Claude [API docs: Count Tokens](https://docs.anthropic.com/claude/reference/counting-tokens)$$
|
||||
sql: |
|
||||
SELECT claude_utils.post(
|
||||
SELECT claude_utils.post_api(
|
||||
'/v1/messages/count_tokens',
|
||||
{
|
||||
'model': COALESCE(MODEL, 'claude-3-5-sonnet-20241022'),
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
options: |
|
||||
COMMENT = $$List available Claude models [API docs: List Models](https://docs.anthropic.com/claude/reference/models_get)$$
|
||||
sql: |
|
||||
SELECT claude_utils.get(
|
||||
SELECT claude_utils.get_api(
|
||||
'/v1/models'
|
||||
) as response
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
options: |
|
||||
COMMENT = $$Get details for a specific Claude model [API docs: Get Model](https://docs.anthropic.com/claude/reference/models_retrieve)$$
|
||||
sql: |
|
||||
SELECT claude_utils.get(
|
||||
SELECT claude_utils.get_api(
|
||||
CONCAT('/v1/models/', MODEL)
|
||||
) as response
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
{#
|
||||
This macro is used to generate API calls to Claude API endpoints
|
||||
#}
|
||||
- name: {{ schema_name -}}.post
|
||||
- name: {{ schema_name -}}.post_api
|
||||
signature:
|
||||
- [PATH, STRING, The API endpoint path]
|
||||
- [BODY, OBJECT, The request body]
|
||||
@ -11,7 +11,7 @@
|
||||
options: |
|
||||
COMMENT = $$Make calls to Claude API [API docs: Claude](https://docs.anthropic.com/claude/reference/getting-started-with-the-api)$$
|
||||
sql: |
|
||||
SELECT live.udf_api(
|
||||
SELECT live.udf_api_v2(
|
||||
'POST',
|
||||
CONCAT('https://api.anthropic.com', PATH),
|
||||
{
|
||||
@ -20,10 +20,14 @@
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
BODY,
|
||||
'_FSC_SYS/CLAUDE'
|
||||
IFF(_utils.udf_whoami() <> CURRENT_USER(),
|
||||
'_FSC_SYS/CLAUDE',
|
||||
'Vault/prod/livequery/claude'
|
||||
),
|
||||
TRUE
|
||||
) as response
|
||||
|
||||
- name: {{ schema_name -}}.get
|
||||
- name: {{ schema_name -}}.get_api
|
||||
signature:
|
||||
- [PATH, STRING, The API endpoint path]
|
||||
return_type:
|
||||
@ -31,7 +35,7 @@
|
||||
options: |
|
||||
COMMENT = $$Make GET requests to Claude API [API docs: Get](https://docs.anthropic.com/claude/reference/get)$$
|
||||
sql: |
|
||||
SELECT live.udf_api(
|
||||
SELECT live.udf_api_v2(
|
||||
'GET',
|
||||
CONCAT('https://api.anthropic.com', PATH),
|
||||
{
|
||||
@ -40,7 +44,11 @@
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
NULL,
|
||||
'_FSC_SYS/CLAUDE'
|
||||
IFF(_utils.udf_whoami() <> CURRENT_USER(),
|
||||
'_FSC_SYS/CLAUDE',
|
||||
'Vault/prod/livequery/claude'
|
||||
),
|
||||
TRUE
|
||||
) as response
|
||||
|
||||
- name: {{ schema_name -}}.delete_method
|
||||
@ -51,7 +59,7 @@
|
||||
options: |
|
||||
COMMENT = $$Make DELETE requests to Claude API [API docs: Delete](https://docs.anthropic.com/claude/reference/delete)$$
|
||||
sql: |
|
||||
SELECT live.udf_api(
|
||||
SELECT live.udf_api_v2(
|
||||
'DELETE',
|
||||
CONCAT('https://api.anthropic.com', PATH),
|
||||
{
|
||||
@ -60,6 +68,10 @@
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
NULL,
|
||||
'_FSC_SYS/CLAUDE'
|
||||
IFF(_utils.udf_whoami() <> CURRENT_USER(),
|
||||
'_FSC_SYS/CLAUDE',
|
||||
'Vault/prod/livequery/claude'
|
||||
),
|
||||
TRUE
|
||||
) as response
|
||||
{% endmacro %}
|
||||
|
||||
@ -294,7 +294,7 @@
|
||||
- [repo, "TEXT"]
|
||||
- [run_id, "TEXT"]
|
||||
- [ai_provider, "TEXT"]
|
||||
- [groq_model, "STRING"]
|
||||
- [model_name, "STRING"]
|
||||
return_type:
|
||||
- "TABLE(run_id STRING, ai_analysis STRING, total_failures NUMBER, failure_metadata ARRAY)"
|
||||
options: |
|
||||
@ -345,12 +345,13 @@
|
||||
WHEN LOWER(ai_provider) = 'claude' THEN
|
||||
(
|
||||
SELECT COALESCE(
|
||||
response:content[0]:text::STRING,
|
||||
response:error:message::STRING,
|
||||
response:data:content[0]:text::STRING,
|
||||
response:data:error:message::STRING,
|
||||
'Claude analysis failed'
|
||||
)
|
||||
FROM (
|
||||
SELECT claude.post_messages(
|
||||
COALESCE(NULLIF(model_name, ''), 'claude-3-5-sonnet-20241022'),
|
||||
ARRAY_CONSTRUCT(
|
||||
OBJECT_CONSTRUCT(
|
||||
'role', 'user',
|
||||
@ -361,10 +362,11 @@
|
||||
'1. Common failure patterns\n',
|
||||
'2. Root cause analysis\n',
|
||||
'3. Prioritized action items\n\n',
|
||||
SUBSTR(job_details, 1, 2000)
|
||||
job_details
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
4096
|
||||
) as response
|
||||
)
|
||||
)
|
||||
@ -379,9 +381,9 @@
|
||||
'1. Common failure patterns\n',
|
||||
'2. Root cause analysis\n',
|
||||
'3. Prioritized action items\n\n',
|
||||
SUBSTR(job_details, 1, 2000)
|
||||
job_details
|
||||
),
|
||||
COALESCE(NULLIF(groq_model, ''), 'llama3-8b-8192')
|
||||
COALESCE(NULLIF(model_name, ''), 'llama3-8b-8192')
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
-- depends_on: {{ ref('live') }}
|
||||
-- depends_on: {{ ref('claude_utils__claude_utils') }}
|
||||
{%- set configs = [
|
||||
config_claude_messages_udfs,
|
||||
config_claude_models_udfs,
|
||||
|
||||
@ -2,10 +2,10 @@ version: 2
|
||||
models:
|
||||
- name: claude_utils__claude_utils
|
||||
columns:
|
||||
- name: post
|
||||
- name: post_api
|
||||
tests:
|
||||
- test_udf:
|
||||
name: test_claude_utils__post_status_200
|
||||
name: test_claude_utils__post_api_status_200
|
||||
args: >
|
||||
'/v1/messages'
|
||||
, {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user