Skip to content

Commit 0cb08b0

Browse files
committed
feat: implement AI plugin calling interface with dedicated endpoints
This commit implements the AI plugin calling logic that enables the main project to communicate with AI plugins using the existing unified plugin architecture. AI plugins are treated like other plugins but identified by categories: ["ai"]. Key implementations: - Added CallAI and GetAICapabilities RPC methods in server.proto - Implemented AI plugin calling logic in remote_server.go using existing Query interface - AI plugins use standard map[string]string parameters: method, model, prompt, config - Response follows DataResult.Pairs format: content, meta, success, error - HTTP endpoints: POST /api/v1/ai/generate, GET /api/v1/ai/capabilities/{plugin_name} AI plugin developers need to: 1. Configure categories: ["ai"] in extension.yaml 2. Implement Query method to handle "ai.generate" and "ai.capabilities" 3. Return standard DataResult format The implementation maintains full compatibility with existing plugin architecture while providing AI-specific communication standards.
1 parent ce1f79f commit 0cb08b0

File tree

11 files changed

+4295
-5935
lines changed

11 files changed

+4295
-5935
lines changed

pkg/runner/monitor/monitor.pb.go

Lines changed: 32 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/runner/monitor/monitor_grpc.pb.go

Lines changed: 26 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/server/ai_interface.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Copyright 2024 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package server
18+
19+
// AI Plugin Communication Interface Standards
20+
// AI plugins use the existing testing.Loader.Query(map[string]string) interface
21+
22+
// Standard AI plugin communication methods
23+
const (
24+
AIMethodGenerate = "ai.generate" // Generate content from prompt
25+
AIMethodCapabilities = "ai.capabilities" // Get plugin capabilities
26+
)
27+
28+
// AI Plugin Query Parameter Standards
29+
// AI plugins are called using loader.Query(query map[string]string) with these parameters:
30+
31+
// For ai.generate:
32+
// - "method": "ai.generate"
33+
// - "model": model identifier (e.g., "gpt-4", "claude")
34+
// - "prompt": the prompt or instruction
35+
// - "config": optional JSON configuration string (e.g., `{"temperature": 0.7, "max_tokens": 1000}`)
36+
37+
// For ai.capabilities:
38+
// - "method": "ai.capabilities"
39+
40+
// AI Plugin Response Standards
41+
// AI plugins return response through testing.DataResult.Pairs with these keys:
42+
43+
// For successful ai.generate:
44+
// - "content": the generated content
45+
// - "meta": optional JSON metadata string (model info, timing, etc.)
46+
// - "success": "true"
47+
48+
// For successful ai.capabilities:
49+
// - "capabilities": JSON string containing plugin capabilities
50+
// - "models": JSON array of supported models (fallback if capabilities not available)
51+
// - "features": JSON array of supported features (fallback)
52+
// - "description": plugin description (fallback)
53+
// - "version": plugin version (fallback)
54+
// - "success": "true"
55+
56+
// For errors:
57+
// - "error": error message
58+
// - "success": "false"
59+
60+
// Plugin Discovery
61+
// AI plugins are identified by having "ai" in their categories field:
62+
// categories: ["ai"]
63+
64+
// Usage Examples:
65+
//
66+
// Get AI plugins:
67+
// stores, err := server.GetStores(ctx, &SimpleQuery{Kind: "ai"})
68+
//
69+
// Call AI plugin:
70+
// loader, err := server.getLoaderByStoreName("my-ai-plugin")
71+
// result, err := loader.Query(map[string]string{
72+
// "method": "ai.generate",
73+
// "model": "gpt-4",
74+
// "prompt": "Hello world",
75+
// "config": `{"temperature": 0.7}`,
76+
// })
77+
// content := result.Pairs["content"]
78+
79+
// Documentation structures (for reference only, actual types are generated from proto)
80+
// See server.proto for the actual message definitions:
81+
//
82+
// AIRequest fields:
83+
// - plugin_name: AI plugin name
84+
// - model: Model identifier (e.g., "gpt-4", "claude")
85+
// - prompt: The prompt or instruction
86+
// - config: JSON configuration string (optional)
87+
//
88+
// AIResponse fields:
89+
// - content: Generated content
90+
// - meta: JSON metadata string (optional)
91+
// - success: Whether the call succeeded
92+
// - error: Error message if failed
93+
//
94+
// AICapabilitiesResponse fields:
95+
// - models: Supported models
96+
// - features: Supported features
97+
// - description: Plugin description
98+
// - version: Plugin version
99+
// - success: Whether the call succeeded
100+
// - error: Error message if failed

0 commit comments

Comments
 (0)