Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLM test using JS #1

Merged
merged 13 commits into from
Mar 5, 2025
28 changes: 28 additions & 0 deletions .github/workflows/run-cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Run Cypress

on:
push: # Todo: Remove on push
branches:
- testllm
workflow_dispatch:

jobs:
run-cypress:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install Dependencies
run: npm ci

- name: Run Cypress
env:
OPEN_AI_API_KEY: ${{ secrets.OPEN_AI_API_KEY }}
run: npm run cypress:run -- --env openai_api_key=$OPEN_AI_API_KEY
5 changes: 5 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {}
})
15 changes: 15 additions & 0 deletions cypress/e2e/tests/llmTest.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint no-undef: 0 */
import OpenAi from '../../page-objects/authorisation/auth'

describe('OpenAI API Test', () => {
const openAiApi = new OpenAi()

it('Should return the correct response', () => {
openAiApi.sendMessage('What is the capital of England?').then(response => {
expect(response.status).to.eq(200)
expect(response.body.choices[0].message.content.trim()).to.include(
'London'
)
})
})
})
24 changes: 24 additions & 0 deletions cypress/page-objects/authorisation/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint no-undef: 0 */
class OpenAi {
constructor() {
this.apiUrl = 'https://api.openai.com/v1/chat/completions'
this.authHeader = {
Authorization: `Bearer ${Cypress.env('openai_api_key')}`,
'Content-Type': 'application/json'
}
}

sendMessage(message) {
return cy.request({
method: 'POST',
url: this.apiUrl,
headers: this.authHeader,
body: {
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: message }]
}
})
}
}

export default OpenAi
Empty file added cypress/support/commands.js
Empty file.
17 changes: 17 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
Loading
Loading