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

Function testOpenAI

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

Source from the content-addressed store, hash-verified

109}
110
111func testOpenAI(ctx context.Context, model, message string, tools []uctypes.ToolDefinition) {
112 apiKey := os.Getenv("OPENAI_APIKEY")
113 if apiKey == "" {
114 fmt.Println("Error: OPENAI_APIKEY environment variable not set")
115 os.Exit(1)
116 }
117
118 opts := &uctypes.AIOptsType{
119 APIType: uctypes.APIType_OpenAIResponses,
120 APIToken: apiKey,
121 Model: model,
122 MaxTokens: 4096,
123 ThinkingLevel: uctypes.ThinkingLevelMedium,
124 }
125
126 // Generate a chat ID
127 chatID := uuid.New().String()
128
129 // Convert to AIMessage format for WaveAIPostMessageWrap
130 aiMessage := &uctypes.AIMessage{
131 MessageId: uuid.New().String(),
132 Parts: []uctypes.AIMessagePart{
133 {
134 Type: uctypes.AIMessagePartTypeText,
135 Text: message,
136 },
137 },
138 }
139
140 fmt.Printf("Testing OpenAI streaming with WaveAIPostMessageWrap, model: %s\n", model)
141 fmt.Printf("Message: %s\n", message)
142 fmt.Printf("Chat ID: %s\n", chatID)
143 fmt.Println("---")
144
145 testWriter := &TestResponseWriter{}
146 sseHandler := sse.MakeSSEHandlerCh(testWriter, ctx)
147 defer sseHandler.Close()
148
149 chatOpts := uctypes.WaveChatOpts{
150 ChatId: chatID,
151 ClientId: uuid.New().String(),
152 Config: *opts,
153 Tools: tools,
154 }
155 err := aiusechat.WaveAIPostMessageWrap(ctx, sseHandler, aiMessage, chatOpts)
156 if err != nil {
157 fmt.Printf("OpenAI streaming error: %v\n", err)
158 }
159}
160
161func testOpenAIComp(ctx context.Context, model, message string, tools []uctypes.ToolDefinition) {
162 apiKey := os.Getenv("OPENAI_APIKEY")

Callers 2

testT2Function · 0.85
mainFunction · 0.85

Calls 4

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

Tested by

no test coverage detected