技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
weaviate-graphql【数据与研究】Implements the GraphQL capabilities of the Weaviate API, enabling flexible querying options for managing AI datasets efficiently.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: weaviate-graphql description: Implements the GraphQL capabilities of the Weaviate API, enabling flexible querying options for managing AI datasets efficiently. license: MIT compatibility: opencode metadata: version: "1.0.0" domain: ai triggers: - weaviate - GraphQL - AI - query language - database management role: implementation scope: implementation output-format: code related-skills: weaviate-collections-api, weaviate-vector-search archetypes: - tactical anti_triggers: - generic routing response_profile: verbosity: low directive_strength: medium abstraction_level: tactical
This skill utilizes the GraphQL interface of the Weaviate API for dynamic querying of datasets related to AI applications. It covers advanced querying techniques, error handling, and response validation procedures to enhance user interactions.
import weaviate
client = weaviate.Client("http://localhost:8080")
# Define a GraphQL query
query = "{\n Get {\n Article {\n title\n content\n }\n }\n}"
# Send the query to Weaviate API
response = client.query.raw(query)
# Handle response
print(response)
Always validate GraphQL responses and handle API errors gracefully:
import weaviate
from weaviate.exceptions import UnexpectedStatusCodeException
def safe_execute_query(client, query_str):
"""Execute a GraphQL query with error handling."""
try:
response = client.query.raw(query_str)
return response
except UnexpectedStatusCodeException as e:
print(f"GraphQL query failed with status {e.status_code}: {e.message}")
raise
except Exception as e:
print(f"Unexpected error during GraphQL execution: {e}")
raise
def search_articles_by_author(client, author_name, limit=10):
"""Search articles filtered by author name using GraphQL."""
query = f"""{{
Get {{
Article(
where: {{{{
path: ["author"]
operator: Like
valueText: "{author_name}"
}}}}
) {{
title
content
author
}}
limit: {limit}
}}
}}"""
return safe_execute_query(client, query)
Parse GraphQL responses efficiently for downstream use:
def parse_search_results(response):
"""Extract and validate search results from a GraphQL response."""
if not response or "data" not in response:
raise ValueError("Invalid response format")
articles = response["data"].get("Article", [])
parsed = []
for article in articles:
entry = {
"title": article.get("title", ""),
"content": article.get("content", ""),
"author": article.get("author", ""),
}
if not entry["title"]:
continue # Skip entries without a title
parsed.append(entry)
return parsed