Skip to content

Commit

Permalink
typescript integ etst
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-palakurthi committed Jun 28, 2024
1 parent aba85e7 commit 58d92e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion integ-tests/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"typescript": "^5.4.2"
},
"dependencies": {
"@boundaryml/baml": "link:../../engine/language_client_typescript"
"@boundaryml/baml": "link:../../engine/language_client_typescript",
"dotenv": "^16.4.5"
}
}
4 changes: 3 additions & 1 deletion integ-tests/typescript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions integ-tests/typescript/tests/integ-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
} from '../baml_client'
import TypeBuilder from '../baml_client/type_builder'
import { RecursivePartialNull } from '../baml_client/client'
import { config } from 'dotenv'
config()

describe('Integ tests', () => {
it('should work for all inputs', async () => {
Expand Down Expand Up @@ -135,15 +137,24 @@ describe('Integ tests', () => {
})

it('should support streaming in OpenAI', async () => {
const stream = b.stream.PromptTestOpenAI('Mt Rainier is tall')
const stream = b.stream.PromptTestStreaming('Mt Rainier is tall')
const msgs: string[] = []
const startTime = performance.now()

let firstMsgTime: number | null = null
for await (const msg of stream) {
msgs.push(msg ?? '')
if (firstMsgTime === null) {
firstMsgTime = performance.now()
}
}
const final = await stream.getFinalResponse()

expect(final.length).toBeGreaterThan(0)
expect(msgs.length).toBeGreaterThan(0)
expect(firstMsgTime).not.toBeNull()
expect(firstMsgTime! - startTime).toBeLessThanOrEqual(1500) // 1.5 seconds

for (let i = 0; i < msgs.length - 2; i++) {
expect(msgs[i + 1].startsWith(msgs[i])).toBeTruthy()
}
Expand All @@ -167,7 +178,7 @@ describe('Integ tests', () => {
})

it('should support streaming without iterating', async () => {
const final = await b.stream.PromptTestOpenAI('Mt Rainier is tall').getFinalResponse()
const final = await b.stream.PromptTestStreaming('Mt Rainier is tall').getFinalResponse()
expect(final.length).toBeGreaterThan(0)
})

Expand Down

0 comments on commit 58d92e7

Please sign in to comment.