update tests to run in CI

This commit is contained in:
Nate 2025-06-08 21:51:18 -07:00
parent f15b379daf
commit 9f92372dd5
3 changed files with 128 additions and 106 deletions

View file

@ -435,6 +435,8 @@ jobs:
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_FOUNDRY_API_KEY: ${{ secrets.AZURE_FOUNDRY_API_KEY }}
AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY: ${{ secrets.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY }}
AZURE_OPENAI_GPT41_API_KEY: ${{ secrets.AZURE_OPENAI_GPT41_API_KEY }}
package-tests:
runs-on: ubuntu-latest

View file

@ -8,7 +8,12 @@ import { getLlmApi, testChat, testEmbed } from "./util.js";
dotenv.config();
function testConfig(config: ModelConfig) {
export interface TestConfigOptions {
skipTools: boolean;
}
function testConfig(_config: ModelConfig & { options?: TestConfigOptions }) {
const { options, ...config } = _config;
const model = config.model;
const api = getLlmApi({
provider: config.provider as any,
@ -22,7 +27,7 @@ function testConfig(config: ModelConfig) {
config.roles?.includes(role as any),
)
) {
testChat(api, model);
testChat(api, model, options);
}
if (config.roles?.includes("embed")) {
@ -34,7 +39,7 @@ function testConfig(config: ModelConfig) {
}
}
const TESTS: Omit<ModelConfig, "name">[] = [
const TESTS: Omit<ModelConfig & { options?: TestConfigOptions }, "name">[] = [
{
provider: "openai",
model: "gpt-4o",
@ -106,7 +111,7 @@ const TESTS: Omit<ModelConfig, "name">[] = [
provider: "azure",
model: "gpt-4.1",
apiBase: "https://continue-openai.openai.azure.com",
apiKey: process.env.AZURE_OPENAI_API_KEY,
apiKey: process.env.AZURE_OPENAI_GPT41_API_KEY,
env: {
deployment: "gpt-4.1",
apiVersion: "2024-02-15-preview",
@ -114,6 +119,14 @@ const TESTS: Omit<ModelConfig, "name">[] = [
},
roles: ["chat"],
},
{
provider: "azure",
model: "mistral-small-2503",
apiBase: "https://nate-0276-resource.services.ai.azure.com/models",
apiKey: process.env.AZURE_FOUNDRY_MISTRAL_SMALL_API_KEY,
roles: ["chat"],
options: { skipTools: true },
},
];
TESTS.forEach((config) => {

View file

@ -1,5 +1,6 @@
import { BaseLlmApi, constructLlmApi } from "../index.js";
import { LLMConfig } from "../types.js";
import { TestConfigOptions } from "./main.test.js";
export function getLlmApi(config: LLMConfig) {
const api = constructLlmApi(config);
@ -72,7 +73,11 @@ export function testFim(api: BaseLlmApi, model: string) {
});
}
export function testChat(api: BaseLlmApi, model: string) {
export function testChat(
api: BaseLlmApi,
model: string,
options?: TestConfigOptions,
) {
test("should successfully stream chat", async () => {
const stream = api.chatCompletionStream(
{
@ -199,123 +204,125 @@ export function testChat(api: BaseLlmApi, model: string) {
expect(completion?.startsWith("RESPONSE: ")).toBe(true);
});
test("Tool Call works", async () => {
let args = "";
let isFirstChunk = true;
for await (const chunk of api.chatCompletionStream(
{
messages: [
{
role: "user",
content:
"Hi, my name is Nate. Please call the say_hello function to respond to me.",
},
],
tools: [
{
function: {
name: "say_hello",
description: "Say Hello",
parameters: {
type: "object",
properties: {
name: {
type: "string",
description: "The name of the person to greet",
if (options?.skipTools === false) {
test("Tool Call works", async () => {
let args = "";
let isFirstChunk = true;
for await (const chunk of api.chatCompletionStream(
{
messages: [
{
role: "user",
content:
"Hi, my name is Nate. Please call the say_hello function to respond to me.",
},
],
tools: [
{
function: {
name: "say_hello",
description: "Say Hello",
parameters: {
type: "object",
properties: {
name: {
type: "string",
description: "The name of the person to greet",
},
},
},
},
type: "function",
},
],
tool_choice: {
type: "function",
function: {
name: "say_hello",
},
},
],
tool_choice: {
type: "function",
function: {
name: "say_hello",
},
stream: true,
model,
},
stream: true,
model,
},
new AbortController().signal,
)) {
const toolCall = chunk.choices[0].delta.tool_calls?.[0];
if (!toolCall) {
continue;
new AbortController().signal,
)) {
const toolCall = chunk.choices[0].delta.tool_calls?.[0];
if (!toolCall) {
continue;
}
args += toolCall.function?.arguments ?? "";
expect(chunk.choices[0].delta.tool_calls).toHaveLength(1);
if (isFirstChunk) {
isFirstChunk = false;
expect(toolCall.id).toBeDefined();
expect(toolCall.function!.name).toBe("say_hello");
}
}
args += toolCall.function?.arguments ?? "";
expect(chunk.choices[0].delta.tool_calls).toHaveLength(1);
const parsedArgs = JSON.parse(args);
expect(parsedArgs.name).toBe("Nate");
});
if (isFirstChunk) {
isFirstChunk = false;
expect(toolCall.id).toBeDefined();
expect(toolCall.function!.name).toBe("say_hello");
}
}
const parsedArgs = JSON.parse(args);
expect(parsedArgs.name).toBe("Nate");
});
test("Tool Call second message works", async () => {
let response = "";
for await (const chunk of api.chatCompletionStream(
{
messages: [
{
role: "user",
content:
"Hi, my name is Nate. Please call the say_hello function to respond to me, then respond to me again.",
},
{
role: "assistant",
tool_calls: [
{
function: {
arguments: '{"name":"Nate"}',
name: "say_hello",
test("Tool Call second message works", async () => {
let response = "";
for await (const chunk of api.chatCompletionStream(
{
messages: [
{
role: "user",
content:
"Hi, my name is Nate. Please call the say_hello function to respond to me, then respond to me again.",
},
{
role: "assistant",
tool_calls: [
{
function: {
arguments: '{"name":"Nate"}',
name: "say_hello",
},
id: "tool_call_1",
type: "function",
},
id: "tool_call_1",
type: "function",
},
],
},
{
role: "tool",
tool_call_id: "tool_call_1",
content: "Nate was greeted",
},
],
tools: [
{
function: {
name: "say_hello",
description: "Say Hello",
parameters: {
type: "object",
properties: {
name: {
type: "string",
description: "The name of the person to greet",
],
},
{
role: "tool",
tool_call_id: "tool_call_1",
content: "Nate was greeted",
},
],
tools: [
{
function: {
name: "say_hello",
description: "Say Hello",
parameters: {
type: "object",
properties: {
name: {
type: "string",
description: "The name of the person to greet",
},
},
},
},
type: "function",
},
type: "function",
},
],
stream: true,
model,
},
new AbortController().signal,
)) {
response += chunk.choices[0].delta.content ?? "";
}
],
stream: true,
model,
},
new AbortController().signal,
)) {
response += chunk.choices[0].delta.content ?? "";
}
expect(response.length).toBeGreaterThan(0);
});
expect(response.length).toBeGreaterThan(0);
});
}
}
export function testCompletion(api: BaseLlmApi, model: string) {