Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams committed Jun 12, 2024
1 parent 87e1e92 commit 7ecde08
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 54 deletions.
64 changes: 32 additions & 32 deletions src/openai/chat/non-streaming.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const TEST_TIMEOUT = 8_000;

const hopfield = hop.client(openai).provider(openAIClient);

const chat = hopfield.chat('gpt-4o-2024-05-13');
const chatMultiple = hopfield.chat('gpt-4o-2024-05-13', 2);
const chat = hopfield.chat('gpt-3.5-turbo-0613');
const chatMultiple = hopfield.chat('gpt-3.5-turbo-0613', 2);

describe.concurrent('non-streaming', () => {
test(
Expand All @@ -29,18 +29,18 @@ describe.concurrent('non-streaming', () => {
});

expect(parsed.choices).toMatchInlineSnapshot(`
[
{
"__type": "stop",
"finish_reason": "stop",
"index": 0,
"message": {
"content": "The coolest way to eat a pizza is by folding it in half and taking a big, satisfying bite.",
"role": "assistant",
[
{
"__type": "stop",
"finish_reason": "stop",
"index": 0,
"message": {
"content": "The coolest way to eat a pizza is by folding it in half and taking a big, satisfying bite.",
"role": "assistant",
},
},
},
]
`);
]
`);
},
TEST_TIMEOUT,
);
Expand All @@ -62,27 +62,27 @@ describe.concurrent('non-streaming', () => {
});

expect(parsed.choices).toMatchInlineSnapshot(`
[
{
"__type": "stop",
"finish_reason": "stop",
"index": 0,
"message": {
"content": "The coolest way to eat a pizza is by folding it in half and taking a big, satisfying bite.",
"role": "assistant",
[
{
"__type": "stop",
"finish_reason": "stop",
"index": 0,
"message": {
"content": "The coolest way to eat a pizza is by folding it in half and taking a big, satisfying bite.",
"role": "assistant",
},
},
},
{
"__type": "stop",
"finish_reason": "stop",
"index": 1,
"message": {
"content": "The coolest way to eat a pizza is by folding it in half and taking a big, satisfying bite.",
"role": "assistant",
{
"__type": "stop",
"finish_reason": "stop",
"index": 1,
"message": {
"content": "The coolest way to eat a pizza is by folding it in half and taking a big, satisfying bite.",
"role": "assistant",
},
},
},
]
`);
]
`);
},
TEST_TIMEOUT,
);
Expand Down
7 changes: 5 additions & 2 deletions src/openai/chat/non-streaming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe.concurrent('non-streaming chat', () => {
test('all test messages', async () => {
const allTests = [openaiBasicMessage, openaiLengthLimited];

const testChat = hop.client(openai).chat();
const testChat = hop.client(openai).chat('gpt-4o-2024-05-13');

const allTypes: hop.inferResult<typeof testChat>[] = [];

Expand Down Expand Up @@ -157,7 +157,10 @@ describe.concurrent('non-streaming functions chat', () => {
openaiLengthLimited,
];

const testChat = hop.client(openai).chat().functions([weatherFunction]);
const testChat = hop
.client(openai)
.chat('gpt-4o-2024-05-13')
.functions([weatherFunction]);

const allTypes: hop.inferResult<typeof testChat>[] = [];

Expand Down
42 changes: 22 additions & 20 deletions src/openai/chat/streaming.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe.concurrent('streaming', () => {
: '';
}

expect(content).toMatchInlineSnapshot('"Fold and devour."');
expect(content).toMatchInlineSnapshot('"Upside-down slice."');
expect(onChunkTypes).toEqual(onDoneTypes);
},
TEST_TIMEOUT,
Expand Down Expand Up @@ -90,24 +90,26 @@ describe.concurrent('streaming', () => {
}
}

expect(content1).toMatchInlineSnapshot('"Fold and devour."');
expect(content2).toMatchInlineSnapshot('"Fold and devour."');
expect(content1).toMatchInlineSnapshot('"Upside-down slice."');
expect(content2).toMatchInlineSnapshot('"Upside-down slice."');
expect(onChunkTypes).toMatchInlineSnapshot(`
[
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"stop",
"stop",
]
`);
[
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"content",
"stop",
"stop",
]
`);
},
TEST_TIMEOUT,
);
Expand Down Expand Up @@ -136,7 +138,7 @@ describe.concurrent('streaming', () => {
: '';
}

expect(content).toMatchInlineSnapshot('"Fold and devour."');
expect(content).toMatchInlineSnapshot('"Upside-down slice."');
},
TEST_TIMEOUT,
);
Expand Down Expand Up @@ -170,7 +172,7 @@ describe.concurrent('streaming', () => {
readCount++;
}

expect(content).toMatchInlineSnapshot('"Fold"');
expect(content).toMatchInlineSnapshot('"Ups"');

const postCancelRead = await reader.read();
expect(postCancelRead.done).toBe(true);
Expand Down

0 comments on commit 7ecde08

Please sign in to comment.