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

Function testNanoGPT

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

Source from the content-addressed store, hash-verified

259}
260
261func testNanoGPT(ctx context.Context, model, message string, tools []uctypes.ToolDefinition) {
262 apiKey := os.Getenv("NANOGPT_KEY")
263 if apiKey == "" {
264 fmt.Println("Error: NANOGPT_KEY environment variable not set")
265 os.Exit(1)
266 }
267
268 opts := &uctypes.AIOptsType{
269 APIType: uctypes.APIType_OpenAIChat,
270 APIToken: apiKey,
271 Endpoint: "https://nano-gpt.com/api/v1/chat/completions",
272 Model: model,
273 MaxTokens: 4096,
274 }
275
276 chatID := uuid.New().String()
277
278 aiMessage := &uctypes.AIMessage{
279 MessageId: uuid.New().String(),
280 Parts: []uctypes.AIMessagePart{
281 {
282 Type: uctypes.AIMessagePartTypeText,
283 Text: message,
284 },
285 },
286 }
287
288 fmt.Printf("Testing NanoGPT with WaveAIPostMessageWrap, model: %s\n", model)
289 fmt.Printf("Message: %s\n", message)
290 fmt.Printf("Chat ID: %s\n", chatID)
291 fmt.Println("---")
292
293 testWriter := &TestResponseWriter{}
294 sseHandler := sse.MakeSSEHandlerCh(testWriter, ctx)
295 defer sseHandler.Close()
296
297 chatOpts := uctypes.WaveChatOpts{
298 ChatId: chatID,
299 ClientId: uuid.New().String(),
300 Config: *opts,
301 Tools: tools,
302 SystemPrompt: []string{"You are a helpful assistant. Be concise and clear in your responses."},
303 }
304 err := aiusechat.WaveAIPostMessageWrap(ctx, sseHandler, aiMessage, chatOpts)
305 if err != nil {
306 fmt.Printf("NanoGPT streaming error: %v\n", err)
307 }
308}
309
310func testAnthropic(ctx context.Context, model, message string, tools []uctypes.ToolDefinition) {
311 apiKey := os.Getenv("ANTHROPIC_APIKEY")

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