(ctx context.Context, model, message string, tools []uctypes.ToolDefinition)
| 159 | } |
| 160 | |
| 161 | func testOpenAIComp(ctx context.Context, model, message string, tools []uctypes.ToolDefinition) { |
| 162 | apiKey := os.Getenv("OPENAI_APIKEY") |
| 163 | if apiKey == "" { |
| 164 | fmt.Println("Error: OPENAI_APIKEY environment variable not set") |
| 165 | os.Exit(1) |
| 166 | } |
| 167 | |
| 168 | opts := &uctypes.AIOptsType{ |
| 169 | APIType: uctypes.APIType_OpenAIChat, |
| 170 | APIToken: apiKey, |
| 171 | Endpoint: "https://api.openai.com/v1/chat/completions", |
| 172 | Model: model, |
| 173 | MaxTokens: 4096, |
| 174 | ThinkingLevel: uctypes.ThinkingLevelMedium, |
| 175 | } |
| 176 | |
| 177 | chatID := uuid.New().String() |
| 178 | |
| 179 | aiMessage := &uctypes.AIMessage{ |
| 180 | MessageId: uuid.New().String(), |
| 181 | Parts: []uctypes.AIMessagePart{ |
| 182 | { |
| 183 | Type: uctypes.AIMessagePartTypeText, |
| 184 | Text: message, |
| 185 | }, |
| 186 | }, |
| 187 | } |
| 188 | |
| 189 | fmt.Printf("Testing OpenAI Completions API with WaveAIPostMessageWrap, model: %s\n", model) |
| 190 | fmt.Printf("Message: %s\n", message) |
| 191 | fmt.Printf("Chat ID: %s\n", chatID) |
| 192 | fmt.Println("---") |
| 193 | |
| 194 | testWriter := &TestResponseWriter{} |
| 195 | sseHandler := sse.MakeSSEHandlerCh(testWriter, ctx) |
| 196 | defer sseHandler.Close() |
| 197 | |
| 198 | chatOpts := uctypes.WaveChatOpts{ |
| 199 | ChatId: chatID, |
| 200 | ClientId: uuid.New().String(), |
| 201 | Config: *opts, |
| 202 | Tools: tools, |
| 203 | SystemPrompt: []string{"You are a helpful assistant. Be concise and clear in your responses."}, |
| 204 | } |
| 205 | err := aiusechat.WaveAIPostMessageWrap(ctx, sseHandler, aiMessage, chatOpts) |
| 206 | if err != nil { |
| 207 | fmt.Printf("OpenAI Completions API streaming error: %v\n", err) |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | func testOpenRouter(ctx context.Context, model, message string, tools []uctypes.ToolDefinition) { |
| 212 | apiKey := os.Getenv("OPENROUTER_APIKEY") |
no test coverage detected