MCPcopy
hub / github.com/wavetermdev/waveterm / testOpenRouter

Function testOpenRouter

cmd/testai/main-testai.go:211–259  ·  view source on GitHub ↗
(ctx context.Context, model, message string, tools []uctypes.ToolDefinition)

Source from the content-addressed store, hash-verified

209}
210
211func testOpenRouter(ctx context.Context, model, message string, tools []uctypes.ToolDefinition) {
212 apiKey := os.Getenv("OPENROUTER_APIKEY")
213 if apiKey == "" {
214 fmt.Println("Error: OPENROUTER_APIKEY environment variable not set")
215 os.Exit(1)
216 }
217
218 opts := &uctypes.AIOptsType{
219 APIType: uctypes.APIType_OpenAIChat,
220 APIToken: apiKey,
221 Endpoint: "https://openrouter.ai/api/v1/chat/completions",
222 Model: model,
223 MaxTokens: 4096,
224 ThinkingLevel: uctypes.ThinkingLevelMedium,
225 }
226
227 chatID := uuid.New().String()
228
229 aiMessage := &uctypes.AIMessage{
230 MessageId: uuid.New().String(),
231 Parts: []uctypes.AIMessagePart{
232 {
233 Type: uctypes.AIMessagePartTypeText,
234 Text: message,
235 },
236 },
237 }
238
239 fmt.Printf("Testing OpenRouter with WaveAIPostMessageWrap, model: %s\n", model)
240 fmt.Printf("Message: %s\n", message)
241 fmt.Printf("Chat ID: %s\n", chatID)
242 fmt.Println("---")
243
244 testWriter := &TestResponseWriter{}
245 sseHandler := sse.MakeSSEHandlerCh(testWriter, ctx)
246 defer sseHandler.Close()
247
248 chatOpts := uctypes.WaveChatOpts{
249 ChatId: chatID,
250 ClientId: uuid.New().String(),
251 Config: *opts,
252 Tools: tools,
253 SystemPrompt: []string{"You are a helpful assistant. Be concise and clear in your responses."},
254 }
255 err := aiusechat.WaveAIPostMessageWrap(ctx, sseHandler, aiMessage, chatOpts)
256 if err != nil {
257 fmt.Printf("OpenRouter streaming error: %v\n", err)
258 }
259}
260
261func testNanoGPT(ctx context.Context, model, message string, tools []uctypes.ToolDefinition) {
262 apiKey := os.Getenv("NANOGPT_KEY")

Callers 1

mainFunction · 0.85

Calls 4

MakeSSEHandlerChFunction · 0.92
WaveAIPostMessageWrapFunction · 0.92
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected