Skip to content

Commit

Permalink
feat(opentrons-ai-client): update api call functions for simulator api
Browse files Browse the repository at this point in the history
update api call functions for simulator api

close AUTH-388
  • Loading branch information
koji committed May 7, 2024
1 parent ab4117d commit 6e00625
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified opentrons-ai-client/src/assets/images/favicon/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified opentrons-ai-client/src/assets/images/favicon/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 21 additions & 8 deletions opentrons-ai-client/src/molecules/InputPrompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import {
} from '@opentrons/components'
import { SendButton } from '../../atoms/SendButton'
import { preparedPromptAtom, chatDataAtom } from '../../resources/atoms'
import { detectSimulate } from '../../resources/utils'

import type { ChatData } from '../../resources/types'

// ToDo (kk:05/02/2024) This url is temporary
const url = 'http://localhost:8000/streaming/ask'
const CHAT_ENDPOINT = 'http://localhost:8000/streaming/ask'
const SIMULATOR_ENDPOINT = ''

Check failure on line 26 in opentrons-ai-client/src/molecules/InputPrompt/index.tsx

View workflow job for this annotation

GitHub Actions / js checks

'SIMULATOR_ENDPOINT' is assigned a value but never used

Check failure on line 26 in opentrons-ai-client/src/molecules/InputPrompt/index.tsx

View workflow job for this annotation

GitHub Actions / js checks

'SIMULATOR_ENDPOINT' is assigned a value but never used

interface InputType {
userPrompt: string
Expand Down Expand Up @@ -49,11 +51,11 @@ export function InputPrompt(): JSX.Element {
return rowsNum
}

const fetchData = async (prompt: string): Promise<void> => {
const fetchChatData = async (prompt: string): Promise<void> => {
if (prompt !== '') {
setLoading(true)
try {
const response = await axios.post(url, {
const response = await axios.post(CHAT_ENDPOINT, {
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -68,13 +70,24 @@ export function InputPrompt(): JSX.Element {
}
}

const fetchSimulatorResult = async (): Promise<void> => {
// code to call opentrons simulator
}

const handleClick = (): void => {
const userInput: ChatData = {
role: 'user',
content: userPrompt,
// Note (kk:05/07/2024) if user prompt is to simulate a protocol
// call fetchSimulateResult
if (detectSimulate(userPrompt)) {
void fetchSimulatorResult()
} else {
const userInput: ChatData = {
role: 'user',
content: userPrompt,
}
setChatData(chatData => [...chatData, userInput])
void fetchChatData(userPrompt)
}
setChatData(chatData => [...chatData, userInput])
void fetchData(userPrompt)

setSubmitted(true)
reset()
}
Expand Down
22 changes: 22 additions & 0 deletions opentrons-ai-client/src/resources/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, it, expect } from 'vitest'
import { detectSimulate } from '../utils'

describe('detectSimulate', () => {
it('should return true', () => {
expect(detectSimulate('simulate')).toBeTruthy()
expect(detectSimulate('simulate the above protocol')).toBeTruthy()
expect(detectSimulate('simulates the above protocol')).toBeTruthy()
expect(detectSimulate('I want to simulate the above protocol')).toBeTruthy()
expect(detectSimulate('Simulate')).toBeTruthy()
expect(detectSimulate('Simulates')).toBeTruthy()
expect(detectSimulate('SIMULATE')).toBeTruthy()
expect(detectSimulate('SIMULATES')).toBeTruthy()
expect(detectSimulate('please simulate the above protocol')).toBeTruthy()
})

it('should return false', () => {
expect(detectSimulate('simulator')).toBeFalsy()
expect(detectSimulate('run a simulator')).toBeFalsy()
expect(detectSimulate('test')).toBeFalsy()
})
})
12 changes: 12 additions & 0 deletions opentrons-ai-client/src/resources/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This function checks if the input string contains the word 'simulate'.
* It uses a global, case-insensitive, multiline regular expression to search for the word.
*
* @param {string} input - The string to be tested.
* @returns {boolean} - Returns true if 'simulate' is found in the input string, false otherwise.
*/

export const detectSimulate = (input: string): boolean => {
const regex = /simulate/gim
return regex.test(input)
}

0 comments on commit 6e00625

Please sign in to comment.