|
133 | 133 | {:role "assistant" :content [{:type "output_text" :text "Foo"}]} |
134 | 134 | {:role "user" :content [{:type "input_text" :text "What foo?"}]}]} |
135 | 135 | llm.mocks/*last-req-body*)))))) |
| 136 | + |
| 137 | +(deftest openai-chat-simple-text |
| 138 | + (eca/start-process!) |
| 139 | + |
| 140 | + (testing "We use the default model from custom provider" |
| 141 | + (is (match? |
| 142 | + {:models (m/embeds ["myProvider/deepseek-coder"]) |
| 143 | + :chatDefaultModel "myProvider/deepseek-coder"} |
| 144 | + (eca/request! (fixture/initialize-request |
| 145 | + {:initializationOptions |
| 146 | + (merge fixture/default-init-options |
| 147 | + {:customProviders |
| 148 | + {"myProvider" |
| 149 | + {:api "openai-chat" |
| 150 | + :url (str "http://localhost:" llm-mock.server/port "/openai-chat") |
| 151 | + :key "foobar" |
| 152 | + :models ["deepseek-chat" "deepseek-coder"] |
| 153 | + :defaultModel "deepseek-coder"}}}) |
| 154 | + :capabilities {:codeAssistant {:chat {}}}}))))) |
| 155 | + (eca/notify! (fixture/initialized-notification)) |
| 156 | + (let [chat-id* (atom nil)] |
| 157 | + (testing "We send a simple hello message" |
| 158 | + (llm.mocks/set-case! :simple-text-0) |
| 159 | + (let [req-id 0 |
| 160 | + resp (eca/request! (fixture/chat-prompt-request |
| 161 | + {:request-id req-id |
| 162 | + :model "myProvider/deepseek-coder" |
| 163 | + :message "Tell me a joke!"})) |
| 164 | + chat-id (reset! chat-id* (:chatId resp))] |
| 165 | + |
| 166 | + (is (match? |
| 167 | + {:chatId (m/pred string?) |
| 168 | + :model "myProvider/deepseek-coder" |
| 169 | + :status "success"} |
| 170 | + resp)) |
| 171 | + |
| 172 | + (match-content chat-id req-id "user" {:type "text" :text "Tell me a joke!\n"}) |
| 173 | + (match-content chat-id req-id "system" {:type "progress" :state "running" :text "Waiting model"}) |
| 174 | + (match-content chat-id req-id "system" {:type "progress" :state "running" :text "Generating"}) |
| 175 | + (match-content chat-id req-id "assistant" {:type "text" :text "Knock"}) |
| 176 | + (match-content chat-id req-id "assistant" {:type "text" :text " knock!"}) |
| 177 | + (match-content chat-id req-id "system" {:type "progress" :state "finished"}) |
| 178 | + (is (match? |
| 179 | + {:input [{:role "user" :content [{:type "input_text" :text "Tell me a joke!"}]}] |
| 180 | + :instructions (m/pred string?)} |
| 181 | + llm.mocks/*last-req-body*)))) |
| 182 | + |
| 183 | + (testing "We reply" |
| 184 | + (llm.mocks/set-case! :simple-text-1) |
| 185 | + (let [req-id 1 |
| 186 | + resp (eca/request! (fixture/chat-prompt-request |
| 187 | + {:chat-id @chat-id* |
| 188 | + :request-id req-id |
| 189 | + :model "myProvider/deepseek-coder" |
| 190 | + :message "Who's there?"})) |
| 191 | + chat-id @chat-id*] |
| 192 | + |
| 193 | + (is (match? |
| 194 | + {:chatId (m/pred string?) |
| 195 | + :model "myProvider/deepseek-coder" |
| 196 | + :status "success"} |
| 197 | + resp)) |
| 198 | + |
| 199 | + (match-content chat-id req-id "user" {:type "text" :text "Who's there?\n"}) |
| 200 | + (match-content chat-id req-id "system" {:type "progress" :state "running" :text "Waiting model"}) |
| 201 | + (match-content chat-id req-id "system" {:type "progress" :state "running" :text "Generating"}) |
| 202 | + (match-content chat-id req-id "assistant" {:type "text" :text "Foo"}) |
| 203 | + (match-content chat-id req-id "system" {:type "progress" :state "finished"}) |
| 204 | + (is (match? |
| 205 | + {:input [{:role "user" :content [{:type "input_text" :text "Tell me a joke!"}]} |
| 206 | + {:role "assistant" :content [{:type "output_text" :text "Knock knock!"}]} |
| 207 | + {:role "user" :content [{:type "input_text" :text "Who's there?"}]}]} |
| 208 | + llm.mocks/*last-req-body*)))) |
| 209 | + |
| 210 | + (testing "model reply again keeping context" |
| 211 | + (llm.mocks/set-case! :simple-text-2) |
| 212 | + (let [req-id 2 |
| 213 | + resp (eca/request! (fixture/chat-prompt-request |
| 214 | + {:chat-id @chat-id* |
| 215 | + :request-id req-id |
| 216 | + :model "myProvider/deepseek-coder" |
| 217 | + :message "What foo?"})) |
| 218 | + chat-id @chat-id*] |
| 219 | + |
| 220 | + (is (match? |
| 221 | + {:chatId (m/pred string?) |
| 222 | + :model "myProvider/deepseek-coder" |
| 223 | + :status "success"} |
| 224 | + resp)) |
| 225 | + |
| 226 | + (match-content chat-id req-id "user" {:type "text" :text "What foo?\n"}) |
| 227 | + (match-content chat-id req-id "system" {:type "progress" :state "running" :text "Waiting model"}) |
| 228 | + (match-content chat-id req-id "system" {:type "progress" :state "running" :text "Generating"}) |
| 229 | + (match-content chat-id req-id "assistant" {:type "text" :text "Foo"}) |
| 230 | + (match-content chat-id req-id "assistant" {:type "text" :text " bar!"}) |
| 231 | + (match-content chat-id req-id "assistant" {:type "text" :text "\n\n"}) |
| 232 | + (match-content chat-id req-id "assistant" {:type "text" :text "Ha!"}) |
| 233 | + (match-content chat-id req-id "system" {:type "progress" :state "finished"}) |
| 234 | + (is (match? |
| 235 | + {:input [{:role "user" :content [{:type "input_text" :text "Tell me a joke!"}]} |
| 236 | + {:role "assistant" :content [{:type "output_text" :text "Knock knock!"}]} |
| 237 | + {:role "user" :content [{:type "input_text" :text "Who's there?"}]} |
| 238 | + {:role "assistant" :content [{:type "output_text" :text "Foo"}]} |
| 239 | + {:role "user" :content [{:type "input_text" :text "What foo?"}]}]} |
| 240 | + llm.mocks/*last-req-body*)))))) |
0 commit comments